#include <Pratt.hpp>
Classes | |
struct | Binary |
struct | Expression |
struct | Unary |
struct | Value |
Public Member Functions | |
Pratt (Instance *inst) | |
~Pratt () | |
Instance * | instance () |
void | def_unary (int name, int precedence, const char *op_left, bool child_mandatory, const char *op_right, bool phantom=false) |
void | def_binary (int name, int precedence, const char *op_left, bool left_child_mandatory, const char *op_middle, bool right_child_mandatory, const char *op_right) |
void | def_value (int name) |
void | define_operators (Lex *lex) |
void | read_expression (Lex *lex) |
void | clear () |
const Expression * | root () |
Public Attributes | |
ClientMarker | cm |
Detailed Description
This reads expression from given Lex analyzer and builds its syntactic tree. Expression supports unary prefix, binary infix and unary postfix operators with custom precedence, parentheses (to change operator precedence) and funcalls . A funcall begins with a left parenthesis after an expression. Inside parentheses is a list of arguments (expressions) separated with ',' symbol. Symbol ',' used as function argument separator will always take precedence over its use as prefix, infix or postfix operator (use double parentheses to force its use as postfix, infix or prefix operator).
When reading expression, Pratt reads exactly one expression (expression not folowed by infix or postfix operator).
Constructor & Destructor Documentation
◆ Pratt()
◆ ~Pratt()
Member Function Documentation
◆ instance()
◆ def_unary()
void iv::Pratt::def_unary | ( | int | name, |
int | precedence, | ||
const char * | op_left, | ||
bool | child_mandatory, | ||
const char * | op_right, | ||
bool | phantom = false |
||
) |
Define any unary (prefix or postfix) operation. Higher precedence means that the operation is more inside.
- Parameters
-
phantom If set to true, operators will be ignored and child expression will be passed as child of parent expression directly. Use this for operators that change precedence but have no other effect, typicaly parentheses. precedence Not valid for every operators (operators with both op_left and op_right does not use parameter precedence). Default precedence is -1, so do not use negative precedence of operators. name op_left child_mandatory op_right
◆ def_binary()
void iv::Pratt::def_binary | ( | int | name, |
int | precedence, | ||
const char * | op_left, | ||
bool | left_child_mandatory, | ||
const char * | op_middle, | ||
bool | right_child_mandatory, | ||
const char * | op_right | ||
) |
◆ def_value()
◆ define_operators()
void iv::Pratt::define_operators | ( | Lex * | lex | ) |
◆ read_expression()
void iv::Pratt::read_expression | ( | Lex * | lex | ) |
Parses one expression from given Lex instance. The parsed syntax tree is accessible through Pratt::root method. Pratt::define_operators should be called on this instance before read_expression is called.
◆ clear()
void iv::Pratt::clear | ( | ) |
Deletes syntax tree created in Pratt::read_expression method. Does not have to be called; Pratt::read_expression clears old instance; Pratt::~Pratt also calls does this.
◆ root()
const Pratt::Expression * iv::Pratt::root | ( | ) |
Returns syntax tree created by Pratt::read_expression method. Returns nullptr if read_expression was not called yet or if there was an error during reading or if there was just nothing to read (for example if current Lex token is operator unknown to Pratt parser).
Member Data Documentation
◆ cm
ClientMarker iv::Pratt::cm |
The documentation for this class was generated from the following files: