|
Yate
|
An expression parser and evaluator. More...
#include <yatescript.h>
Public Types | |
| enum | Parser { C , SQL } |
| enum | Opcode { OpcNone = 0 , OpcNull , OpcPush , OpcDrop , OpcDup , OpcSwap , OpcRot , OpcOver , OpcAdd , OpcSub , OpcMul , OpcDiv , OpcMod , OpcNeg , OpcIncPre , OpcDecPre , OpcIncPost , OpcDecPost , OpcAnd , OpcOr , OpcXor , OpcNot , OpcShl , OpcShr , OpcLAnd , OpcLOr , OpcLXor , OpcLNot , OpcCat , OpcReM , OpcReIM , OpcReNm , OpcReINm , OpcLike , OpcILike , OpcNLike , OpcNIlike , OpcEq , OpcNe , OpcGt , OpcLt , OpcGe , OpcLe , OpcCond , OpcAs , OpcField , OpcFunc , OpcLabel , OpcCopy , OpcNullish , OpcAssign = 0x0100 , OpcPrivate = 0x1000 } |
Public Member Functions | |
| ExpEvaluator (const TokenDict *operators=0, const TokenDict *unaryOps=0) | |
| ExpEvaluator (Parser style) | |
| ExpEvaluator (const ExpEvaluator &original) | |
| virtual | ~ExpEvaluator () |
| int | compile (ParsePoint &expr, GenObject *context=0) |
| bool | evaluate (ObjList *results, GenObject *context=0) const |
| bool | evaluate (ObjList &results, GenObject *context=0) const |
| int | evaluate (NamedList &results, unsigned int index=0, const char *prefix=0, GenObject *context=0) const |
| int | evaluate (Array &results, unsigned int index, GenObject *context=0) const |
| bool | simplify () |
| bool | inError () const |
| unsigned int | lineNumber () const |
| virtual bool | null () const |
| void | dump (const ObjList &codes, String &res, bool lineNo=false) const |
| virtual void | dump (String &res, bool lineNo=false) const |
| String | dump (const ObjList &codes, bool lineNo=false) const |
| String | dump (bool lineNo=false) const |
| const TokenDict * | operators () const |
| const TokenDict * | unaryOps () const |
| ExpExtender * | extender () const |
| void | extender (ExpExtender *ext) |
| virtual ExpOperation * | popValue (ObjList &stack, GenObject *context=0) const |
| virtual bool | runOperation (ObjList &stack, const ExpOperation &oper, GenObject *context=0) const |
| virtual bool | runAllFields (ObjList &stack, GenObject *context=0) const |
Public Member Functions inherited from DebugEnabler | |
| DebugEnabler (int level=TelEngine::debugLevel(), bool enabled=true) | |
| int | debugLevel () const |
| int | debugLevel (int level) |
| bool | debugEnabled () const |
| void | debugEnabled (bool enable) |
| const char * | debugName () const |
| bool | debugAt (int level) const |
| bool | debugChained () const |
| void | debugChain (const DebugEnabler *chain=0) |
| void | debugCopy (const DebugEnabler *original=0) |
Static Public Member Functions | |
| static unsigned int | getLineOf (ExpOperation *op1, ExpOperation *op2=0, ExpOperation *op3=0) |
| static void | pushOne (ObjList &stack, ExpOperation *oper) |
| static ExpOperation * | popOne (ObjList &stack) |
| static ExpOperation * | popAny (ObjList &stack) |
Protected Member Functions | |
| virtual char | skipWhites (ParsePoint &expr) |
| Opcode | getOperator (const char *&expr, const TokenDict *operators, bool caseInsensitive=false) const |
| virtual bool | keywordLetter (char c) const |
| virtual bool | keywordDigit (char c) const |
| virtual bool | keywordChar (char c) const |
| virtual int | getKeyword (const char *str) const |
| bool | gotError (const char *error=0, const char *text=0, unsigned int line=0) const |
| bool | gotError (const char *error=0, const char *text=0, unsigned int line=0) |
| bool | gotError (const char *error, unsigned int line) const |
| bool | gotError (const char *error, unsigned int line) |
| virtual void | formatLineNo (String &buf, unsigned int line) const |
| bool | runCompile (ParsePoint &expr, char stop, GenObject *nested=0) |
| virtual bool | runCompile (ParsePoint &expr, const char *stop=0, GenObject *nested=0) |
| virtual char | skipComments (ParsePoint &expr, GenObject *context=0) |
| virtual int | preProcess (ParsePoint &expr, GenObject *context=0) |
| virtual Opcode | getOperator (ParsePoint &expr) |
| virtual Opcode | getUnaryOperator (ParsePoint &expr) |
| virtual Opcode | getPostfixOperator (ParsePoint &expr, int precedence=0) |
| virtual const char * | getOperator (Opcode oper) const |
| virtual int | getPrecedence (Opcode oper) const |
| virtual bool | getRightAssoc (Opcode oper) const |
| virtual bool | getSeparator (ParsePoint &expr, bool remove) |
| virtual bool | getInstruction (ParsePoint &expr, char stop=0, GenObject *nested=0) |
| virtual bool | getOperand (ParsePoint &expr, bool endOk=true, int precedence=0) |
| virtual bool | getSimple (ParsePoint &expr, bool constOnly=false) |
| virtual bool | getNumber (ParsePoint &expr) |
| virtual bool | getString (ParsePoint &expr) |
| virtual bool | getFunction (ParsePoint &expr) |
| virtual bool | getString (const char *&expr, String &str) |
| virtual bool | getEscape (const char *&expr, String &str, char sep) |
| virtual bool | getField (ParsePoint &expr) |
| void | addOpcode (ExpOperation *oper, unsigned int line=0) |
| ExpOperation * | addOpcode (Opcode oper, bool barrier=false, unsigned int line=0) |
| ExpOperation * | addOpcode (Opcode oper, int64_t value, bool barrier=false) |
| ExpOperation * | addOpcode (const String &value) |
| ExpOperation * | addOpcode (int64_t value) |
| ExpOperation * | addOpcode (bool value) |
| ExpOperation * | addOpcode (Opcode oper, const String &name, int64_t value=0, bool barrier=false, unsigned int line=0) |
| ExpOperation * | popOpcode () |
| virtual bool | trySimplify () |
| virtual bool | runEvaluate (const ObjList &opcodes, ObjList &stack, GenObject *context=0) const |
| virtual bool | runEvaluate (const ObjVector &opcodes, ObjList &stack, GenObject *context=0, unsigned int index=0) const |
| virtual bool | runEvaluate (ObjList &stack, GenObject *context=0) const |
| virtual bool | runFunction (ObjList &stack, const ExpOperation &oper, GenObject *context=0) const |
| virtual bool | runField (ObjList &stack, const ExpOperation &oper, GenObject *context=0) const |
| virtual bool | runAssign (ObjList &stack, const ExpOperation &oper, GenObject *context=0) const |
| virtual void | dump (const ExpOperation &oper, String &res, bool lineNo=false) const |
Protected Member Functions inherited from DebugEnabler | |
| void | debugName (const char *name) |
Static Protected Member Functions | |
| static char | condLower (char chr, bool makeLower) |
Protected Attributes | |
| const TokenDict * | m_operators |
| const TokenDict * | m_unaryOps |
| ObjList | m_opcodes |
| ObjList * | m_lastOpcode |
| bool | m_inError |
| unsigned int | m_lineNo |
Friends | |
| class | ParsePoint |
An expression parser and evaluator.
A class used to build stack based (posifix) expression parsers and evaluators
| enum Opcode |
Operation codes
| enum Parser |
Parsing styles
|
explicit |
Constructs an evaluator from an operator dictionary
| operators | Pointer to operator dictionary, longest strings first |
| unaryOps | Pointer to unary operators dictionary, longest strings first |
References operators(), and unaryOps().
Referenced by ExpEvaluator().
|
explicit |
Constructs an evaluator from a parser style
| style | Style of parsing to use |
| ExpEvaluator | ( | const ExpEvaluator & | original | ) |
Copy constructor
| original | Evaluator to copy the operation list from |
References ExpEvaluator().
|
virtual |
Destructor
|
protected |
Add a boolean constant to the expression
| value | Boolean value to add, will be pushed on execution |
|
protected |
Add a string constant to the expression
| value | String value to add, will be pushed on execution |
|
protected |
Add an aready built operation to the expression and set its line number
| oper | Operation to add |
| line | Line number where operation was compiled, zero to used parsing point |
|
protected |
Add an integer constant to the expression
| value | Integer value to add, will be pushed on execution |
|
protected |
Add a simple operator to the expression
| oper | Operator code to add |
| barrier | True to create an evaluator stack barrier |
| line | Line number where operation was compiled, zero to used parsing point |
|
protected |
Add a function or field to the expression
| oper | Operator code to add, must be OpcField or OpcFunc |
| name | Name of the field or function, case sensitive |
| value | Numerical value used as parameter count to functions |
| barrier | True to create an exavuator stack barrier |
| line | Line number where operation was compiled, zero to used parsing point |
|
protected |
Add a simple operator to the expression
| oper | Operator code to add |
| value | 64 bit nteger value to add |
| barrier | True to create an evaluator stack barrier |
| int compile | ( | ParsePoint & | expr, |
| GenObject * | context = 0 ) |
Parse and compile an expression
| expr | Parsing context to compile |
| context | Pointer to arbitrary object to be passed to called methods |
|
inlinestaticprotected |
Helper method to conditionally convert to lower case
| chr | Character to convert |
| makeLower | True to convert chr to lower case |
|
inline |
|
protectedvirtual |
Dump a single operation according to current operators dictionary
| oper | Operation to dump |
| res | Result string representation of operations |
| lineNo | True to include line numbers |
|
virtual |
Dump the postfix expression according to current operators dictionary
| res | Result string representation of operations |
| lineNo | True to include line numbers |
Evaluate the expression, return computed results
| results | Array of result rows to populate |
| index | Index of result row, zero to just set column headers |
| context | Pointer to arbitrary object to be passed to called methods |
| int evaluate | ( | NamedList & | results, |
| unsigned int | index = 0, | ||
| const char * | prefix = 0, | ||
| GenObject * | context = 0 ) const |
Evaluate the expression, return computed results
| results | List of parameters to populate with results row |
| index | Index of result row, zero to not include an index |
| prefix | Prefix to prepend to parameter names |
| context | Pointer to arbitrary object to be passed to called methods |
Evaluate the expression, return computed results
| results | List to fill with results row |
| context | Pointer to arbitrary object to be passed to called methods |
References evaluate().
Evaluate the expression, optionally return results
| results | List to fill with results row |
| context | Pointer to arbitrary object to be passed to called methods |
Referenced by evaluate().
|
inline |
Retrieve the internally used expression extender
| void extender | ( | ExpExtender * | ext | ) |
Set the expression extender to use in evaluation
| ext | Pointer to the extender to use, NULL to remove current |
|
protectedvirtual |
Formats a line number to display in error messages
| buf | String buffer used to return the value |
| line | Line number to format |
|
protectedvirtual |
|
protectedvirtual |
Get a field keyword, advance parsing pointer past it
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
|
protectedvirtual |
Get a function call, advance parsing pointer past it
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
|
protectedvirtual |
Get an instruction or block, advance parsing pointer past it
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
| stop | Optional character expected after the instruction |
| nested | User defined object passed from nested parsing |
|
protectedvirtual |
Helper method to count characters making a keyword
| str | Pointer to text without whitespaces in front |
|
static |
Retrieve the line number from one to three operands
| op1 | First operand |
| op2 | Optional second operand |
| op3 | Optional third operand |
|
protectedvirtual |
Get a numerical operand, advance parsing pointer past it
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
|
protectedvirtual |
Get an operand, advance parsing pointer past it
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
| endOk | Consider reaching the end of string a success |
| precedence | The precedence of the previous operator |
|
protected |
Helper method to return next operator in the parsed text
| expr | Pointer to text to parse, gets advanced if succeeds |
| operators | Pointer to operators table to use |
| caseInsensitive | Match case-insensitive if set |
References operators().
|
protectedvirtual |
Helper method to get the canonical name of an operator
| oper | Operator code |
|
protectedvirtual |
Returns next operator in the parsed text
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
|
protectedvirtual |
Returns next unary postfix operator in the parsed text
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
| precedence | The precedence of the previous operator |
|
protectedvirtual |
Get the precedence of an operator
| oper | Operator code |
|
protectedvirtual |
Get the associativity of an operator
| oper | Operator code |
|
protectedvirtual |
Check if we are at an expression separator and optionally skip past it
| expr | Current parsing context to check, advances on expression to be compiled if asked to remove separator |
| remove | True to skip past the found separator |
|
protectedvirtual |
Get an inline simple type, usually string or number
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
| constOnly | Return only inline constants |
|
protectedvirtual |
Helper method - get a string, advance parsing pointer past it
| expr | Pointer to string separator, gets advanced on success |
| str | String in which the result is returned |
|
protectedvirtual |
Get a string operand, advance parsing pointer past it
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
|
protectedvirtual |
Returns next unary operator in the parsed text
| expr | Current parsing context, advances on expression to be compiled if it succeeds |
|
inlineprotected |
Helper method to set error flag and display debugging errors internally
| error | Text of the error |
| line | Number of line generating the error, zero for parsing errors |
References gotError().
|
inlineprotected |
Helper method to display debugging errors internally
| error | Text of the error |
| line | Number of line generating the error, zero for parsing errors |
References gotError().
|
protected |
Helper method to set error flag and display debugging errors internally
| error | Text of the error |
| text | Optional text that caused the error |
| line | Number of line generating the error, zero for parsing errors |
|
protected |
Helper method to display debugging errors internally
| error | Text of the error |
| text | Optional text that caused the error |
| line | Number of line generating the error, zero for parsing errors |
Referenced by gotError(), and gotError().
|
inline |
Check if a parse or compile error was encountered
References m_inError.
|
protectedvirtual |
Check if a character can be part of a keyword or identifier
| c | Character to check |
|
protectedvirtual |
Check if a character can be can be a digit character in a keyword or identifier
| c | Character to check |
|
protectedvirtual |
Check if a character can be a letter character in a keyword or identifier
| c | Character to check |
|
inline |
Retrieve the number of line currently being parsed
References m_lineNo.
|
virtual |
Check if the expression is empty (no operands or operators)
|
inline |
Retrieve the internally used operator dictionary
References m_operators.
Referenced by ExpEvaluator(), and getOperator().
|
static |
Pops any operand (including barriers) off an evaluation stack
| stack | Evaluation stack to remove the operand from |
|
static |
Pops an operand off an evaluation stack, does not pop a barrier
| stack | Evaluation stack to remove the operand from |
|
protected |
Remove from the code and return the last operation
|
virtual |
Pops and evaluate the value of an operand off an evaluation stack, does not pop a barrier
| stack | Evaluation stack to remove the operand from |
| context | Pointer to arbitrary object to be passed to called methods |
|
protectedvirtual |
Process top-level preprocessor directives
| expr | Current parsing context, advances on expression to be compiled |
| context | Pointer to arbitrary object to be passed to called methods |
|
static |
Push an operand on an evaluation stack
| stack | Evaluation stack to remove the operand from |
| oper | Operation to push on stack, NULL will not be pushed |
Convert all fields on the evaluation stack to their values
| stack | Evaluation stack to evaluate fields from |
| context | Pointer to arbitrary object to be passed to called methods |
|
protectedvirtual |
Try to assign a value to a single field
| stack | Evaluation stack in use |
| oper | Field to assign to, contains the field name and new value |
| context | Pointer to arbitrary object to be passed to called methods |
|
protected |
Runs the parser and compiler for one (sub)expression
| expr | Current parsing context, advances on expression to be compiled |
| stop | Optional character expected after the expression |
| nested | User defined object to pass for nested parsing |
|
protectedvirtual |
Runs the parser and compiler for one (sub)expression
| expr | Current parsing context, advances on expression to be compiled |
| stop | Optional list of possible characters expected after the expression |
| nested | User defined object to pass for nested parsing |
|
protectedvirtual |
Try to evaluate a list of operation codes
| opcodes | List of operation codes to evaluate |
| stack | Evaluation stack in use, results are left on stack |
| context | Pointer to arbitrary object to be passed to called methods |
|
protectedvirtual |
Try to evaluate a vector of operation codes
| opcodes | ObjVector of operation codes to evaluate |
| stack | Evaluation stack in use, results are left on stack |
| context | Pointer to arbitrary object to be passed to called methods |
| index | Index in operation codes to start evaluation from |
Try to evaluate the expression
| stack | Evaluation stack in use, results are left on stack |
| context | Pointer to arbitrary object to be passed to called methods |
|
protectedvirtual |
Try to evaluate a single field
| stack | Evaluation stack in use, field value must be pushed on it |
| oper | Field to evaluate |
| context | Pointer to arbitrary object to be passed to called methods |
|
protectedvirtual |
Try to evaluate a single function
| stack | Evaluation stack in use, parameters are popped off this stack and results are pushed back on stack |
| oper | Function to evaluate |
| context | Pointer to arbitrary object to be passed to called methods |
|
virtual |
Try to evaluate a single operation
| stack | Evaluation stack in use, operands are popped off this stack and results are pushed back on stack |
| oper | Operation to execute |
| context | Pointer to arbitrary object to be passed to called methods |
|
inline |
Simplify the expression, performs constant folding
References trySimplify().
|
protectedvirtual |
Skip over comments and whitespaces
| expr | Current parsing context, advances on expression to be compiled |
| context | Pointer to arbitrary object to be passed to called methods |
|
protectedvirtual |
Method to skip over whitespaces, count parsed lines too
| expr | Current parsing context, advances on expression to be compiled |
|
protectedvirtual |
Try to apply simplification to the expression
Referenced by simplify().
|
inline |
Retrieve the internally used unary operators dictionary
References m_unaryOps.
Referenced by ExpEvaluator().
|
protected |
Flag that we encountered a parse or compile error
Referenced by inError().
|
protected |
Internally used for faster appending to the operator codes list
|
protected |
Current line index
Referenced by lineNumber().
|
protected |
Internally used list of operands and operator codes
|
protected |
Internally used operator dictionary
Referenced by operators().
|
protected |
Internally used unary operators dictionary
Referenced by unaryOps().