class ExpEvaluator

An expression parser and evaluator. More...

Full nameTelEngine::ExpEvaluator
Definition#include <yateclass.h>
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Methods

Protected Methods

Protected Members


Detailed Description

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:
operatorsPointer to operator dictionary, longest strings first

explicit  ExpEvaluator (Parser style)

ExpEvaluator

Constructs an evaluator from a parser style

Parameters:
styleStyle of parsing to use

 ExpEvaluator (const ExpEvaluator& original)

ExpEvaluator

Copy constructor

Parameters:
originalEvaluator to copy the operation list from

 ~ExpEvaluator ()

~ExpEvaluator

[virtual]

Destructor

int  compile (const char* expr)

compile

Parse and compile an expression

Parameters:
exprPointer to expression to compile

Returns: Number of expressions compiled, zero on error

bool  evaluate (ObjList* results)

evaluate

Evaluate the expression, optionally return results

Parameters:
resultsList 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:
resultsList 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:
resultsList of parameters to populate with results row
indexIndex of result row, zero to not include an index
prefixPrefix 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:
resultsArray of result rows to populate
indexIndex 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:
extPointer to the extender to use, NULL to remove current

char  skipWhites (const char*& expr)

skipWhites

[protected const]

Helper method to skip over whitespaces

Parameters:
exprPointer 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:
strPointer 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:
errorText of the error
textOptional 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:
exprPointer 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:
exprPointer 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:
operOperator 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:
operOperator 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:
exprPointer to text to check, gets advanced if asked to remove separator
removeTrue 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:
exprPointer 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:
exprPointer 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:
exprPointer 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:
exprPointer 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:
exprPointer 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:
operOperator code to add

void  addOpcode (const String& value)

addOpcode

[protected]

Add a string constant to the expression

Parameters:
valueString value to add, will be pushed on execution

void  addOpcode (long int value)

addOpcode

[protected]

Add an integer constant to the expression

Parameters:
valueInteger 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:
operOperator code to add, must be OpcField or OpcFunc
nameName of the field or function, case sensitive
valueNumerical value used as parameter count to functions

ExpOperation*  popOne (ObjList& stack)

popOne

[protected]

Pops an operand off the evaluation stack

Parameters:
stackEvaluation 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:
stackEvaluation 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:
stackEvaluation stack in use, operands are popped off this stack and results are pushed back on stack
operOperation to execute

Returns: True if evaluation succeeded

bool  runFunction (ObjList& stack, const ExpOperation& oper)

runFunction

[protected virtual]

Try to evaluate a single function

Parameters:
stackEvaluation stack in use, parameters are popped off this stack and results are pushed back on stack
operFunction to evaluate

Returns: True if evaluation succeeded

bool  runField (ObjList& stack, const ExpOperation& oper)

runField

[protected virtual]

Try to evaluate a single field

Parameters:
stackEvaluation stack in use, field value must be pushed on it
operField 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 Mar 8 18:42:27 2011, using kdoc 2.0a54.