|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.rubecula.jep.ExpressionParser
This class is the link from JQuantity to JEP - ExpressionParser depends on JEP, but depends only the com.rubecula.util package from the JQuantity project. There is no dependence on com.rubecula.jquantity, either compile-time or dynamic, in this class -- the only reference is in the main (testing) program (as an example of usage).
Field Summary | |
private java.util.Vector |
_AlgebraicVariables
|
private boolean |
_Debug
|
private org.nfunk.jep.JEP |
_JEP
JEP instance to parse and evaluate expressions. |
private MillFactoryInterface |
_MillFactory
Factory to create Mills for evaluating expressions. |
private long |
_MillID
Counter for identifying mills used for expression evaluation. |
private PresentableNumberFactory |
_NumberFactory
Factory to create numbers, implementing the NumberFactory interface. |
private Lookupable |
_Variables
Store in which to lookup the current values of variables that arise in the terms of expressions. |
Constructor Summary | |
ExpressionParser()
Constructor to create a new expression parser using both JEP and JQuantity. |
Method Summary | |
java.lang.Double |
addAlgebraicVariable(java.lang.String string,
double value)
Method to add a predefined variable to the JEP expression parser. |
Presentable |
evaluate(java.lang.Object parseTree)
Method to evaluate the result of parsing an expression. |
java.util.Collection |
getExpressionVariables()
|
java.lang.String |
getIdentifier()
Method to get the specific identifier for an object. |
static void |
main(java.lang.String[] args)
Main program for testing purposes only. |
java.lang.Object |
parse(java.lang.String expression)
Method to parse an expression and return a reference to the parse tree. |
void |
resetAlgebraicVariables()
Method to remove all predefined variables from the expression parser. |
void |
setDebug(boolean debug)
Method to set the debug flag for this instance to the value of debug. |
void |
setMillFactory(MillFactoryInterface millFactory)
Method to setup the mill factory for the evaluation of expressions, in particular monadic, dyadic operations, pushing and popping of values. |
void |
setVariables(Lookupable variables)
Method to setup the variables map for allowing variables to be dealt with in expressions. |
private java.lang.String |
transform(java.lang.String expression)
Method to transform the operation names, etc. which on input conform to the Microsoft Excel names into JEP operation names). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private final org.nfunk.jep.JEP _JEP
private MillFactoryInterface _MillFactory
private PresentableNumberFactory _NumberFactory
private Lookupable _Variables
private final java.util.Vector _AlgebraicVariables
private long _MillID
private boolean _Debug
Constructor Detail |
public ExpressionParser()
PresentableNumberFactory.PresentableNumberFactory()
.
Method Detail |
public static void main(java.lang.String[] args)
MillFactory
for its
computation mill.
args
- the command line arguments (each argument is an an expression
to be parsed and evaluated).public java.lang.String getIdentifier()
getIdentifier
in interface Identifiable
public void setMillFactory(MillFactoryInterface millFactory)
setMillFactory
in interface ExpressionInterface
millFactory
- a factory for creating mills with which to evaluate
expressions.public void setVariables(Lookupable variables)
setVariables
in interface ExpressionInterface
variables
- a map of variables, so that they can be looked up (may be
null, in which case undeclared variables are not enabled for
this expression parser).public java.lang.Double addAlgebraicVariable(java.lang.String string, double value)
addAlgebraicVariable
in interface ExpressionInterface
string
- the name of the variablevalue
- the desired value of the variable.
public void setDebug(boolean debug)
setDebug
in interface ExpressionInterface
debug
- true or false.public java.lang.Object parse(java.lang.String expression)
parse
in interface ExpressionInterface
expression
- a mathematical expression to parse.
public Presentable evaluate(java.lang.Object parseTree) throws PresentableException
evaluate
in interface ExpressionInterface
parseTree
- the result of previously calling parse(String)
.
PresentableException
- if the result of parsing was an error.private java.lang.String transform(java.lang.String expression)
expression
- an Excel-like mathematical expression to transform.
public java.util.Collection getExpressionVariables()
getExpressionVariables
in interface ExpressionInterface
public void resetAlgebraicVariables()
ExpressionInterface
resetAlgebraicVariables
in interface ExpressionInterface
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |