|
|
A class used to build stack based (posifix) expression parsers and evaluators
| enum Parser { C, SQL, } | Parser |
Parsing styles
| 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, } | Opcode |
Operation codes
| explicit ExpEvaluator (const TokenDict* operators = 0)
| ExpEvaluator |
Constructs an evaluator from an operator dictionary
Parameters:
| operators | Pointer to operator dictionary, longest strings first |
| explicit ExpEvaluator (Parser style)
| ExpEvaluator |
Constructs an evaluator from a parser style
Parameters:
| style | Style of parsing to use |
| ExpEvaluator (const ExpEvaluator& original)
| ExpEvaluator |
Copy constructor
Parameters:
| original | Evaluator to copy the operation list from |
| ~ExpEvaluator ()
| ~ExpEvaluator |
[virtual]
Destructor
| int compile (const char* expr)
| compile |
Parse and compile an expression
Parameters:
| expr | Pointer to expression to compile |
Returns: Number of expressions compiled, zero on error
| bool evaluate (ObjList* results)
| evaluate |
Evaluate the expression, optionally return results
Parameters:
| results | List to fill with results row |
Returns: True if expression evaluation succeeded, false on failure
| inline bool evaluate (ObjList& results)
| evaluate |
Evaluate the expression, return computed results
Parameters:
| results | List to fill with results row |
Returns: True if expression evaluation succeeded, false on failure
| int evaluate (NamedList& results, unsigned int index = 0, const char* prefix = 0)
| evaluate |
Evaluate the expression, return computed results
Parameters:
| 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 |
Returns: Number of result columns, -1 on failure
| int evaluate (Array& results, unsigned int index)
| evaluate |
Evaluate the expression, return computed results
Parameters:
| results | Array of result rows to populate |
| index | Index of result row, zero to just set column headers |
Returns: Number of result columns, -1 on failure
| inline bool simplify ()
| simplify |
Simplify the expression, performs constant folding
Returns: True if the expression was simplified
| inline bool null ()
| null |
[const]
Check if the expression is empty (no operands or operators)
Returns: True if the expression is completely empty
| String dump ()
| dump |
[const]
Dump the postfix expression according to current operators dictionary
Returns: String representation of operations
| inline const TokenDict* operators ()
| operators |
Retrieve the internally used operator dictionary
Returns: Pointer to operators dictionary in use
| inline ExpExtender* extender ()
| extender |
[const]
Retrieve the internally used expression extender
Returns: Pointer to the extender in use, NULL if none
| void extender (ExpExtender* ext)
| extender |
Set the expression extender to use in evaluation
Parameters:
| ext | Pointer to the extender to use, NULL to remove current |
| char skipWhites (const char*& expr)
| skipWhites |
[protected const]
Helper method to skip over whitespaces
Parameters:
| expr | Pointer to expression cursor, gets advanced |
Returns: First character after whitespaces where expr points
| int getKeyword (const char* str)
| getKeyword |
[protected const]
Helper method to count characters making a keyword
Parameters:
| str | Pointer to text without whitespaces in front |
Returns: Length of the keyword, 0 if a valid keyword doesn't follow
| bool gotError (const char* error = 0, const char* text = 0)
| gotError |
[protected]
Helper method to display debugging errors internally
Parameters:
| error | Text of the error |
| text | Optional text that caused the error |
Returns: Always returns false
| bool runCompile (const char*& expr)
| runCompile |
[protected virtual]
Runs the parser and compiler for one (sub)expression
Parameters:
| expr | Pointer to text to parse, gets advanced |
Returns: True if one expression was compiled and a separator follows
| Opcode getOperator (const char*& expr)
| getOperator |
[protected const virtual]
Returns next operator in the parsed text
Parameters:
| expr | Pointer to text to parse, gets advanced if succeeds |
Returns: Operator code, OpcNone on failure
| const char* getOperator (Opcode oper)
| getOperator |
[protected const virtual]
Helper method to get the canonical name of an operator
Parameters:
| oper | Operator code |
Returns: name of the operator, NULL if it doesn't have one
| int getPrecedence (Opcode oper)
| getPrecedence |
[protected virtual]
Get the precedence of an operator
Parameters:
| oper | Operator code |
Returns: Precedence of the operator, zero (lowest) if unknown
| bool getSeparator (const char*& expr, bool remove)
| getSeparator |
[protected virtual]
Check if we are at an expression separator and optionally skip past it
Parameters:
| expr | Pointer to text to check, gets advanced if asked to remove separator |
| remove | True to skip past the found separator |
Returns: True if a separator was found
| bool getOperand (const char*& expr)
| getOperand |
[protected virtual]
Get an operand, advance parsing pointer past it
Parameters:
| expr | Pointer to text to parse, gets advanced on success |
Returns: True if succeeded, must add the operand internally
| bool getNumber (const char*& expr)
| getNumber |
[protected virtual]
Get a numerical operand, advance parsing pointer past it
Parameters:
| expr | Pointer to text to parse, gets advanced on success |
Returns: True if succeeded, must add the operand internally
| bool getString (const char*& expr)
| getString |
[protected virtual]
Get a string operand, advance parsing pointer past it
Parameters:
| expr | Pointer to text to parse, gets advanced on success |
Returns: True if succeeded, must add the operand internally
| bool getFunction (const char*& expr)
| getFunction |
[protected virtual]
Get a function call, advance parsing pointer past it
Parameters:
| expr | Pointer to text to parse, gets advanced on success |
Returns: True if succeeded, must add the operand internally
| bool getField (const char*& expr)
| getField |
[protected virtual]
Get a field keyword, advance parsing pointer past it
Parameters:
| expr | Pointer to text to parse, gets advanced on success |
Returns: True if succeeded, must add the operand internally
| void addOpcode (Opcode oper)
| addOpcode |
[protected]
Add a simple operator to the expression
Parameters:
| oper | Operator code to add |
| void addOpcode (const String& value)
| addOpcode |
[protected]
Add a string constant to the expression
Parameters:
| value | String value to add, will be pushed on execution |
| void addOpcode (long int value)
| addOpcode |
[protected]
Add an integer constant to the expression
Parameters:
| value | Integer value to add, will be pushed on execution |
| void addOpcode (Opcode oper, const String& name, long int value = 0)
| addOpcode |
[protected]
Add a function or field to the expression
Parameters:
| 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)
| popOne |
[protected]
Pops an operand off the evaluation stack
Parameters:
| stack | Evaluation stack to remove the operand from |
Returns: Operator removed from stack, NULL if stack underflow
| bool trySimplify ()
| trySimplify |
[protected virtual]
Try to apply simplification to the expression
Returns: True if the expression was simplified
| bool runEvaluate (ObjList& stack)
| runEvaluate |
[protected virtual]
Try to evaluate the expression
Parameters:
| stack | Evaluation stack in use, results are left on stack |
Returns: True if evaluation succeeded
| bool runOperation (ObjList& stack, const ExpOperation& oper)
| runOperation |
[protected virtual]
Try to evaluate a single operation
Parameters:
| stack | Evaluation stack in use, operands are popped off this stack and results are pushed back on stack |
| oper | Operation to execute |
Returns: True if evaluation succeeded
| bool runFunction (ObjList& stack, const ExpOperation& oper)
| runFunction |
[protected virtual]
Try to evaluate a single function
Parameters:
| stack | Evaluation stack in use, parameters are popped off this stack and results are pushed back on stack |
| oper | Function to evaluate |
Returns: True if evaluation succeeded
| bool runField (ObjList& stack, const ExpOperation& oper)
| runField |
[protected virtual]
Try to evaluate a single field
Parameters:
| stack | Evaluation stack in use, field value must be pushed on it |
| oper | Field to evaluate |
Returns: True if evaluation succeeded
| const TokenDict* m_operators | m_operators |
[protected]
| ObjList m_opcodes | m_opcodes |
[protected]
| Generated by: paulc on bussard on Tue Apr 12 17:15:21 2011, using kdoc 2.0a54. |