#include <Pratt.hpp>

Classes

struct  Binary
 
struct  Expression
 
struct  Unary
 
struct  Value
 

Public Member Functions

 Pratt (Instance *inst)
 
 ~Pratt ()
 
Instanceinstance ()
 
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 Expressionroot ()
 

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).

Definition at line 18 of file Pratt.hpp.

Constructor & Destructor Documentation

◆ Pratt()

iv::Pratt::Pratt ( Instance inst)

Definition at line 8 of file Pratt.cpp.

◆ ~Pratt()

iv::Pratt::~Pratt ( )

Definition at line 17 of file Pratt.cpp.

Member Function Documentation

◆ instance()

Instance * iv::Pratt::instance ( )

Definition at line 22 of file Pratt.cpp.

◆ 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
phantomIf 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.
precedenceNot 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

Definition at line 78 of file Pratt.cpp.

◆ 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 
)

Similar to def_unary. Op_middle is mandatory. Operator is also registered as unary operator if op_left is empty and left_child_mandatory is false.

Definition at line 139 of file Pratt.cpp.

◆ def_value()

void iv::Pratt::def_value ( int  name)

Definition at line 73 of file Pratt.cpp.

◆ define_operators()

void iv::Pratt::define_operators ( Lex lex)

Tells given Lex about defined operators.

Definition at line 27 of file Pratt.cpp.

◆ 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.

Definition at line 34 of file Pratt.cpp.

◆ 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.

Definition at line 49 of file Pratt.cpp.

◆ 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).

Definition at line 44 of file Pratt.cpp.

Member Data Documentation

◆ cm

ClientMarker iv::Pratt::cm

Definition at line 66 of file Pratt.hpp.


The documentation for this class was generated from the following files: