Class Evaluator

All Implemented Interfaces:
GJVisitor<Object,EvalContext>
Direct Known Subclasses:
SqlGenerator

This class traverses (and evaluates) an expression AST graph. It traverses the AST in depth-first order (by extending the ObjectDepthFirst visitor class generated by jtb). This class implements the 'Visitor' design pattern.

Each visit() method in this class takes two parameters, the first being the node being visited, and the second contains an EvalContext object containing the variables and functions which can be referenced within the expression. The visitor (i.e. this class) is then passed to it's children nodes using the nodes' accept() method (generated by jtb).

Variables can be any wrappered primitive type (e.g. Long, Integer, ...), although mathematical evaluation (+, -, /, etc) are currently only implemented for Doubles and Longs.

This class can be considered thread-safe, since it holds no instance-wide state. (All methods that require access to a EvalContext have it passed in through a method parameter). i.e. many threads may use the same Evaluator instance to evaluate different expressions.

NB: In the javadocs below, "lhs" refers to the left-hand-side value of any binary operation, and "rhs" refers to the right-hand-side value; e.g. in "3 + 4", the lhs is "3", the rhs is "4" and the op is "+".

Author:
knoxg