|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--edu.buffalo.fs7.mathlib.Parse
class providing methods to parse an arithmetic expression. A string with an arithmetic expression is first preprocessed to allow certain short notations such like |01><01| for an outer product, then then string is divided into MathObject tokens by the Tokenizer class. The parse class finally evaluates the expression and returns the result of the expression or throws an exception in case of an error.
Since this class is the central class for evalutating an expression it also provides the mathlib event handling. Everytime there is for example an assignment in an expression and the expression was completely evaluated, a MathlibEvent is fired to notify listeners about the newly assigned variable. The MathlibEvent mechnism is very similar to the event model implemented in Java itself. Potential listener classes need to implement the MathlibEventListener interface and register themselves here in the Parse object.
For this class to have all features, a Mathlib object must be instantiated. Although this class provides static expression evalutation methods, it is strongly recommended to provide a mathlib object in order to use the full functinality (the Mathlib class provides the variable management).
MathlibEvent listeners are for example the classes Mathlib, QVarTree, GateTable.
Tokenizer,
Mathlib,
MathlibEvent,
MathlibEventListener| Field Summary | |
protected static java.lang.String |
category
|
static boolean |
echoAnswer
still in use ? |
protected static java.util.Vector |
listeners
holds the MathlibEventListeners |
protected Mathlib |
mathlib
holds the Mathlib object |
| Constructor Summary | |
Parse(Mathlib mathlib)
creates a Parse object associated with a certain Mathlib object |
|
| Method Summary | |
static void |
addMathlibEventListener(MathlibEventListener m)
registers a MathlibEventListener |
java.lang.String |
evaluateExpression(java.lang.String str)
this method fully evaluates an expression and assignes the result variable. |
static void |
fireMathlibEvent(java.lang.String objectName,
MathObject mathObject,
int action)
creates a MathlibEvent and pumps it to processEvent |
static void |
fireMathlibEvent(java.lang.String objectName,
java.lang.String newName)
creates a MathlibEvent and pumps it to processEvent |
static void |
fireMathlibEvent(java.lang.String objectName,
java.lang.String newName,
java.lang.String category,
MathObject mathObject,
int action)
creates a MathlibEvent and pumps it to processEvent |
static MathObject |
parseExpression(java.lang.String str)
static method which can parse an expression without using variable and without any assignments. |
protected static void |
processEvent(MathlibEvent event)
is called internally by fireMathlibEvent in order to dispatch the event |
static void |
removeMathlibEventListener(MathlibEventListener m)
removes a MathlibEventListener |
static java.lang.String |
replaceSubstring(java.lang.String workStr,
java.lang.String oldStr,
java.lang.String newStr)
static method replacing a substring by another substring used by the preprocessor |
void |
setCategory(java.lang.String newCategory)
set a preset category in order to let all MathlibEvents generated by the parse methods belong to this preset category (not used anymore) |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static boolean echoAnswer
protected static java.util.Vector listeners
protected Mathlib mathlib
protected static java.lang.String category
| Constructor Detail |
public Parse(Mathlib mathlib)
| Method Detail |
public static void addMathlibEventListener(MathlibEventListener m)
m - listener objectpublic static void removeMathlibEventListener(MathlibEventListener m)
protected static void processEvent(MathlibEvent event)
e - MathlibEvent to dispatch
public static void fireMathlibEvent(java.lang.String objectName,
MathObject mathObject,
int action)
objectName - name of the mathobjectmathObject - the actual mathobjectthe - action to perform
public static void fireMathlibEvent(java.lang.String objectName,
java.lang.String newName,
java.lang.String category,
MathObject mathObject,
int action)
objectName - name of the mathobjectnewName - new name of the mathobject in case of a CHANGE_NAM eventcategory - logical category of the mathobjectmathObject - the actual mathobjectthe - action to perform
public static void fireMathlibEvent(java.lang.String objectName,
java.lang.String newName)
objectName - name of the mathobjectnewName - new name of the mathobjectthe - action to performpublic void setCategory(java.lang.String newCategory)
public static MathObject parseExpression(java.lang.String str)
throws java.lang.IllegalArgumentException
str - string to parse
public java.lang.String evaluateExpression(java.lang.String str)
throws java.lang.IllegalArgumentException
str - string to be evaluated.
public static java.lang.String replaceSubstring(java.lang.String workStr,
java.lang.String oldStr,
java.lang.String newStr)
workStr - string to work inoldStr - substring to replacenewStr - string to replace with
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||