|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.nfunk.jep.EvaluatorVisitor
public class 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 handling by making visit methods throw ParseException. Changed visit(ASTVarNode node) so messages not calculated every time.
Field Summary | |
---|---|
protected static boolean |
debug
Debug flag |
protected java.util.Stack |
stack
Stack used for evaluating the expression |
protected SymbolTable |
symTab
The symbol table for variable lookup |
protected boolean |
trapNullValues
TrapNull |
Constructor Summary | |
---|---|
EvaluatorVisitor()
Constructor. |
Method Summary | |
---|---|
java.lang.Object |
eval(Node node)
Evaluates a node and returns and object with the value of the node. |
java.lang.Object |
eval(PostfixMathCommandI pfmc,
Node[] children)
Evaluates a PostfixMathCommandI with given arguments. |
java.lang.Object |
getValue(Node topNode,
SymbolTable symTab_in)
Returns the value of the expression as an object. |
boolean |
isTrapNullValues()
Tests whether null variable values are trapped by evaluator. |
void |
setTrapNullValues(boolean b)
Sets the behaviour when a variable's value is null. |
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 SymbolTable symTab
protected static final boolean debug
protected boolean trapNullValues
Constructor Detail |
---|
public EvaluatorVisitor()
Method Detail |
---|
public java.lang.Object getValue(Node topNode, SymbolTable symTab_in) throws ParseException
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.
ParseException
- if there is a problem with the evaluation.public java.lang.Object eval(Node node) throws ParseException
EvaluatorI
eval
in interface EvaluatorI
ParseException
- if errors occur during evaluation;public java.lang.Object eval(PostfixMathCommandI pfmc, Node[] children) throws ParseException
pfmc
- the command to evaluate.children
- the parameters to the function.
ParseException
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
public boolean isTrapNullValues()
public void setTrapNullValues(boolean b)
b
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |