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
Fields -
Constructor Summary
Constructors -
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 PostfixEvaluatorvoidInitialize the component.protected booleansuppressExaminingChildren(Node child) Whether to examine the children ofthisnodes.protected voidvisit(ASTConstant node, int nchildren, int depth) Visit a constant nodeprotected voidvisit(ASTFunNode node, int nchildren, int depth) Visit a function nodeprotected voidVisit an operator nodeprotected voidvisit(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:EvaluatorMain entry point, evaluates a node and returns and object with the value of the node.- Specified by:
evaluatein interfaceEvaluator- Parameters:
node- node to evaluate- Returns:
- value after evaluation
- Throws:
EvaluationException- if errors occur during evaluation;
-
visit
Description copied from class:PostfixTreeWalkerVisit a function node- Specified by:
visitin 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:PostfixTreeWalkerVisit an operator node- Specified by:
visitin 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:PostfixTreeWalkerVisit a variable node- Specified by:
visitin 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:PostfixTreeWalkerVisit a constant node- Specified by:
visitin 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:PostfixTreeWalkerWhether to examine the children ofthisnodes. In some cases it is necessary to jump out of traversal strategy to process a node.- Overrides:
suppressExaminingChildrenin classPostfixTreeWalker- Returns:
- false unless overridden by sub-class
-
eval
Description copied from interface:EvaluatorEvaluates a sub expression. This method can be called by PostfixMathCommands which implementCallbackEvaluationI- Specified by:
evalin 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:JepComponentInitialize 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:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
getLightWeightInstance
Return new PostfixEvaluator- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-