Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.lsmp.djep.xjep
Class XJep

    java.lang.Object
      org.nfunk.jep.JEP
          org.lsmp.djep.xjep.XJep

Direct Known Subclasses:
  DJep

    public class XJep

extends JEP

An extended version of JEP adds various routines for working with trees. Has a NodeFactory, and OperatorSet, TreeUtils and Visitors DoNothingVisitor,

Author:
  Rich Morris Created on 16-Nov-2003

Field Summary
`protected CommandVisitor` | `commandv`
`protected DeepCopyVisitor` | `copier`
`protected NodeFactory` | `nf` Creates new nodes
`protected PrintVisitor` | `pv`
`protected SimplificationVisitor` | `simpv`
`protected SubstitutionVisitor` | `subv`
`protected TreeUtils` | `tu` A few utility functions.

Fields inherited from class org.nfunk.jep.JEP
`allowAssignment, allowUndeclared, errorList, ev, funTab, implicitMul, numberFactory, opSet, parser, symTab`

Constructor Summary
`` | `XJep()` Create a new XJep will all the function of JEP plus printing and other features.
`` | `XJep(JEP j)` Conversion constructor.
`protected` | `XJep(XJep j)` Copy constructions, reuses all the components of argument.

Method Summary
`void` | `addComplex()` Call this function if you want to parse expressions which involve complex numbers.
`void` | `addStandardConstants()` Adds the constants pi and e to the parser.
`void` | `addStandardFunctions()` Adds the standard functions to the parser.
`java.lang.Object` | `calcVarValue(java.lang.String name)` Calculates the value for the variables equation and returns that value.
`Node` | `continueParsing()` Continue parsing without re-initilising the stream.
`Node` | `deepCopy(Node node)` Returns a deep copy of an expression tree.
`java.lang.Object` | `evaluate(PostfixMathCommandI pfmc, Node node)`
`NodeFactory` | `getNodeFactory()` Returns the node factory, used for constructing trees of Nodes.
`PrintVisitor` | `getPrintVisitor()` Returns the PrintVisitor, used for printing equations.
`TreeUtils` | `getTreeUtils()` Returns the TreeUtilitities, used for examining properties of nodes.
`java.util.Vector` | `getVarsInEquation(Node n, java.util.Vector v)` Finds all the variables in an equation.
`XJep` | `newInstance()` Creates a new instance of XJep with the same components as this one.
`XJep` | `newInstance(SymbolTable st)` Creates a new instance of XJep with the same components as this one and the specified symbol table.
`Node` | `preprocess(Node node)` Pre-processes an equation to allow the diff and eval operators to be used.
`void` | `print(Node node)` Prints the expression tree on standard output.
`void` | `print(Node node, java.io.PrintStream out)` Prints the expression tree on given stream.
`void` | `println(Node node)` Prints the expression tree on standard output with newline at end.
`void` | `println(Node node, java.io.PrintStream out)` Prints the expression tree on given stream with newline at end.
`java.util.Vector` | `recursiveGetVarsInEquation(Node n, java.util.Vector v)` Finds all the variables in an equation and if any of those variables are defined by equations find the variables in those equations as well.
`void` | `restartParser(java.io.Reader reader)` Restarts the parser with the given Reader.
`void` | `restartParser(java.lang.String str)` Restarts the parser with the given string.
`Node` | `simplify(Node node)` Returns a simplification of an expression tree.
`Node` | `substitute(Node orig, java.lang.String[] names, Node[] replacements)` Substitute all occurrences of a set of named variable with a set of expression tree.
`Node` | `substitute(Node orig, java.lang.String name, Node replacement)` Substitute all occurrences of a named variable with an expression tree.
`java.lang.String` | `toString(Node node)` Returns a string representation of a expression tree.

Methods inherited from class org.nfunk.jep.JEP
`addConstant, addFunction, addVariable, addVariable, addVariable, evaluate, getAllowAssignment, getAllowUndeclared, getComplexValue, getErrorInfo, getEvaluatorVisitor, getFunctionTable, getImplicitMul, getNumberFactory, getOperatorSet, getParser, getSymbolTable, getTopNode, getTraverse, getValue, getValueAsObject, getVar, getVarValue, hasError, initFunTab, initSymTab, parse, parseExpression, removeFunction, removeVariable, setAllowAssignment, setAllowUndeclared, setImplicitMul, setTraverse, setVarValue`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### nf

    protected NodeFactory nf

  Creates new nodes

### tu

    protected TreeUtils tu

  A few utility functions.

### copier

    protected DeepCopyVisitor copier

### subv

    protected SubstitutionVisitor subv

### simpv

    protected SimplificationVisitor simpv

### commandv

    protected CommandVisitor commandv

### pv

    protected PrintVisitor pv

Constructor Detail

### XJep

    public XJep()

  Create a new XJep will all the function of JEP plus printing and other features.

### XJep

    protected XJep(XJep j)

  Copy constructions, reuses all the components of argument.

### XJep

    public XJep(JEP j)

  Conversion constructor. Turns a JEP object into an XJep object.

  Parameters:
    `j` -

Method Detail

### newInstance

    public XJep newInstance()

  Creates a new instance of XJep with the same components as this one. Sub classes should overwrite this method to create objects of the correct type.

### newInstance

    public XJep newInstance(SymbolTable st)

  Creates a new instance of XJep with the same components as this one and the specified symbol table. Sub classes should overwrite this method to create objects of the correct type.

