org.lsmp.djep.xjep
Class SubstitutionVisitor

java.lang.Object
  extended byorg.lsmp.djep.xjep.DoNothingVisitor
      extended byorg.lsmp.djep.xjep.SubstitutionVisitor
All Implemented Interfaces:
ParserVisitor

public class SubstitutionVisitor
extends DoNothingVisitor

Allows substution of a given variable with an expresion 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 expresion "(sin(y))^2+sin(y)".

Author:
Rich Morris Created on 16-Nov-2003

Constructor Summary
SubstitutionVisitor()
           
 
Method Summary
 Node substitute(Node orig, java.lang.String[] names, Node[] replacements, XJep xjep)
          Substitutes all occurences of a set of variable var with a set of replacements.
 Node substitute(Node orig, java.lang.String name, Node replacement, XJep xjep)
          Substitutes all occurences of variable var with replacement.
 java.lang.Object visit(ASTVarNode node, java.lang.Object data)
           
 
Methods inherited from class org.lsmp.djep.xjep.DoNothingVisitor
acceptChildrenAsArray, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SubstitutionVisitor

public SubstitutionVisitor()
Method Detail

substitute

public Node substitute(Node orig,
                       java.lang.String name,
                       Node replacement,
                       XJep xjep)
                throws ParseException
Substitutes all occurences of variable var with replacement. Does not do a DeepCopy.

Parameters:
orig - the expresion we wish to perform the substitution on
name - the name of the variable
replacement - 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 xjep)
                throws ParseException
Substitutes all occurences of a set of variable var with a set of replacements. Does not do a DeepCopy.

Parameters:
orig - the expresion we wish to perform the substitution on
names - the names of the variable
replacements - 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 © 2004 Singular Systems