|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--org.silence.smushcode.Expression
Expression is the heart of the SMUSHcode75 system. Every SMUSHcode75
statement is parsed and executed by a subclass of Expression.
NOTE: Expression should never be instantiated directly. When a
SMUSHcode75 statement is to be stored in memory, it should be passed
through Expression.classify(). The resulting Expression-derived
object is of the proper class to hold the statement.
classify(org.silence.smushcode.ExpressionCache, java.lang.String)| Field Summary | |
protected boolean |
constantExpr
Stores if this object returns a constant value regardless of context. |
protected java.lang.String |
constantValue
Stores the value returned by this object during evaluation if this object always returns a constant value regardless of the context it was called from. |
protected ExpressionCache |
exprStoreLink
Stores a link back to the cache for this instantiation of the SMUSHcode75 system. |
| Constructor Summary | |
Expression()
Creates an empty SMUSHcode75 statement. |
|
Expression(ExpressionCache newCache,
java.lang.String newExpr)
This constructor creates a base Expression with the contents
newExpr. |
|
| Method Summary | |
static Expression |
classify(ExpressionCache newLink,
java.lang.String newString)
Most of the magic in Expression takes place here. |
java.lang.String[] |
evaluate(ExpressionCaller callerLink)
Calls Expression.evaluate(ExpressionCaller, Vector) with a request only for the
output of the evaluated functions, not the original SMUSHcode75 statements
as well. |
protected java.util.Vector[] |
evaluate(ExpressionCaller callerLink,
java.util.Vector[] evalProgress)
Drives the evaluation of the SMUSHcode75 statements and should be overridden in each class to provide unique functionality. |
protected void |
findConstancy()
Determines if this object will always return the same value regardless of its context. |
protected boolean |
getConstancy()
Returns the value of constantExpr. |
boolean |
logic(ExpressionCaller callerLink)
Determines if the value stored in the Expression is "true" or
"false" in SMUSHcode75 terms. |
static boolean |
logic(java.lang.String input)
Determines if the value passed is "true" or "false" in SMUSHcode75 terms. |
java.lang.String |
noExec()
In Expression's subclasses, noExec() returns the SMUSHcode75
statement stored in the object. |
static java.util.Vector |
separate(ExpressionCache newLink,
java.lang.String newExpr,
char separator)
Primarily for use by the constructors of Expression-derived
classes, separate() will pick out the parameters to the
SMUSHcode75 statement and pull them apart. |
protected void |
setLink(ExpressionCache newLink)
Provides a way to set this object's pointer to an ExpressionCache
object after it has been instantiated. |
java.lang.String |
toString(ExpressionCaller callerLink)
The SMUSHcode75 statement stored in the object is evaluated and its result is returned. |
java.lang.String[][] |
traceExec(ExpressionCaller callerLink)
Calls Expression.evaluate(ExpressionCaller, Vector) with a request for both the
output of the stored statement and the SMUSHcode75 expression that produced
it. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.lang.String constantValue
null, the it is assumed that either (1) the
object does not return a constant value regardless of context or (2) the object
returns a constant value regardless of context but has not yet been evaluated.
protected ExpressionCache exprStoreLink
ExpressionCaller is passed in during
evaluation-time, but several SMUSHcode75 functions need this value at
evaluation-time and passing it in twice is even less elegant than storing it.
protected boolean constantExpr
true by default (for no particular reason).
| Constructor Detail |
public Expression()
Expression-derived
object that properly stores/evaluates its data. classify()
should be used instead.
classify(org.silence.smushcode.ExpressionCache, java.lang.String)
public Expression(ExpressionCache newCache,
java.lang.String newExpr)
throws SMUSHInvalidExpressionException
Expression with the contents
newExpr. It removes all comments, uppercase and whitespace from
the SMUSHcode75 statement (except within the string literals). This
constructor is typically called by classify() before it
does its own processing of the statement.
newCache - a link back to the cache for this instantiation of the
SMUSHcode75 system.newExpr - the SMUSHcode75 statement to be stored in the new Expression
SMUSHInvalidExpressionException - Generated if the SMUSHcode75
statement is invalid for some reason.| Method Detail |
public final java.lang.String[] evaluate(ExpressionCaller callerLink)
Expression.evaluate(ExpressionCaller, Vector) with a request only for the
output of the evaluated functions, not the original SMUSHcode75 statements
as well.
callerLink - a link back to the ExpressionCaller that holds this
instance's evaluation stack.
ExpressionCaller,
org.silence.smushcode.Expression#evaluate(org.silence.smushcode.ExpressionCaller, java.lang.util.Vector)public final java.lang.String[][] traceExec(ExpressionCaller callerLink)
Expression.evaluate(ExpressionCaller, Vector) with a request for both the
output of the stored statement and the SMUSHcode75 expression that produced
it.
callerLink - a link back to the ExpressionCaller that holds this
instance's evaluation stack.
traceExec(ExpressionCaller)[SmushcodeDefines.indexNoExec][]
contains the original unevaluated expressions while traceExec(ExpressionCaller)[SmushcodeDefines.indexExec][]
contains their output.ExpressionCaller,
org.silence.smushcode.Expression#evaluate(org.silence.smushcode.ExpressionCaller, java.lang.util.Vector),
SmushcodeDefines.indexNoExec,
SmushcodeDefines.indexExec
protected java.util.Vector[] evaluate(ExpressionCaller callerLink,
java.util.Vector[] evalProgress)
Expression
provides no special functionality, this function only returns the string
stored within the object.
callerLink - a link back to the ExpressionCaller that holds this
instance's evaluation stack.evalProgress - an array of Vectors that contain the output
and (possibly) the original expressions. If evalProgress[SmushcodeDefines.indexNoExec]
is null, the original expressions are not generated.
Vectors with the output and (possibly)
original statement from this object added to the end.ExpressionCallerpublic final java.lang.String toString(ExpressionCaller callerLink)
callerLink - a link back to the ExpressionCaller that holds this
instance's evaluation stack.
ExpressionCaller,
evaluate(org.silence.smushcode.ExpressionCaller),
org.silence.smushcode.Expression#evaluate(org.silence.smushcode.ExpressionCaller, java.lang.util.Vector),
traceExec(org.silence.smushcode.ExpressionCaller)public java.lang.String noExec()
Expression's subclasses, noExec() returns the SMUSHcode75
statement stored in the object. Since the base Expression
class has no special properties, the output of noExec() is the
same as toString().
public boolean logic(ExpressionCaller callerLink)
Expression is "true" or
"false" in SMUSHcode75 terms. In SMUSHcode75, an Expression
is "false" if it evaluates to the string "0". Everything else is "true".
This function simply returns logic(toString(callerLink)).
public static boolean logic(java.lang.String input)
input - the value to be examined for "trueness".
public static Expression classify(ExpressionCache newLink,
java.lang.String newString)
throws SMUSHInvalidExpressionException
Expression takes place here. This function
is the only way that new Expression-derived objects should
be created. The unparsed SMUSHcode75 statement is passed to classify()
and an Expression-derived object that contains the SMUSHcode75
is returned.
The magic of this function is that it identifies the type of SMUSHcode75
statement it has been passed, finds the appropriate Java class to hold it
and instantiates an object of that class. The type of SMUSHcode75
statement is determined according to the SMUSHcode75 EBNF specifications.
Note that SMUSHcode75 functions each have their own classes, which
classify() finds dynamically. The EBNF specs for SMUSHcode75
and the delimiters for each type of statement are contained in the
comments for SmushcodeDefines.
newLink - a link back to the cache for this instantiation of the
SMUSHcode75 system.newString - the unparsed SMUSHcode75 statement to be stored in a new
Expression-derived object
Expression-derived object holding the parsed
SMUSHcode75 statement.
SMUSHInvalidExpressionException - Generated if the SMUSHcode75
statement is invalid for some reason.SmushcodeDefines
public static java.util.Vector separate(ExpressionCache newLink,
java.lang.String newExpr,
char separator)
throws SMUSHInvalidExpressionException
Expression-derived
classes, separate() will pick out the parameters to the
SMUSHcode75 statement and pull them apart. The parameters are returned
as individual Expression-derived objects stored in an
Vector. separate() calls classify() for
each parameter located.
newLink - a link back to the cache for this instantiation of the
SMUSHcode75 system.newExpr - the String containing the SMUSHcode75 statement's parameters.separator - the character that separates the parameters within newExpr.
SMUSHInvalidExpressionException - Generated if the SMUSHcode75
statement is invalid for some reason.protected void setLink(ExpressionCache newLink)
ExpressionCache
object after it has been instantiated.
newLink - a link back to the cache for this instantiation of the
SMUSHcode75 system.protected void findConstancy()
Expression. Because Expression provides no special
functionality, this function simply sets constantExpr to true.
constantExprprotected boolean getConstancy()
constantExpr.
constantExpr.constantExpr
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||