com.singularsys.jep.walkers

## Class PostfixEvaluator

- java.lang.Object
- - com.singularsys.jep.walkers.PostfixTreeWalker
  - - com.singularsys.jep.walkers.PostfixEvaluator

- All Implemented Interfaces:
    Evaluator, JepComponent, java.io.Serializable

      public class PostfixEvaluator
      extends PostfixTreeWalker
      implements Evaluator

  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:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Stack<java.lang.Object>` | `stack`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PostfixEvaluator()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Object` | `eval(Node node)` Evaluates a sub expression.
    `java.lang.Object` | `evaluate(Node node)` Main entry point, evaluates a node and returns and object with the value of the node.
    `JepComponent` | `getLightWeightInstance()` Return new PostfixEvaluator
    `void` | `init(Jep jep)` Initialize the component.
    `protected boolean` | `supressExaminingChildren(Node child)` Whether to examine the children of this nodes.
    `protected void` | `visit(ASTConstant node, int nchildren, int depth)` Visit a constant node
    `protected void` | `visit(ASTFunNode node, int nchildren, int depth)` Visit a function node
    `protected void` | `visit(ASTOpNode node, int nchildren, int depth)` Visit an operator node
    `protected void` | `visit(ASTVarNode node, int nchildren, int depth)` Visit a variable node

    - ### Methods inherited from class com.singularsys.jep.walkers.PostfixTreeWalker

      `walk, walkSubEquations`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### stack

          protected transient java.util.Stack<java.lang.Object> stack

  - ### Constructor Detail

    - #### PostfixEvaluator

          public PostfixEvaluator()

  - ### Method Detail

    - #### evaluate

          public java.lang.Object evaluate(Node node)
                                    throws EvaluationException

      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 interface `Evaluator`
      Parameters:
        `node` - node to evaluate
      Returns:
        value after evaluation
      Throws:
        `EvaluationException` - if errors occur during evaluation;

    - #### visit

          protected void visit(ASTFunNode node,
                               int nchildren,
                               int depth)
                        throws EvaluationException

      Description copied from class: `PostfixTreeWalker`
      Visit a function node
      Specified by:
        `visit` in class `PostfixTreeWalker`
      Parameters:
        `node` - the current node being visited
        `nchildren` - number of children of the node
        `depth` - depth of tree, root node is depth 1.
      Throws:
        `EvaluationException`

    - #### visit

          protected void visit(ASTOpNode node,
                               int nchildren,
                               int depth)
                        throws EvaluationException

      Description copied from class: `PostfixTreeWalker`
      Visit an operator node
      Specified by:
        `visit` in class `PostfixTreeWalker`
      Parameters:
        `node` - the current node being visited
        `nchildren` - number of children of the node
        `depth` - depth of tree, root node is depth 1.
      Throws:
        `EvaluationException`

    - #### visit

          protected void visit(ASTVarNode node,
                               int nchildren,
                               int depth)

      Description copied from class: `PostfixTreeWalker`
      Visit a variable node
      Specified by:
        `visit` in class `PostfixTreeWalker`
      Parameters:
        `node` - the current node being visited
        `nchildren` - number of children of the node
        `depth` - depth of tree, root node is depth 1.

    - #### visit

          protected void visit(ASTConstant node,
                               int nchildren,
                               int depth)
                        throws EvaluationException

      Description copied from class: `PostfixTreeWalker`
      Visit a constant node
      Specified by:
        `visit` in class `PostfixTreeWalker`
      Parameters:
        `node` - the current node being visited
        `nchildren` - number of children of the node
        `depth` - depth of tree, root node is depth 1.
      Throws:
        `EvaluationException`

    - #### supressExaminingChildren

          protected boolean supressExaminingChildren(Node child)

      Description copied from class: `PostfixTreeWalker`
      Whether to examine the children of this nodes. In some cases it is necessary to jump out of traversal strategy to process a node.
      Overrides:
        `supressExaminingChildren` in class `PostfixTreeWalker`
      Returns:
        false unless overridden by sub-class

    - #### eval

          public java.lang.Object eval(Node node)
                                throws EvaluationException

      Description copied from interface: `Evaluator`
      Evaluates a sub expression. This method can be called by PostfixMathCommands which implement `CallbackEvaluationI`
      Specified by:
        `eval` in interface `Evaluator`
      Parameters:
        `node` - node to evaluate
      Returns:
        The value after evaluating the sub expression.
      Throws:
        `EvaluationException` - if errors occur during evaluation;

    - #### init

          public void init(Jep jep)

      Description copied from interface: `JepComponent`
      Initialize the component. This methods 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 interface `JepComponent`
      Parameters:
        `jep` - the current Jep instance

    - #### getLightWeightInstance

          public JepComponent getLightWeightInstance()

      Return new PostfixEvaluator
      Specified by:
        `getLightWeightInstance` in interface `JepComponent`
      Returns:
        either an new instance, or 'this'.

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