# Package com.singularsys.jep.walkers

package com.singularsys.jep.walkers
Expression tree traversal classes.

These classes implement various methods of traversing trees representing equations. Jep 4.1 introduced a generic visitors interface `GenericVisitor<R,D,E>`, and generic base classes `GenericDoNothingVisitor<D>` and `GenericDeepCopyVisitor<D>`. These provide better type safety for subclasses.

For very large equations with 10,000+ nodes the standard `ParserVisitor` class can encounter problems with stack overflows due to recursions. The `PostfixTreeWalker` offers a base class for a traversal strategy which minimises the number of stack frames used and the `PostfixEvaluator` is an evaluator which uses this strategy. These methods visit each node in postfix fashion hence for `1+cos(x)` the nodes are visited in the order `1, x, cos, +`. `PrefixTreeWalker` is similar but visits nodes in a prefix fashion for `1+cos(x)` the nodes are visited in the order `+, 1, cos, x`.

`DoNothingVisitor` and `DeepCopyVisitor` are two base classes for classes which manipulate expressions using a standard recursive traversal. `DoNothingVisitor` visits each node in turn performing no action and returning the node. `DeepCopyVisitor` visits each node returning a copy of that node.

- Related Packages
  Package
  Description
  com.singularsys.jep
  The main package containing the Jep class as well as other core classes.
- Class
  Description
  DeepCopyVisitor
  A Visitor which returns an exact copy of the tree.
  DoNothingVisitor
  A Visitor which visits each node of an expression tree and does nothing.
  ExpressionConsolidator
  Consolidates nested addition and multiplication to produce nary operators.
  GenericDeepCopyVisitor<D>
  A Visitor which returns an exact copy of the tree, creating new nodes for each type.
  GenericDoNothingVisitor<D>
  A Visitor which visits each node, typically return the original node.
  HookRemover
  Remove a specific hook from any node which has it on a tree
  ImportationVisitor
  Imports an expression from one Jep instance into another.
  LightWeightImportationVisitor
  A variant off the `ImportationVisitor` that uses either the same pfmc for a node or its `getLightWeightInstance()` if the function implements `JepComponent`.
  PostfixEvaluator
  Evaluation component that avoids excessive use of the stack for large expressions.
  PostfixTreeWalker
  Base class for routines which use a non-recursive tree walker strategy.
  PrefixTreeDumper
  Dumps the contents of a tree to a specified stream, or to standard output.
  PrefixTreeWalker
  Base class for routines which use a non-recursive tree walker strategy.
  SerializableExpression
  A serializable representation of an expression.
  SerializableExpression.Constant
  An element representing a constant value.
  SerializableExpression.Element
  interface used in internal representation of expression
  SerializableExpression.Function
  An element representing a function.
  SerializableExpression.Operator
  An element representing an operator.
  SerializableExpression.Variable
  An element representing a variable.
  SubstitutionVisitor
  Allows substitution of variable with values or expressions.
  TestingVisitor
  A visitor than can test all nodes in a tree against a set of predicates.
  TreeAnalyzer
  Analyze an expression, counting the number of nodes of each type, and recording which variables, functions and operators occurred in the expression.