com.singularsys.jep.walkers
Class PostfixTreeWalker

java.lang.Object
  extended by com.singularsys.jep.walkers.PostfixTreeWalker
Direct Known Subclasses:
PostfixEvaluator, SerializableExpression, TreeAnalyzer

public abstract class PostfixTreeWalker
extends java.lang.Object

Base class for routines which use a non recursive tree walker strategy. The typical recursive strategy can use a lot of stack frames for very large expressions these can cause a stack overflow exception. Subclasses should implement the visit methods. to transverse the various nodes. In general these methods should not recursively walk the child nodes. This class uses a postfix transversal scheme hence the nodes of '1+2' will be visited in the order 1,2,+.

Since:
3.2 depth of root node is now 1 not 0
Author:
Richard Morris
See Also:
PrefixTreeWalker

Constructor Summary
PostfixTreeWalker()
           
 
Method Summary
protected  boolean supressExaminingChildren(Node child)
          Whether to examine the children of this nodes.
protected abstract  void visit(ASTConstant node, int nchildren, int depth)
          Visit a constant node
protected abstract  void visit(ASTFunNode node, int nchildren, int depth)
          Visit a function node
protected abstract  void visit(ASTOpNode node, int nchildren, int depth)
          Visit an operator node
protected abstract  void visit(ASTVarNode node, int nchildren, int depth)
          Visit a variable node
protected  void walk(Node top)
          Start transversal of the expression.
protected  void walkSubEquations(Node top)
          If a supressExaminingChildren() returns true, then the children of the node will not be visited by default.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostfixTreeWalker

public PostfixTreeWalker()
Method Detail

walk

protected final void walk(Node top)
                   throws JepException
Start transversal of the expression.

Parameters:
top - top node for the expression
Throws:
JepException

supressExaminingChildren

protected boolean supressExaminingChildren(Node child)
Whether to examine the children of this nodes. In some cases it is necessary to jump out of transversal strategy to process a node.

Parameters:
child -
Returns:
false unless overridden by sub-class

walkSubEquations

protected final void walkSubEquations(Node top)
                               throws JepException
If a supressExaminingChildren() returns true, then the children of the node will not be visited by default. This method allows a sub-class to visit the children of such a node if needed.

Parameters:
top -
Throws:
JepException

visit

protected abstract void visit(ASTFunNode node,
                              int nchildren,
                              int depth)
                       throws JepException
Visit a function node

Parameters:
node - the current node being visited
nchildren - number of children of the node
depth - depth of tree, root node is depth 1.
Throws:
JepException

visit

protected abstract void visit(ASTOpNode node,
                              int nchildren,
                              int depth)
                       throws JepException
Visit an operator node

Parameters:
node - the current node being visited
nchildren - number of children of the node
depth - depth of tree, root node is depth 1.
Throws:
JepException

visit

protected abstract void visit(ASTVarNode node,
                              int nchildren,
                              int depth)
                       throws JepException
Visit a variable node

Parameters:
node - the current node being visited
nchildren - number of children of the node
depth - depth of tree, root node is depth 1.
Throws:
JepException

visit

protected abstract void visit(ASTConstant node,
                              int nchildren,
                              int depth)
                       throws JepException
Visit a constant node

Parameters:
node - the current node being visited
nchildren - number of children of the node
depth - depth of tree, root node is depth 1.
Throws:
JepException


Copyright © 2010 Singular Systems http://www.singularsys.com/jep