|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--opale.mathtools.parser.Parser
This class can parse a string definition of a function and return its value. It's possible to choose the independent variable that must be recognized (for instance 'x', 'y', 'x1' etc...).
The recognised operations are : +, -, *, /, (, ), ^
The recognised functions are :
void addFunc(UnaryFunction f)
).
The recognised constants are : Pi, E
This parser is not case sensitive: "e" and "E" will be interpreted as the string "e".
Constructor Summary | |
Parser()
Instantiate an object of this class |
|
Parser(java.lang.String s)
Instantiate an object of this class with specifying a string to be parsed |
Method Summary | |
void |
addCst(java.lang.String name,
double value)
Add a constant. |
void |
addFunc(UnaryFunction f)
Add a function for the string analyser. |
void |
addVar(java.lang.String name)
Add a variable. |
double |
eval()
Evaluate the function represented by the string. |
double |
getVar(java.lang.String name)
Get the value of a variable. |
static void |
main(java.lang.String[] arg)
|
void |
parseString()
Parse the string defined in this class. |
void |
parseString(java.lang.String s)
Parse a string |
void |
setVar(java.lang.String name,
double value)
Set the value of a variable. |
void |
setVar(java.lang.String name,
java.lang.String value)
Set the value of a variable. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Parser()
public Parser(java.lang.String s)
s,
- the string that will be parsed.Method Detail |
public void parseString(java.lang.String s)
s,
- the string that will be parsed.public void parseString()
public double eval()
public void addFunc(UnaryFunction f)
UnaryFunction
- f, a function that must be recognized in a stringpublic void addVar(java.lang.String name)
String,
- the keyword of the variable that must be parsed (x, y, x2, a etc...).public void setVar(java.lang.String name, double value)
String,
- the keyword of the variable to set.double,
- the value of this variable.public void setVar(java.lang.String name, java.lang.String value)
String,
- the keyword of the variable to set.String,
- a string representation of the value.public double getVar(java.lang.String name)
String,
- the keyword of a variable.public void addCst(java.lang.String name, double value)
String,
- the keyword of the constant.double,
- the value of this constant.public static void main(java.lang.String[] arg)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |