Package com.singularsys.jep.walkers
Class PostfixEvaluator
java.lang.Object
com.singularsys.jep.walkers.PostfixTreeWalker
com.singularsys.jep.walkers.PostfixEvaluator
- All Implemented Interfaces:
Evaluator
,JepComponent
,Serializable
Evaluation component that avoids excessive use of the stack for large
expressions. Instead of using recursion to traverse the expression tree,
traversal is based on the PostfixTreeWalker.
- Author:
- Richard Morris
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionEvaluates a sub expression.Main entry point, evaluates a node and returns and object with the value of the node.Return new PostfixEvaluatorvoid
Initialize the component.protected boolean
suppressExaminingChildren
(Node child) Whether to examine the children ofthis
nodes.protected void
visit
(ASTConstant node, int nchildren, int depth) Visit a constant nodeprotected void
visit
(ASTFunNode node, int nchildren, int depth) Visit a function nodeprotected void
Visit an operator nodeprotected void
visit
(ASTVarNode node, int nchildren, int depth) Visit a variable nodeMethods inherited from class com.singularsys.jep.walkers.PostfixTreeWalker
walk, walkSubEquations
-
Field Details
-
stack
-
-
Constructor Details
-
PostfixEvaluator
public PostfixEvaluator()
-
-
Method Details
-
evaluate
Description copied from interface:Evaluator
Main entry point, evaluates a node and returns and object with the value of the node.- Specified by:
evaluate
in interfaceEvaluator
- Parameters:
node
- node to evaluate- Returns:
- value after evaluation
- Throws:
EvaluationException
- if errors occur during evaluation;
-
visit
Description copied from class:PostfixTreeWalker
Visit a function node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.- Throws:
EvaluationException
-
visit
Description copied from class:PostfixTreeWalker
Visit an operator node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.- Throws:
EvaluationException
-
visit
Description copied from class:PostfixTreeWalker
Visit a variable node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.
-
visit
Description copied from class:PostfixTreeWalker
Visit a constant node- Specified by:
visit
in classPostfixTreeWalker
- Parameters:
node
- the current node being visitednchildren
- number of children of the nodedepth
- depth of tree, root node is depth 1.
-
suppressExaminingChildren
Description copied from class:PostfixTreeWalker
Whether to examine the children ofthis
nodes. In some cases it is necessary to jump out of traversal strategy to process a node.- Overrides:
suppressExaminingChildren
in classPostfixTreeWalker
- Returns:
- false unless overridden by sub-class
-
eval
Description copied from interface:Evaluator
Evaluates a sub expression. This method can be called by PostfixMathCommands which implementCallbackEvaluationI
- Specified by:
eval
in interfaceEvaluator
- Parameters:
node
- node to evaluate- Returns:
- The value after evaluating the sub expression.
- Throws:
EvaluationException
- if errors occur during evaluation;
-
init
Description copied from interface:JepComponent
Initialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.- Specified by:
init
in interfaceJepComponent
- Parameters:
jep
- the current Jep instance
-
getLightWeightInstance
Return new PostfixEvaluator- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- either a new instance, null or 'this'.
-