3 #ifndef _MADARA_KNOWLEDGE_INTERPRETER_H_ 4 #define _MADARA_KNOWLEDGE_INTERPRETER_H_ 6 #ifndef _MADARA_NO_KARL_ 84 static inline bool is_number (
char input);
130 std::string::size_type &i,
131 int & accumulated_precedence,
132 ::std::list<Symbol *>& list,
133 Symbol *& returnableInput);
147 std::string::size_type &i,
148 int & accumulated_precedence,
149 ::std::list<Symbol *>& list,
150 Symbol *& lastValidInput);
166 std::string::size_type &i,
167 int & accumulated_precedence,
168 ::std::list<Symbol *>& list,
169 Symbol *& lastValidInput);
183 std::string::size_type &i,
184 int & accumulated_precedence,
185 ::std::list<Symbol *>& list,
186 Symbol *& lastValidInput);
200 std::string::size_type &i,
201 int & accumulated_precedence,
202 ::std::list<Symbol *>& list,
203 Symbol *& lastValidInput);
213 Symbol *op, ::std::list<Symbol *>& list);
229 std::string::size_type &i,
232 int & accumulated_precedence,
233 ::std::list<Symbol *>& list,
234 bool build_argument_list =
false);
250 std::string::size_type &i,
253 int & accumulated_precedence,
254 ::std::list<Symbol *>& list);
271 std::string::size_type &i,
274 int & accumulated_precedence,
275 ::std::list<Symbol *>& list,
276 bool build_argument_list =
false);
287 #endif // _MADARA_NO_KARL_ ExpressionTree interpret(madara::knowledge::ThreadSafeContext &context, const std::string &input)
Compiles an expression into an expression tree.
Encapsulates a MADARA KaRL expression into an evaluatable tree.
Interpreter()
Constructor.
This class stores variables and their values for use by any entity needing state information in a thr...
void precedence_insert(madara::knowledge::ThreadSafeContext &context, Symbol *op,::std::list< Symbol * > &list)
Inserts a mathematical operator into the tree.
void main_loop(madara::knowledge::ThreadSafeContext &context, const std::string &input, std::string::size_type &i, Symbol *&lastValidInput, bool &handled, int &accumulated_precedence,::std::list< Symbol * > &list, bool build_argument_list=false)
Inserts a variable into the tree.
static bool is_alphanumeric(char input)
Checks a character to see if it is alphanumeric.
static bool is_number(char input)
Checks a character to see if it is a number.
void number_insert(madara::knowledge::ThreadSafeContext &context, const std::string &input, std::string::size_type &i, int &accumulated_precedence,::std::list< Symbol * > &list, Symbol *&lastValidInput)
Inserts a number into the tree.
void string_insert(char opener, madara::knowledge::ThreadSafeContext &context, const std::string &input, std::string::size_type &i, int &accumulated_precedence,::std::list< Symbol * > &list, Symbol *&lastValidInput)
Inserts a variable into the tree.
static bool is_whitespace(char input)
Checks a character to see if it is whitespace.
Abstract base class of all parse tree nodes.
Parses incoming expression strings into a parse tree and generates an expression tree from the parse ...
ExpressionTreeMap cache_
Cache of expressions that have been previously compiled.
void handle_parenthesis(madara::knowledge::ThreadSafeContext &context, const std::string &input, std::string::size_type &i, Symbol *&lastValidInput, bool &handled, int &accumulated_precedence,::std::list< Symbol * > &list, bool build_argument_list=false)
Handles a parenthesis.
static bool is_exponential(char input)
Checks a character to see if it is in scientific format.
void system_call_insert(madara::knowledge::ThreadSafeContext &context, const std::string &input, std::string::size_type &i, int &accumulated_precedence,::std::list< Symbol * > &list, Symbol *&lastValidInput)
Inserts a system call into the tree.
void handle_for_loop(madara::knowledge::ThreadSafeContext &context, std::string &variable, const std::string &input, std::string::size_type &i, int &accumulated_precedence,::std::list< Symbol * > &list, Symbol *&returnableInput)
extracts precondition, condition, postcondition, and body from input
void handle_array(madara::knowledge::ThreadSafeContext &context, const std::string &input, std::string::size_type &i, Symbol *&lastValidInput, bool &handled, int &accumulated_precedence,::std::list< Symbol * > &list)
Handles a parenthesis.
std::map< std::string, ExpressionTree > ExpressionTreeMap
Copyright (c) 2015 Carnegie Mellon University.
static bool is_string_literal(char input)
Checks a character to see if it is a string literal.
bool delete_expression(const std::string &expression)
Attempts to delete an expression from cache.
static bool is_operator(char input)
Checks a character to see if it is a mathematical operator.
virtual ~Interpreter()
Destructor.
void variable_insert(madara::knowledge::ThreadSafeContext &context, const std::string &input, std::string::size_type &i, int &accumulated_precedence,::std::list< Symbol * > &list, Symbol *&lastValidInput)
Inserts a variable into the tree.