public class EvaluatorVisitor extends Object implements ParserVisitor, EvaluatorI
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.
| Modifier and Type | Field and Description |
|---|---|
protected static boolean |
debug
Debug flag
|
protected Stack |
stack
Stack used for evaluating the expression
|
protected SymbolTable |
symTab
The symbol table for variable lookup
|
protected boolean |
trapNullValues
TrapNull
|
| 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.
|
protected Stack stack
protected SymbolTable symTab
protected static final boolean debug
protected boolean trapNullValues
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 EvaluatorInode - 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.ParseExceptionpublic Object visit(SimpleNode node, Object data) throws ParseException
visit in interface ParserVisitorParseExceptionpublic Object visit(ASTStart node, Object data) throws ParseException
visit in interface ParserVisitorParseExceptionpublic Object visit(ASTFunNode node, Object data) throws ParseException
If a function implements SpecialEvaluationI then the evaluate method of PFMC is called.
visit in interface ParserVisitorParseExceptionpublic Object visit(ASTVarNode node, Object data) throws ParseException
visit in interface ParserVisitorParseExceptionpublic Object visit(ASTConstant node, Object data)
visit in interface ParserVisitorpublic boolean isTrapNullValues()
public void setTrapNullValues(boolean b)
b - Copyright © 2018. All rights reserved.