### addStandardFunctions

    public void addStandardFunctions()

  Description copied from class: `JEP`
  Adds the standard functions to the parser. If this function is not called before parsing an expression, functions such as sin() or cos() would produce an "Unrecognized function..." error. In most cases, this method should be called immediately after the JEP object is created.

  Overrides:
    `addStandardFunctions` in class `JEP`

### addStandardConstants

    public void addStandardConstants()

  Description copied from class: `JEP`
  Adds the constants pi and e to the parser. As addStandardFunctions(), this method should be called immediately after the JEP object is created.

  Overrides:
    `addStandardConstants` in class `JEP`

### addComplex

    public void addComplex()

  Description copied from class: `JEP`
  Call this function if you want to parse expressions which involve complex numbers. This method specifies "i" as the imaginary unit (0,1). Two functions re() and im() are also added for extracting the real or imaginary components of a complex number respectively.

  Overrides:
    `addComplex` in class `JEP`

### deepCopy

    public Node deepCopy(Node node)
                  throws ParseException

  Returns a deep copy of an expression tree.

  Throws:
    `ParseException`

### simplify

    public Node simplify(Node node)
                  throws ParseException

  Returns a simplification of an expression tree.

  Throws:
    `ParseException`

### preprocess

    public Node preprocess(Node node)
                    throws ParseException

  Pre-processes an equation to allow the diff and eval operators to be used.

  Throws:
    `ParseException`

### substitute

    public Node substitute(Node orig,
                           java.lang.String name,
                           Node replacement)
                    throws ParseException

  Substitute all occurrences of a named variable with an expression tree.

  Throws:
    `ParseException`

### substitute

    public Node substitute(Node orig,
                           java.lang.String[] names,
                           Node[] replacements)
                    throws ParseException

  Substitute all occurrences of a set of named variable with a set of expression tree.

  Throws:
    `ParseException`

### print

    public void print(Node node)

  Prints the expression tree on standard output.

### print

    public void print(Node node,
                      java.io.PrintStream out)

  Prints the expression tree on given stream.

### println

    public void println(Node node)

  Prints the expression tree on standard output with newline at end.

### println

    public void println(Node node,
                        java.io.PrintStream out)

  Prints the expression tree on given stream with newline at end.

### toString

    public java.lang.String toString(Node node)

  Returns a string representation of a expression tree.

### getNodeFactory

    public NodeFactory getNodeFactory()

  Returns the node factory, used for constructing trees of Nodes.

### getTreeUtils

    public TreeUtils getTreeUtils()

  Returns the TreeUtilitities, used for examining properties of nodes.

### getPrintVisitor

    public PrintVisitor getPrintVisitor()

  Returns the PrintVisitor, used for printing equations.

### calcVarValue

    public java.lang.Object calcVarValue(java.lang.String name)
                                  throws java.lang.Exception

  Calculates the value for the variables equation and returns that value. If the variable does not have an equation just return its value.

  Throws:
    `java.lang.Exception`

### continueParsing

    public Node continueParsing()
                         throws ParseException

  Continue parsing without re-initilising the stream. Allows re-entrance of parser so that strings like "x=1; y=2; z=3;" can be parsed. When a semi colon is encountered parsing finishes leaving the rest of the string unparsed. Parsing can be resumed from the current position by using this method. For example

       XJep j = new XJep();
       j.restartParser("x=1;y=2; z=3;");
       Node node;
       try {
       while((node = j.continueParsing())!=null) {
          j.println(node);
       } }catch(ParseException e) {}

  Returns:
    top node of equation parsed to date or null if empty equation
  Throws:
    `ParseException`
  See Also:
    `restartParser(String)`

### restartParser

    public void restartParser(java.lang.String str)

  Restarts the parser with the given string.

  Parameters:
    `str` - String containing a sequence of equations separated by semi-colons.
  See Also:
    `continueParsing()`

### restartParser

    public void restartParser(java.io.Reader reader)

  Restarts the parser with the given Reader.

  Parameters:
    `reader` - Reader from which equations separated by semi-colons will be read.
  See Also:
    `continueParsing()`

### getVarsInEquation

    public java.util.Vector getVarsInEquation(Node n,
                                              java.util.Vector v)

  Finds all the variables in an equation.

  Parameters:
    `n` - the top node of the expression
    `v` - a vector to store the list of variables (new variables will be added on end)
  Returns:
    v

### recursiveGetVarsInEquation

    public java.util.Vector recursiveGetVarsInEquation(Node n,
                                                       java.util.Vector v)
                                                throws ParseException

  Finds all the variables in an equation and if any of those variables are defined by equations find the variables in those equations as well. The result is an ordered sequence, evaluating each variable in turn will correctly allow the final equation to be evaluated.

  For example if the equation is `a+b` and `a=c+d`, `b=c+e` then the result will be the sequence `(c,d,a,e,b)`

  Parameters:
    `n` - top node
    `v` - vector for storing results, new variables will be added on the end.
  Returns:
    v, the ordered sequence of variables
  Throws:
    `ParseException` - if equation is recursive i.e. `x=y; y=x+1;`

### evaluate

    public java.lang.Object evaluate(PostfixMathCommandI pfmc,
                                     Node node)
                              throws ParseException

  Throws:
    `ParseException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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