|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.singularsys.jep.Jep
public class Jep
The Jep class is the main interface with which the user should interact. It contains all necessary methods to parse and evaluate expressions.
Basic use can be performed through the parse(String) and evaluate() methods.
Field Summary | |
---|---|
protected boolean |
allowAssignment
Allow Assignment option |
protected boolean |
allowUndeclared
Allow Undeclared Variables option |
protected Evaluator |
evaluator
Evaluator instance used for evaluating parse trees |
protected FunctionTable |
funTab
Function Table |
protected boolean |
implicitMul
Implicit Multiplication option |
protected Node |
lastRootNode
Root node of the last parsed expression |
protected NodeFactory |
nodeFac
Node Factory |
protected NumberFactory |
numFac
Number Factory |
protected OperatorTable |
opTab
Operator Table |
protected Parser |
parser
Parser instance used for parsing expressions |
protected PrintVisitor |
pv
PrintVisitor |
protected VariableFactory |
varFac
Variable Factory |
protected VariableTable |
varTab
Variable Table |
Constructor Summary | |
---|---|
Jep()
Creates a new Jep instance using the standard components with default settings. |
|
Jep(ComponentSet compSet)
Creates a new Jep instance with a specific component set. |
|
Jep(JepComponent[] components)
Creates a new Jep instance with a set of componentents specified by an array of components. |
Method Summary | |
---|---|
PostfixMathCommandI |
addFunction(java.lang.String name,
PostfixMathCommandI pfmc)
Adds a function to the parser. |
boolean |
addStandardConstants()
Adds the constants pi and e to the parser. |
Variable |
addVariable(java.lang.String name)
Adds a variable with a given name. |
Variable |
addVariable(java.lang.String name,
double value)
Adds or sets a double variable with a given name and value. |
Variable |
addVariable(java.lang.String name,
double re,
double im)
Adds or sets a complex variable with a given name and value. |
Variable |
addVariable(java.lang.String name,
java.lang.Object value)
Adds or sets a variable with a given name and value. |
java.lang.Object |
evaluate()
Evaluates the most recently parsed expression. |
java.lang.Object |
evaluate(Node node)
Evaluates the expression tree pointed to by the node parameter. |
double |
evaluateD()
Evaluates the most recently parsed expression and returns the result as a double. |
boolean |
getAllowAssignment()
Whether assignment equation y=x+1 equations are allowed. |
boolean |
getAllowUndeclared()
Returns the value of the allowUndeclared option. |
Evaluator |
getEvaluator()
Returns the evaluator |
FunctionTable |
getFunctionTable()
Returns the function table |
boolean |
getImplicitMul()
Returns the value of the implicit multiplication option. |
Node |
getLastRootNode()
Returns the root node of the last successfully parsed expression |
NodeFactory |
getNodeFactory()
Returns the node factory |
NumberFactory |
getNumberFactory()
Returns the number factory |
OperatorTable |
getOperatorTable()
Returns the operator table |
Parser |
getParser()
Returns the parser |
PrintVisitor |
getPrintVisitor()
Returns the print visitor |
Variable |
getVariable(java.lang.String name)
Returns the Variable instance of the variable
name . |
VariableFactory |
getVariableFactory()
Returns the variable factory |
VariableTable |
getVariableTable()
Returns the variable table |
java.lang.Object |
getVariableValue(java.lang.String name)
Returns the value of the variable name . |
Node |
parse(java.io.Reader reader)
Parses the input from a Reader. |
Node |
parse(java.lang.String str)
Parses a string. |
void |
print()
Print the last parsed expression to System.out. |
void |
print(Node node)
Print an expression to System.out. |
void |
print(Node node,
java.io.PrintStream out)
Print an expression to a given stream. |
void |
println()
Print the last parsed expression to System.out with a new line. |
void |
println(Node node)
Print an expression to System.out with a new line. |
void |
println(Node node,
java.io.PrintStream out)
Print an expression to a given stream with a newline. |
java.lang.Object |
readObject(java.io.ObjectInputStream stream)
|
void |
reinitializeComponents()
|
java.lang.String |
rootNodeToString()
Returns a string representation of the last expression parsed. |
void |
setAllowAssignment(boolean value)
Sets whether assignment equations like y=x+1 are allowed. |
void |
setAllowUndeclared(boolean value)
Sets the value for the undeclared variables option. |
void |
setComponent(JepComponent component)
Sets a single component. |
void |
setComponents(JepComponent[] components)
Sets one or more components for this Jep instance. |
void |
setImplicitMul(boolean value)
Sets the value of the implicit multiplication option. |
java.lang.String |
toString(Node node)
Returns a string representation of an expression. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected NumberFactory numFac
protected VariableFactory varFac
protected NodeFactory nodeFac
protected VariableTable varTab
protected FunctionTable funTab
protected OperatorTable opTab
protected PrintVisitor pv
protected Node lastRootNode
protected Parser parser
protected Evaluator evaluator
protected boolean implicitMul
protected boolean allowUndeclared
protected boolean allowAssignment
Constructor Detail |
---|
public Jep()
public Jep(ComponentSet compSet)
compSet
- The component set to be used.public Jep(JepComponent[] components)
components
- An array of components to initialize Jep with.Method Detail |
---|
public void setComponents(JepComponent[] components)
components
- An array of components to be set.public void reinitializeComponents()
public void setComponent(JepComponent component)
component
- The component to be set.public java.lang.Object readObject(java.io.ObjectInputStream stream) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public NumberFactory getNumberFactory()
public NodeFactory getNodeFactory()
public VariableFactory getVariableFactory()
public FunctionTable getFunctionTable()
public OperatorTable getOperatorTable()
public VariableTable getVariableTable()
public Parser getParser()
public Evaluator getEvaluator()
public PrintVisitor getPrintVisitor()
public Variable addVariable(java.lang.String name)
name
- the name of the variable to be added
Variable
instancepublic Variable addVariable(java.lang.String name, java.lang.Object value)
name
- the name of the variable to be addedvalue
- the value of the variable to be added
Variable
instancepublic Variable addVariable(java.lang.String name, double value)
name
- the name of the variable to be addedvalue
- the value of the variable to be added
Variable
instancepublic Variable addVariable(java.lang.String name, double re, double im)
name
- the name of the variable to be addedre
- the real component of the variable to be addedim
- the imaginary component of the variable to be added
Variable
instancepublic boolean addStandardConstants()
public Variable getVariable(java.lang.String name)
Variable
instance of the variable
name
. If the variable has not been added, null is returned.
name
- the name of the variable
Variable
instance, or null if the variable
has not been added.public java.lang.Object getVariableValue(java.lang.String name)
name
. If the variable has
not been added, or if it's value is null
, null
is returned.
name
- the name of the variable
public void setAllowAssignment(boolean value)
public boolean getAllowAssignment()
public void setAllowUndeclared(boolean value)
If this option is set to false, variables that were not previously added to JEP will produce an error while parsing.
The default value is false.
value
- The boolean option for allowing undeclared variables.public boolean getAllowUndeclared()
public void setImplicitMul(boolean value)
"1 2"is valid and is interpreted as
"1*2".
The default value is false.
value
- The boolean implicit multiplication option.public boolean getImplicitMul()
public PostfixMathCommandI addFunction(java.lang.String name, PostfixMathCommandI pfmc)
name
- the name of the functionpfmc
- the function class instance to be used to evaluate the function
public Node getLastRootNode()
public Node parse(java.io.Reader reader) throws ParseException
reader
- the input reader
ParseException
public Node parse(java.lang.String str) throws ParseException
str
- the input string
ParseException
public double evaluateD() throws EvaluationException
EvaluationException
- if an error occurs while evaluating or
if the returned data type can not be converted to a double
number.public java.lang.Object evaluate() throws EvaluationException
EvaluationException
- if an error occurspublic java.lang.Object evaluate(Node node) throws EvaluationException
EvaluationException
- if an error occurspublic void print(Node node, java.io.PrintStream out)
node
- root node of the expression to printout
- stream to print topublic void print(Node node)
node
- root node of the expression to printpublic void print()
public void println(Node node, java.io.PrintStream out)
node
- root node of the expression to printout
- stream to print topublic void println(Node node)
node
- root node of the expression to printpublic void println()
public java.lang.String toString(Node node)
node
- root node of the expression.
public java.lang.String rootNodeToString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |