org.lsmp.djep.xjep
Class SubstitutionVisitor
java.lang.Object
org.lsmp.djep.xjep.DoNothingVisitor
org.lsmp.djep.xjep.SubstitutionVisitor
- All Implemented Interfaces:
- ParserVisitor
public class SubstitutionVisitor
- extends DoNothingVisitor
Allows substitution of a given variable with an expression tree.
Substitution is best done using the
XJep.substitute
method.
For example
XJepI xjep = ...;
Node node = xjep.parse("x^2+x");
Node sub = xjep.parse("sin(y)");
Node res = xjep.substitute(node,"x",sub,xjep);
Will give the expression "(sin(y))^2+sin(y)".
- Author:
- Rich Morris
Created on 16-Nov-2003
Method Summary |
Node |
substitute(Node orig,
java.lang.String[] names,
Node[] replacements,
XJep xj)
Substitutes all occurrences of a set of variable var with a set of replacements. |
Node |
substitute(Node orig,
java.lang.String name,
Node replacement,
XJep xj)
Substitutes all occurrences of variable var with replacement. |
java.lang.Object |
visit(ASTVarNode node,
java.lang.Object data)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SubstitutionVisitor
public SubstitutionVisitor()
substitute
public Node substitute(Node orig,
java.lang.String name,
Node replacement,
XJep xj)
throws ParseException
- Substitutes all occurrences of variable var with replacement.
Does not do a DeepCopy.
- Parameters:
orig
- the expression we wish to perform the substitution onname
- the name of the variablereplacement
- the expression var is substituted for
- Returns:
- the tree with variable replace (does not do a DeepCopy)
- Throws:
ParseException
substitute
public Node substitute(Node orig,
java.lang.String[] names,
Node[] replacements,
XJep xj)
throws ParseException
- Substitutes all occurrences of a set of variable var with a set of replacements.
Does not do a DeepCopy.
- Parameters:
orig
- the expression we wish to perform the substitution onnames
- the names of the variablereplacements
- the expression var is substituted for
- Returns:
- the tree with variable replace (does not do a DeepCopy)
- Throws:
ParseException
visit
public java.lang.Object visit(ASTVarNode node,
java.lang.Object data)
throws ParseException
- Specified by:
visit
in interface ParserVisitor
- Overrides:
visit
in class DoNothingVisitor
- Throws:
ParseException
http://www.singularsys.com/jep Copyright © 2007 Singular Systems