MADARA
3.1.8
|
Parses incoming expression strings into a parse tree and generates an expression tree from the parse tree. More...
#include <Interpreter.h>
Public Member Functions | |
Interpreter () | |
Constructor. More... | |
virtual | ~Interpreter () |
Destructor. More... | |
bool | delete_expression (const std::string &expression) |
Attempts to delete an expression from cache. More... | |
ExpressionTree | interpret (madara::knowledge::ThreadSafeContext &context, const std::string &input) |
Compiles an expression into an expression tree. More... | |
Static Public Member Functions | |
static bool | is_alphanumeric (char input) |
Checks a character to see if it is alphanumeric. More... | |
static bool | is_exponential (char input) |
Checks a character to see if it is in scientific format. More... | |
static bool | is_number (char input) |
Checks a character to see if it is a number. More... | |
static bool | is_operator (char input) |
Checks a character to see if it is a mathematical operator. More... | |
static bool | is_string_literal (char input) |
Checks a character to see if it is a string literal. More... | |
static bool | is_whitespace (char input) |
Checks a character to see if it is whitespace. More... | |
Private Member Functions | |
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. More... | |
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 More... | |
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. More... | |
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. More... | |
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. More... | |
void | precedence_insert (madara::knowledge::ThreadSafeContext &context, Symbol *op,::std::list< Symbol * > &list) |
Inserts a mathematical operator into the tree. More... | |
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. More... | |
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. More... | |
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. More... | |
Private Attributes | |
ExpressionTreeMap | cache_ |
Cache of expressions that have been previously compiled. More... | |
Parses incoming expression strings into a parse tree and generates an expression tree from the parse tree.
This class plays the role of the "interpreter" in the Intepreter pattern. It also uses the Builder pattern to generate the nodes in the expression tree.
Definition at line 42 of file Interpreter.h.
madara::expression::Interpreter::Interpreter | ( | ) |
Constructor.
Definition at line 4358 of file Interpreter.cpp.
|
virtual |
Destructor.
Definition at line 4363 of file Interpreter.cpp.
|
inline |
Attempts to delete an expression from cache.
expression | expression to erase from cache |
Definition at line 75 of file Interpreter.inl.
|
private |
Handles a parenthesis.
context | interpreter context |
input | expression to compile |
i | current position in expression |
lastValidInput | last valid symbol that was read |
list | list of symbols in tree that are free |
handled | whether or not the pos should be incremented |
accumulated_precedence | current precedence |
Definition at line 5943 of file Interpreter.cpp.
|
private |
extracts precondition, condition, postcondition, and body from input
context | interpreter context |
variable | name of the variable the for loop is based on |
input | expression to compile |
i | current position in expression |
accumulated_precedence | current precedence |
list | list of symbols to insert for loop into |
returnableInput | used to interact with lastValidInput if an array reference is found |
if we manage to find a delimiter but not its end, we're seeing an array reference with subtraction in it
Definition at line 4369 of file Interpreter.cpp.
|
private |
Handles a parenthesis.
context | interpreter context |
input | expression to compile |
i | current position in expression |
accumulated_precedence | current precedence |
list | list of symbols in tree that are free |
lastValidInput | last valid symbol that was read |
handled | whether or not the pos should be incremented |
build_argument_list | if true, focuses on building a list instead of an expression tree |
Definition at line 6020 of file Interpreter.cpp.
madara::expression::ExpressionTree madara::expression::Interpreter::interpret | ( | madara::knowledge::ThreadSafeContext & | context, |
const std::string & | input | ||
) |
Compiles an expression into an expression tree.
context | interpreter context |
input | expression to compile |
Definition at line 6117 of file Interpreter.cpp.
|
inlinestatic |
Checks a character to see if it is alphanumeric.
input | char to check |
Definition at line 53 of file Interpreter.inl.
|
inlinestatic |
Checks a character to see if it is in scientific format.
input | char to check |
Definition at line 37 of file Interpreter.inl.
|
inlinestatic |
Checks a character to see if it is a number.
input | char to check |
Definition at line 30 of file Interpreter.inl.
|
inlinestatic |
Checks a character to see if it is a mathematical operator.
input | char to check |
Definition at line 20 of file Interpreter.inl.
|
inlinestatic |
Checks a character to see if it is a string literal.
input | char to check |
Definition at line 45 of file Interpreter.inl.
|
inlinestatic |
Checks a character to see if it is whitespace.
input | char to check |
Definition at line 64 of file Interpreter.inl.
|
private |
Inserts a variable into the tree.
context | interpreter context |
input | expression to compile |
i | current position in expression |
accumulated_precedence | current precedence |
list | list of symbols in tree that are free |
lastValidInput | last valid symbol that was read |
handled | whether or not the pos should be incremented |
build_argument_list | if true, focuses on building a list instead of an expression tree |
Definition at line 5453 of file Interpreter.cpp.
|
private |
Inserts a number into the tree.
context | thread safe context handle |
input | expression to compile |
i | current position in expression |
accumulated_precedence | current precedence |
list | list of symbols in tree that are free |
lastValidInput | last valid symbol that was read |
Definition at line 5232 of file Interpreter.cpp.
|
private |
Inserts a mathematical operator into the tree.
context | thread safe context handle |
op | symbol to insert |
list | list of symbols in tree that are free |
Definition at line 5307 of file Interpreter.cpp.
|
private |
Inserts a variable into the tree.
opener | the opening string |
context | interpreter context |
input | expression to compile |
i | current position in expression |
accumulated_precedence | current precedence |
list | list of symbols in tree that are free |
lastValidInput | last valid symbol that was read |
Definition at line 4912 of file Interpreter.cpp.
|
private |
Inserts a system call into the tree.
context | interpreter context |
input | expression to compile |
i | current position in expression |
accumulated_precedence | current precedence |
list | list of symbols in tree that are free |
lastValidInput | last valid symbol that was read |
Definition at line 4944 of file Interpreter.cpp.
|
private |
Inserts a variable into the tree.
context | interpreter context |
input | expression to compile |
i | current position in expression |
accumulated_precedence | current precedence |
list | list of symbols in tree that are free |
lastValidInput | last valid symbol that was read |
Definition at line 4812 of file Interpreter.cpp.
|
private |
Cache of expressions that have been previously compiled.
Definition at line 280 of file Interpreter.h.