#include <yateclass.h>
Public Types | |
| enum | Parser { C, SQL } |
| enum | Opcode { OpcNone, OpcNull, OpcPush, OpcDrop, OpcDup, OpcSwap, OpcRot, OpcOver, OpcAdd, OpcSub, OpcMul, OpcDiv, OpcMod, OpcNeg, 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 } |
Public Member Functions | |
| ExpEvaluator (const TokenDict *operators=0) | |
| ExpEvaluator (Parser style) | |
| ExpEvaluator (const ExpEvaluator &original) | |
| virtual | ~ExpEvaluator () |
| int | compile (const char *expr) |
| bool | evaluate (ObjList *results) |
| bool | evaluate (ObjList &results) |
| int | evaluate (NamedList &results, unsigned int index=0, const char *prefix=0) |
| int | evaluate (Array &results, unsigned int index) |
| bool | simplify () |
| bool | null () const |
| String | dump () const |
| const TokenDict * | operators () |
| ExpExtender * | extender () const |
| void | extender (ExpExtender *ext) |
Protected Member Functions | |
| char | skipWhites (const char *&expr) const |
| int | getKeyword (const char *str) const |
| bool | gotError (const char *error=0, const char *text=0) |
| virtual bool | runCompile (const char *&expr) |
| virtual Opcode | getOperator (const char *&expr) const |
| virtual const char * | getOperator (Opcode oper) const |
| virtual int | getPrecedence (Opcode oper) |
| virtual bool | getSeparator (const char *&expr, bool remove) |
| virtual bool | getOperand (const char *&expr) |
| virtual bool | getNumber (const char *&expr) |
| virtual bool | getString (const char *&expr) |
| virtual bool | getFunction (const char *&expr) |
| virtual bool | getField (const char *&expr) |
| void | addOpcode (Opcode oper) |
| void | addOpcode (const String &value) |
| void | addOpcode (long int value) |
| void | addOpcode (Opcode oper, const String &name, long int value=0) |
| ExpOperation * | popOne (ObjList &stack) |
| virtual bool | trySimplify () |
| virtual bool | runEvaluate (ObjList &stack) |
| virtual bool | runOperation (ObjList &stack, const ExpOperation &oper) |
| virtual bool | runFunction (ObjList &stack, const ExpOperation &oper) |
| virtual bool | runField (ObjList &stack, const ExpOperation &oper) |
Protected Attributes | |
| const TokenDict * | m_operators |
| ObjList | m_opcodes |
A class used to build stack based (posifix) expression parsers and evaluators
| enum Parser |
Parsing styles
| enum Opcode |
Operation codes
| ExpEvaluator | ( | const TokenDict * | operators = 0 |
) | [explicit] |
Constructs an evaluator from an operator dictionary
| operators | Pointer to operator dictionary, longest strings first |
| ExpEvaluator | ( | Parser | style | ) | [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 |
| virtual ~ExpEvaluator | ( | ) | [virtual] |
Destructor
| int compile | ( | const char * | expr | ) |
Parse and compile an expression
| expr | Pointer to expression to compile |
| bool evaluate | ( | ObjList * | results | ) |
Evaluate the expression, optionally return results
| results | List to fill with results row |
| bool evaluate | ( | ObjList & | results | ) | [inline] |
Evaluate the expression, return computed results
| results | List to fill with results row |
| int evaluate | ( | NamedList & | results, | |
| unsigned int | index = 0, |
|||
| const char * | prefix = 0 | |||
| ) |
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 |
| int evaluate | ( | Array & | results, | |
| unsigned int | index | |||
| ) |
Evaluate the expression, return computed results
| results | Array of result rows to populate | |
| index | Index of result row, zero to just set column headers |
| bool simplify | ( | ) | [inline] |
Simplify the expression, performs constant folding
| bool null | ( | ) | const [inline] |
Check if the expression is empty (no operands or operators)
| String dump | ( | ) | const |
Dump the postfix expression according to current operators dictionary
| const TokenDict* operators | ( | ) | [inline] |
Retrieve the internally used operator dictionary
| ExpExtender* extender | ( | ) | const [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 |
| char skipWhites | ( | const char *& | expr | ) | const [protected] |
Helper method to skip over whitespaces
| expr | Pointer to expression cursor, gets advanced |
| int getKeyword | ( | const char * | str | ) | const [protected] |
Helper method to count characters making a keyword
| str | Pointer to text without whitespaces in front |
| bool gotError | ( | const char * | error = 0, |
|
| const char * | text = 0 | |||
| ) | [protected] |
Helper method to display debugging errors internally
| error | Text of the error | |
| text | Optional text that caused the error |
| virtual bool runCompile | ( | const char *& | expr | ) | [protected, virtual] |
Runs the parser and compiler for one (sub)expression
| expr | Pointer to text to parse, gets advanced |
| virtual Opcode getOperator | ( | const char *& | expr | ) | const [protected, virtual] |
Returns next operator in the parsed text
| expr | Pointer to text to parse, gets advanced if succeeds |
| virtual const char* getOperator | ( | Opcode | oper | ) | const [protected, virtual] |
Helper method to get the canonical name of an operator
| oper | Operator code |
| virtual int getPrecedence | ( | Opcode | oper | ) | [protected, virtual] |
Get the precedence of an operator
| oper | Operator code |
| virtual bool getSeparator | ( | const char *& | expr, | |
| bool | remove | |||
| ) | [protected, virtual] |
Check if we are at an expression separator and optionally skip past it
| expr | Pointer to text to check, gets advanced if asked to remove separator | |
| remove | True to skip past the found separator |
| virtual bool getOperand | ( | const char *& | expr | ) | [protected, virtual] |
Get an operand, advance parsing pointer past it
| expr | Pointer to text to parse, gets advanced on success |
| virtual bool getNumber | ( | const char *& | expr | ) | [protected, virtual] |
Get a numerical operand, advance parsing pointer past it
| expr | Pointer to text to parse, gets advanced on success |
| virtual bool getString | ( | const char *& | expr | ) | [protected, virtual] |
Get a string operand, advance parsing pointer past it
| expr | Pointer to text to parse, gets advanced on success |
| virtual bool getFunction | ( | const char *& | expr | ) | [protected, virtual] |
Get a function call, advance parsing pointer past it
| expr | Pointer to text to parse, gets advanced on success |
| virtual bool getField | ( | const char *& | expr | ) | [protected, virtual] |
Get a field keyword, advance parsing pointer past it
| expr | Pointer to text to parse, gets advanced on success |
| void addOpcode | ( | Opcode | oper | ) | [protected] |
Add a simple operator to the expression
| oper | Operator code to add |
| void addOpcode | ( | const String & | value | ) | [protected] |
Add a string constant to the expression
| value | String value to add, will be pushed on execution |
| void addOpcode | ( | long int | value | ) | [protected] |
Add an integer constant to the expression
| value | Integer value to add, will be pushed on execution |
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 |
| ExpOperation* popOne | ( | ObjList & | stack | ) | [protected] |
Pops an operand off the evaluation stack
| stack | Evaluation stack to remove the operand from |
| virtual bool trySimplify | ( | ) | [protected, virtual] |
Try to apply simplification to the expression
| virtual bool runEvaluate | ( | ObjList & | stack | ) | [protected, virtual] |
Try to evaluate the expression
| stack | Evaluation stack in use, results are left on stack |
| virtual bool runOperation | ( | ObjList & | stack, | |
| const ExpOperation & | oper | |||
| ) | [protected, 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 |
| virtual bool runFunction | ( | ObjList & | stack, | |
| const ExpOperation & | oper | |||
| ) | [protected, virtual] |
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 |
| virtual bool runField | ( | ObjList & | stack, | |
| const ExpOperation & | oper | |||
| ) | [protected, virtual] |
Try to evaluate a single field
| stack | Evaluation stack in use, field value must be pushed on it | |
| oper | Field to evaluate |
const TokenDict* m_operators [protected] |
Internally used operator dictionary
1.5.6