public class EvaluatorVisitor extends Object implements ParserVisitor, EvaluatorI, Serializable
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.
Constructor and Description |
---|
EvaluatorVisitor()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
Object |
eval(Node node)
Evaluates a given node, in the current context.
|
Object |
eval(PostfixMathCommandI pfmc,
Node[] children)
Evaluates a PostfixMathCommandI with given arguments.
|
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.
|
Object |
visit(ASTConstant node,
Object data)
Visit a constant node.
|
Object |
visit(ASTFunNode node,
Object data)
Visit a function node.
|
Object |
visit(ASTStart node,
Object data)
This method should never be called when evaluating a normal
expression.
|
Object |
visit(ASTVarNode node,
Object data)
Visit a variable node.
|
Object |
visit(SimpleNode node,
Object data)
This method should never be called when evaluation a normal
expression.
|
public EvaluatorVisitor()
public Object getValue(Node topNode, SymbolTable symTab_in) throws ParseException
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 Object eval(Node node) throws ParseException
eval
in interface EvaluatorI
node
- The node to evaluateParseException
- if errors occur during evaluation;public Object eval(PostfixMathCommandI pfmc, Node[] children) throws ParseException
pfmc
- the command to evaluate.children
- the parameters to the function.ParseException
public Object visit(SimpleNode node, Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public Object visit(ASTStart node, Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public Object visit(ASTFunNode node, Object data) throws ParseException
If a function implements SpecialEvaluationI then the evaluate method of PFMC is called.
visit
in interface ParserVisitor
ParseException
public Object visit(ASTVarNode node, Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public Object visit(ASTConstant node, Object data)
visit
in interface ParserVisitor
public boolean isTrapNullValues()
public void setTrapNullValues(boolean b)
b
- Jas4pp 1.5 © Java Analysis Studio for Particle Physics