com.singularsys.jep.walkers
Class ExpressionConsolidator
java.lang.Object
com.singularsys.jep.walkers.DoNothingVisitor
com.singularsys.jep.walkers.DeepCopyVisitor
com.singularsys.jep.walkers.ExpressionConsolidator
- All Implemented Interfaces:
- JepComponent, ParserVisitor, java.io.Serializable
public class ExpressionConsolidator
- extends DeepCopyVisitor
Consolidates nested addition and multiplication to produce nary operators.
For example (x+y)+z -> +(x,y,z)
- Author:
- Richard Morris
- See Also:
- Serialized Form
Method Summary |
boolean |
add(Operator op)
Adds an addition operator to be consolidated. |
Node |
consolidate(Node node)
|
protected Node[] |
consolidateChildren(Operator op,
Node[] children)
Creates an array of Nodes, if the child is an ASTOpNode
whose operator is op, then the children of that child will be added
otherwise the child is added. |
java.util.List<Operator> |
getOps()
The list of operators which are consolidated |
java.lang.Object |
visit(ASTOpNode node,
java.lang.Object data)
Visit a operator node. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ops
protected java.util.List<Operator> ops
ExpressionConsolidator
public ExpressionConsolidator(Jep j)
- Default constructor, Add and Multiply are consolidated.
- Parameters:
j
-
consolidate
public Node consolidate(Node node)
throws JepException
- Throws:
JepException
consolidateChildren
protected Node[] consolidateChildren(Operator op,
Node[] children)
- Creates an array of Nodes, if the child is an ASTOpNode
whose operator is op, then the children of that child will be added
otherwise the child is added.
- Parameters:
op
- children
-
- Returns:
- a new list of nodes
visit
public java.lang.Object visit(ASTOpNode node,
java.lang.Object data)
throws JepException
- Description copied from class:
DoNothingVisitor
- Visit a operator node.
Can be overridden by sub-classes.
- Specified by:
visit
in interface ParserVisitor
- Overrides:
visit
in class DeepCopyVisitor
- Throws:
JepException
add
public boolean add(Operator op)
- Adds an addition operator to be consolidated.
- Parameters:
op
- operator to use
- Returns:
- true
getOps
public java.util.List<Operator> getOps()
- The list of operators which are consolidated
- Returns:
- the list
Copyright © 2010 Singular Systems http://www.singularsys.com/jep