|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.nfunk.jep.JEP org.lsmp.djep.xjep.XJep
public class XJep
An extended version of JEP adds various routines for working with trees. Has a NodeFactory, and OperatorSet, TreeUtils and Visitors DoNothingVisitor,
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 |
---|
protected NodeFactory nf
protected TreeUtils tu
protected DeepCopyVisitor copier
protected SubstitutionVisitor subv
protected SimplificationVisitor simpv
protected CommandVisitor commandv
protected PrintVisitor pv
Constructor Detail |
---|
public XJep()
protected XJep(XJep j)
public XJep(JEP j)
j
- Method Detail |
---|
public XJep newInstance()
public XJep newInstance(SymbolTable st)
public void addStandardFunctions()
JEP
addStandardFunctions
in class JEP
public void addStandardConstants()
JEP
addStandardConstants
in class JEP
public void addComplex()
JEP
addComplex
in class JEP
public Node deepCopy(Node node) throws ParseException
ParseException
public Node simplify(Node node) throws ParseException
ParseException
public Node preprocess(Node node) throws ParseException
ParseException
public Node substitute(Node orig, java.lang.String name, Node replacement) throws ParseException
ParseException
public Node substitute(Node orig, java.lang.String[] names, Node[] replacements) throws ParseException
ParseException
public void print(Node node)
public void print(Node node, java.io.PrintStream out)
public void println(Node node)
public void println(Node node, java.io.PrintStream out)
public java.lang.String toString(Node node)
public NodeFactory getNodeFactory()
public TreeUtils getTreeUtils()
public PrintVisitor getPrintVisitor()
public java.lang.Object calcVarValue(java.lang.String name) throws java.lang.Exception
java.lang.Exception
public Node continueParsing() throws ParseException
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) {}
ParseException
restartParser(String)
public void restartParser(java.lang.String str)
str
- String containing a sequence of equations separated by semi-colons.continueParsing()
public void restartParser(java.io.Reader reader)
reader
- Reader from which equations separated by semi-colons will be read.continueParsing()
public java.util.Vector getVarsInEquation(Node n, java.util.Vector v)
n
- the top node of the expressionv
- a vector to store the list of variables (new variables will be added on end)
public java.util.Vector recursiveGetVarsInEquation(Node n, java.util.Vector v) throws ParseException
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)
n
- top nodev
- vector for storing results, new variables will be added on the end.
ParseException
- if equation is recursive i.e. x=y; y=x+1;
public java.lang.Object evaluate(PostfixMathCommandI pfmc, Node node) throws ParseException
ParseException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |