|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.nfunk.jep.EvaluatorVisitor
This class is used for the evaluation of an expression. It uses the Visitor design pattern to traverse the function tree and evaluate the expression using a stack.
Function nodes are evaluated by first evaluating all the children nodes, then applying the function class associated with the node. Variable and constant nodes are evaluated by pushing their value onto the stack.
Some changes implemented by rjm. Nov 03. Added hook to SpecialEvaluationI. Clears stack before evaluation. Simplifies error handeling by making visit methods throw ParseException. Changed visit(ASTVarNode node) so messages not calculated every time.
Field Summary | |
protected boolean |
errorFlag
Flag for errors during evaluation |
protected java.util.Vector |
errorList
The current error list |
protected java.util.Stack |
stack
Stack used for evaluating the expression |
protected SymbolTable |
symTab
The symbol table for variable lookup |
Constructor Summary | |
EvaluatorVisitor()
Constructor. |
Method Summary | |
protected void |
addToErrorList(java.lang.String errorStr)
Adds an error message to the list of errors |
java.lang.Object |
getValue(Node topNode,
java.util.Vector errorList_in,
SymbolTable symTab_in)
Returns the value of the expression as an object. |
java.lang.Object |
visit(ASTConstant node,
java.lang.Object data)
Visit a constant node. |
java.lang.Object |
visit(ASTFunNode node,
java.lang.Object data)
Visit a function node. |
java.lang.Object |
visit(ASTStart node,
java.lang.Object data)
This method should never be called when evaluating a normal expression. |
java.lang.Object |
visit(ASTVarNode node,
java.lang.Object data)
Visit a variable node. |
java.lang.Object |
visit(SimpleNode node,
java.lang.Object data)
This method should never be called when evaluation a normal expression. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.util.Stack stack
protected java.util.Vector errorList
protected SymbolTable symTab
protected boolean errorFlag
Constructor Detail |
public EvaluatorVisitor()
Method Detail |
protected void addToErrorList(java.lang.String errorStr)
public java.lang.Object getValue(Node topNode, java.util.Vector errorList_in, SymbolTable symTab_in) throws java.lang.Exception
The errorList_in
parameter is used to
add error information that may occur during the evaluation. It is not
required, and may be set to null
if no error information is
needed.
The symTab parameter can be null, if no variables are expected in the expression. If a variable is found, an error is added to the error list.
An exception is thrown, if an error occurs during evaluation.
java.lang.Exception
public java.lang.Object visit(SimpleNode node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public java.lang.Object visit(ASTStart node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public java.lang.Object visit(ASTFunNode node, java.lang.Object data) throws ParseException
If a function implements SpecialEvaluationI then the evaluate method of PFMC is called.
visit
in interface ParserVisitor
ParseException
public java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public java.lang.Object visit(ASTConstant node, java.lang.Object data)
visit
in interface ParserVisitor
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |