MADARA  3.4.1
Interpreter.h
Go to the documentation of this file.
1 
2 
3 #ifndef _MADARA_KNOWLEDGE_INTERPRETER_H_
4 #define _MADARA_KNOWLEDGE_INTERPRETER_H_
5 
6 #ifndef _MADARA_NO_KARL_
7 
16 #include <string>
17 #include <list>
18 #include <map>
19 
23 
24 namespace madara
25 {
26 namespace expression
27 {
28 // Forward declaration.
29 class Symbol;
30 
31 typedef std::map<std::string, ExpressionTree> ExpressionTreeMap;
32 
43 {
44 public:
48  Interpreter();
49 
53  virtual ~Interpreter();
54 
63  madara::knowledge::ThreadSafeContext& context, const std::string& input);
64 
70  static inline bool is_string_literal(char input);
71 
77  static inline bool is_operator(char input);
78 
84  static inline bool is_number(char input);
85 
91  static inline bool is_alphanumeric(char input);
92 
98  static inline bool is_whitespace(char input);
99 
105  static inline bool is_exponential(char input);
106 
112  static inline bool is_reserved_word(const std::string& input);
113 
119  inline bool delete_expression(const std::string& expression);
120 
121 private:
134  std::string& variable, const std::string& input,
135  std::string::size_type& i, int& accumulated_precedence,
136  ::std::list<Symbol*>& list, Symbol*& returnableInput);
137 
148  const std::string& input, std::string::size_type& i,
149  int& accumulated_precedence, ::std::list<Symbol*>& list,
150  Symbol*& lastValidInput);
151 
162  void string_insert(char opener, madara::knowledge::ThreadSafeContext& context,
163  const std::string& input, std::string::size_type& i,
164  int& accumulated_precedence, ::std::list<Symbol*>& list,
165  Symbol*& lastValidInput);
166 
177  const std::string& input, std::string::size_type& i,
178  int& accumulated_precedence, ::std::list<Symbol*>& list,
179  Symbol*& lastValidInput);
180 
191  const std::string& input, std::string::size_type& i,
192  int& accumulated_precedence, ::std::list<Symbol*>& list,
193  Symbol*& lastValidInput);
194 
202  Symbol* op, ::std::list<Symbol*>& list);
203 
217  const std::string& input, std::string::size_type& i,
218  Symbol*& lastValidInput, bool& handled, int& accumulated_precedence,
219  ::std::list<Symbol*>& list, bool build_argument_list = false);
220 
232  const std::string& input, std::string::size_type& i,
233  Symbol*& lastValidInput, bool& handled, int& accumulated_precedence,
234  ::std::list<Symbol*>& list);
235 
249  const std::string& input, std::string::size_type& i,
250  Symbol*& lastValidInput, bool& handled, int& accumulated_precedence,
251  ::std::list<Symbol*>& list, bool build_argument_list = false);
256 };
257 }
258 }
259 
260 #include "Interpreter.inl"
261 
262 #endif // _MADARA_NO_KARL_
263 
264 #endif /* _MADARA_KNOWLEDGE_INTERPRETER_H_ */
Encapsulates a MADARA KaRL expression into an evaluatable tree.
Parses incoming expression strings into a parse tree and generates an expression tree from the parse ...
Definition: Interpreter.h:43
static bool is_operator(char input)
Checks a character to see if it is a mathematical operator.
Definition: Interpreter.inl:18
static bool is_string_literal(char input)
Checks a character to see if it is a string literal.
Definition: Interpreter.inl:45
static bool is_reserved_word(const std::string &input)
Checks a given input for a reserved word literal.
Definition: Interpreter.inl:37
static bool is_whitespace(char input)
Checks a character to see if it is whitespace.
Definition: Interpreter.inl:60
static bool is_exponential(char input)
Checks a character to see if it is in scientific format.
Definition: Interpreter.inl:31
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.
static bool is_alphanumeric(char input)
Checks a character to see if it is alphanumeric.
Definition: Interpreter.inl:52
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 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.
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.
static bool is_number(char input)
Checks a character to see if it is a number.
Definition: Interpreter.inl:25
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 precedence_insert(madara::knowledge::ThreadSafeContext &context, Symbol *op, ::std::list< Symbol * > &list)
Inserts a mathematical operator into the tree.
ExpressionTree interpret(madara::knowledge::ThreadSafeContext &context, const std::string &input)
Compiles an expression into an expression 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 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.
ExpressionTreeMap cache_
Cache of expressions that have been previously compiled.
Definition: Interpreter.h:255
bool delete_expression(const std::string &expression)
Attempts to delete an expression from cache.
Definition: Interpreter.inl:70
virtual ~Interpreter()
Destructor.
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.
Abstract base class of all parse tree nodes.
This class stores variables and their values for use by any entity needing state information in a thr...
std::map< std::string, ExpressionTree > ExpressionTreeMap
Definition: Interpreter.h:29
constexpr string_t string
Copyright(c) 2020 Galois.