org.jscience.ml.sbml.jep
Class EvaluatorVisitor

java.lang.Object
  extended by org.jscience.ml.sbml.jep.EvaluatorVisitor
All Implemented Interfaces:
ParserVisitor

public class EvaluatorVisitor
extends java.lang.Object
implements ParserVisitor

This class is used for the evaluation of an expression. It uses the Visitor design pattern to traverse the function tree and evaluate the expression using a stack.

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.


Constructor Summary
EvaluatorVisitor()
          Constructor.
 
Method Summary
 java.lang.Object getValue(Node topNode, java.util.Vector errorList_in)
          Returns the value of the expression as an object.
 java.lang.Object visit(ASTConstant node, java.lang.Object data)
          DOCUMENT ME!
 java.lang.Object visit(ASTElseIfThen node, java.lang.Object data)
          DOCUMENT ME!
 java.lang.Object visit(ASTElse node, java.lang.Object data)
          DOCUMENT ME!
 java.lang.Object visit(ASTFunNode node, java.lang.Object data)
          Visit a function node.
 java.lang.Object visit(ASTIfThen node, java.lang.Object data)
          DOCUMENT ME!
 java.lang.Object visit(ASTPiecewise node, java.lang.Object data)
          DOCUMENT ME!
 java.lang.Object visit(ASTStart node, java.lang.Object data)
          This method should never be called when evaluating a normal expression.
 java.lang.Object visit(ASTVarNode node, java.lang.Object data)
          DOCUMENT ME!
 java.lang.Object visit(SimpleNode node, java.lang.Object data)
          This method should never be called when evaluation a normal expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EvaluatorVisitor

public EvaluatorVisitor()
Constructor. Initialize the stack member

Method Detail

getValue

public java.lang.Object getValue(Node topNode,
                                 java.util.Vector errorList_in)
                          throws java.lang.Exception
Returns the value of the expression as an object. The expression tree is specified with its top node. The algorithm uses a stack for evaluation.

The errorList_in parameter is used to add error information that may occur during the evaluation. It is not required, and may be set to null if no error information is needed.

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.

Returns:
The value of the expression as an object.
Throws:
java.lang.Exception

visit

public java.lang.Object visit(SimpleNode node,
                              java.lang.Object data)
This method should never be called when evaluation a normal expression.

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTStart node,
                              java.lang.Object data)
This method should never be called when evaluating a normal expression.

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTFunNode node,
                              java.lang.Object data)
Visit a function node. The values of the child nodes are first pushed onto the stack. Then the function class associated with the node is used to evaluate the function.

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTVarNode node,
                              java.lang.Object data)
Description copied from interface: ParserVisitor
DOCUMENT ME!

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTConstant node,
                              java.lang.Object data)
Description copied from interface: ParserVisitor
DOCUMENT ME!

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTIfThen node,
                              java.lang.Object data)
Description copied from interface: ParserVisitor
DOCUMENT ME!

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTElse node,
                              java.lang.Object data)
Description copied from interface: ParserVisitor
DOCUMENT ME!

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTPiecewise node,
                              java.lang.Object data)
Description copied from interface: ParserVisitor
DOCUMENT ME!

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!

visit

public java.lang.Object visit(ASTElseIfThen node,
                              java.lang.Object data)
Description copied from interface: ParserVisitor
DOCUMENT ME!

Specified by:
visit in interface ParserVisitor
Parameters:
node - DOCUMENT ME!
data - DOCUMENT ME!
Returns:
DOCUMENT ME!