|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.parser.BaseParser
edu.neu.ccs.parser.JPTParser
Parses and evaulates data Strings
using simple expression evaluation.
The grammar used in this parsing is similar to that defined within the Java Language Specification by James Gosling, Bill Joy, and Guy Steele but as of 2.5.0 we have made significant additions to aid the user of these facilities in interactive mode.
As of 2.5.0, the parser algorithms have all been
refactored down to the new base class called
BaseParser. The purpose of this class
is therefore to define and install constants,
operations, and functions. Each such entity is now
public static final so they may be utilized by some
other class that extends BaseParser if
so desired.
The constants, functions, and operations are all
commented individually. Summary tables of the
constants, functions, and operations are provided
immediately below and repeated in the comments for
the methods
addConstants(),
addFunctions(), and
addOperations().
The summary tables for operations show precedence.
This class now provides an exponentiation operator
denoted ^ that attempts exponentiation
as an integral computation if possible. This is in
contrast to the power function that
always uses Math.pow in its
implementation. By choosing ^ or
power, the user may select implementation.
The function definitions continue to throw exceptions if given incorrect arguments but will no longer throw exceptions if mathematical errors occur. Rather the computation proceeds as in Java itself to produce either an infinity or NaN.
In 2.6.0, added hyperbolic functions.
Constant definitions:
| Identifier | Type | Definition |
true |
XBoolean |
true |
false |
XBoolean |
false |
pi |
XDouble |
Math.PI |
e |
XDouble |
Math.E |
MaxInt |
XInt |
Integer.MAX_VALUE |
maxint |
XInt |
Integer.MAX_VALUE |
MinInt |
XInt |
Integer.MIN_VALUE |
minint |
XInt |
Integer.MIN_VALUE |
MaxLong |
XLong |
Long.MAX_VALUE |
maxlong |
XLong |
Long.MAX_VALUE |
MinLong |
XLong |
Long.MIN_VALUE |
minlong |
XLong |
Long.MIN_VALUE |
MaxDouble |
XDouble |
Double.MAX_VALUE |
maxdouble |
XDouble |
Double.MAX_VALUE |
MinDouble |
XDouble |
Double.MIN_VALUE |
mindouble |
XDouble |
Double.MIN_VALUE |
Infinity |
XDouble |
Double.POSITIVE_INFINITY |
infinity |
XDouble |
Double.POSITIVE_INFINITY |
NaN |
XDouble |
Double.NaN |
nan |
XDouble |
Double.NaN |
Function definitions:
| Function Name | Typical Usage |
abs |
abs(x) |
ceiling |
ceiling(x) |
floor |
floor(x) |
round |
round(x) |
max |
max(x,y) |
min |
min(x,y) |
sqrt |
sqrt(x) |
power |
power(x,y) |
root |
root(x,y) |
todegrees |
todegrees(theta) |
toradians |
toradians(angle) |
sin |
sin(theta) |
sindeg |
sindeg(angle) |
cos |
cos(theta) |
cosdeg |
cosdeg(angle) |
tan |
tan(theta) |
tandeg |
tandeg(angle) |
asin |
asin(s) |
asindeg |
asindeg(s) |
acos |
acos(c) |
acosdeg |
acosdeg(c) |
atan |
atan(t) |
atandeg(t) |
atandeg(t) |
atan2 |
atan2(y,x) |
atan2deg |
atan2deg(y,x) |
exp |
exp(x) |
log |
log(x) |
ln |
ln(x) |
log2 |
log2(x) |
log10 |
log10(x) |
logtobase |
logtobase(x,b) |
sinh |
sinh(x) |
cosh |
cosh(x) |
tanh |
tanh(x) |
asinh |
asinh(x) |
acosh |
acosh(x) |
atanh |
atanh(x) |
In the above table:
x and y
stand for generic variables;
theta
is an angle in radians;
angle
is an angle in degrees;
s, c, t
stand for possible values of
sin, cos, tan;
and b
is the base for a logarithm.
In 2.5.0, random was removed from the
list of functions because as implemented in the class
AbstractFunction a function has a fixed
number of arguments. Instead, random is
now implemented directly in BaseParser
to take one of three forms with the following
interpretations.
| Function Name | Typical Usage | Interpretation |
random |
random() |
Random number between 0 and 1 |
random |
random(x) |
Random number between 0 and x |
random |
random(x,y) |
Random number between x and y |
Operation definitions:
| Precedence | Operations | Symbols |
| 0 | IDENTITY |
None |
| 1 | operationOR |
|| |
| 2 | operationAND |
&& |
| 3 | operationEQ |
== |
| 4 | operationLT |
< |
| 5 | operationPlus |
+ |
| 6 | operationTimes |
* |
| 7 | operationCaret |
^ |
| 8 | operationNOT |
! |
| Field Summary | |
static AbstractFunction |
functionAbs
AbstractFunction to implement abs. |
static AbstractFunction |
functionACos
AbstractFunction to implement acos
based on Math.acos. |
static AbstractFunction |
functionACosDeg
AbstractFunction to implement acosdeg
based on Math.acos
and appropriate radians to degrees conversion. |
static AbstractFunction |
functionACosh
AbstractFunction to implement acosh. |
static AbstractFunction |
functionASin
AbstractFunction to implement asin
based on Math.asin. |
static AbstractFunction |
functionASinDeg
AbstractFunction to implement asindeg
based on Math.asin
and appropriate radians to degrees conversion. |
static AbstractFunction |
functionASinh
AbstractFunction to implement asinh. |
static AbstractFunction |
functionATan
AbstractFunction to implement atan
based on Math.atan. |
static AbstractFunction |
functionATan2
AbstractFunction to implement atan2
based on Math.atan2. |
static AbstractFunction |
functionATan2Deg
AbstractFunction to implement atan2deg
based on Math.atan2
and appropriate radians to degrees conversion. |
static AbstractFunction |
functionATanDeg
AbstractFunction to implement atandeg
based on Math.atan
and appropriate radians to degrees conversion. |
static AbstractFunction |
functionATanh
AbstractFunction to implement atanh. |
static AbstractFunction |
functionCeiling
AbstractFunction to implement ceiling. |
static AbstractFunction |
functionCos
AbstractFunction to implement cos
based on Math.cos. |
static AbstractFunction |
functionCosDeg
AbstractFunction to implement cosdeg
based on Math.cos
and appropriate degrees to radians conversion. |
static AbstractFunction |
functionCosh
AbstractFunction to implement cosh. |
static AbstractFunction |
functionExp
AbstractFunction to implement exp
based on Math.exp. |
static AbstractFunction |
functionFloor
AbstractFunction to implement floor. |
static AbstractFunction |
functionLn
AbstractFunction to implement ln
based on Math.log. |
static AbstractFunction |
functionLog
AbstractFunction to implement log
based on Math.log. |
static AbstractFunction |
functionLog10
AbstractFunction to implement log10. |
static AbstractFunction |
functionLog2
AbstractFunction to implement log2. |
static AbstractFunction |
functionLogToBase
AbstractFunction to implement logtobase. |
static AbstractFunction |
functionMax
AbstractFunction to implement max. |
static AbstractFunction |
functionMin
AbstractFunction to implement min. |
static AbstractFunction |
functionPower
AbstractFunction to implement power
based on Math.pow. |
static AbstractFunction |
functionRoot
AbstractFunction to implement root
based on MathUtilities.root. |
static AbstractFunction |
functionRound
AbstractFunction to implement round. |
static AbstractFunction |
functionSin
AbstractFunction to implement sin
based on Math.sin. |
static AbstractFunction |
functionSinDeg
AbstractFunction to implement sindeg
based on Math.sin
and appropriate degrees to radians conversion. |
static AbstractFunction |
functionSinh
AbstractFunction to implement sinh. |
static AbstractFunction |
functionSqrt
AbstractFunction to implement sqrt
based on Math.sqrt. |
static AbstractFunction |
functionTan
AbstractFunction to implement tan
based on Math.tan. |
static AbstractFunction |
functionTanDeg
AbstractFunction to implement tandeg
based on Math.tan
and appropriate degrees to radians conversion. |
static AbstractFunction |
functionTanh
AbstractFunction to implement tanh. |
static AbstractFunction |
functionToDegrees
AbstractFunction to implement todegrees
based on Math.toDegrees. |
static AbstractFunction |
functionToRadians
AbstractFunction to implement toradians
based on Math.toRadians. |
static BooleanOperation |
operationAND
BooleanOperation to implement "and". |
static NumericOperation |
operationCaret
NumericOperation to implement exponentiation. |
static BooleanOperation |
operationEQ
BooleanOperation to implement equals. |
static BooleanOperation |
operationGE
BooleanOperation to implement greater than or equals. |
static BooleanOperation |
operationGT
BooleanOperation to implement greater than. |
static BooleanOperation |
operationLE
BooleanOperation to implement less than or equals. |
static BooleanOperation |
operationLT
BooleanOperation to implement less than. |
static NumericOperation |
operationMinus
NumericOperation to implement minus. |
static BooleanOperation |
operationNE
BooleanOperation to implement not equals. |
static BooleanOperation |
operationNOT
BooleanOperation to implement "not". |
static BooleanOperation |
operationOR
BooleanOperation to implement "or". |
static NumericOperation |
operationPercent
NumericOperation to implement remainder. |
static NumericOperation |
operationPlus
NumericOperation to implement plus. |
static NumericOperation |
operationSlash
NumericOperation to implement division. |
static NumericOperation |
operationTimes
NumericOperation to implement times. |
| Fields inherited from class edu.neu.ccs.parser.BaseParser |
ARGUMENT_LIST_END, ARGUMENT_LIST_START, ARGUMENT_SEPARATOR, ASSIGNMENT_BY_LET, ASSIGNMENT_BY_SET, data, EVAL, FLOATING, IDENTITY, IF_THEN_ELSE, INTEGRAL, NESTED_EXPRESSION_END, NESTED_EXPRESSION_START, next, OPERATION_PREFIX, RADIX_POINT, RANDOM, suspend, UNDERSCORE |
| Constructor Summary | |
JPTParser()
|
|
| Method Summary | |
protected void |
addConstants()
Adds the standard constants for this parser to the environment. |
protected void |
addFunctions()
Adds the standard functions for this parser to the function table. |
protected void |
addOperations()
Adds the standard operations for this parser to the operation table. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final AbstractFunction functionAbs
abs.
public static final AbstractFunction functionCeiling
ceiling.
public static final AbstractFunction functionFloor
floor.
public static final AbstractFunction functionRound
round.
public static final AbstractFunction functionMax
max.
public static final AbstractFunction functionMin
min.
public static final AbstractFunction functionSqrt
sqrt
based on Math.sqrt.
public static final AbstractFunction functionPower
power
based on Math.pow.
operationCaretpublic static final AbstractFunction functionRoot
root
based on MathUtilities.root.
public static final AbstractFunction functionToDegrees
todegrees
based on Math.toDegrees.
public static final AbstractFunction functionToRadians
toradians
based on Math.toRadians.
public static final AbstractFunction functionSin
sin
based on Math.sin.
public static final AbstractFunction functionSinDeg
sindeg
based on Math.sin
and appropriate degrees to radians conversion.
public static final AbstractFunction functionCos
cos
based on Math.cos.
public static final AbstractFunction functionCosDeg
cosdeg
based on Math.cos
and appropriate degrees to radians conversion.
public static final AbstractFunction functionTan
tan
based on Math.tan.
public static final AbstractFunction functionTanDeg
tandeg
based on Math.tan
and appropriate degrees to radians conversion.
public static final AbstractFunction functionASin
asin
based on Math.asin.
public static final AbstractFunction functionASinDeg
asindeg
based on Math.asin
and appropriate radians to degrees conversion.
public static final AbstractFunction functionACos
acos
based on Math.acos.
public static final AbstractFunction functionACosDeg
acosdeg
based on Math.acos
and appropriate radians to degrees conversion.
public static final AbstractFunction functionATan
atan
based on Math.atan.
public static final AbstractFunction functionATanDeg
atandeg
based on Math.atan
and appropriate radians to degrees conversion.
public static final AbstractFunction functionATan2
atan2
based on Math.atan2.
public static final AbstractFunction functionATan2Deg
atan2deg
based on Math.atan2
and appropriate radians to degrees conversion.
public static final AbstractFunction functionExp
exp
based on Math.exp.
public static final AbstractFunction functionLog
AbstractFunction to implement log
based on Math.log.
This is identical to ln.
public static final AbstractFunction functionLn
AbstractFunction to implement ln
based on Math.log.
This is identical to log.
public static final AbstractFunction functionLog2
AbstractFunction to implement log2.
log2(x) is computed as:
Math.log(x) / Math.log(2)
public static final AbstractFunction functionLog10
AbstractFunction to implement log10.
log10(x) is computed as:
Math.log(x) / Math.log(10)
public static final AbstractFunction functionLogToBase
AbstractFunction to implement logtobase.
logtobase(x,b) is computed as:
Math.log(x) / Math.log(b)
public static final AbstractFunction functionSinh
AbstractFunction to implement sinh.
sinh(x) is computed as:
MathUtilities.sinh(x)
public static final AbstractFunction functionCosh
AbstractFunction to implement cosh.
cosh(x) is computed as:
MathUtilities.cosh(x)
public static final AbstractFunction functionTanh
AbstractFunction to implement tanh.
tanh(x) is computed as:
MathUtilities.tanh(x)
public static final AbstractFunction functionASinh
AbstractFunction to implement asinh.
asinh(x) is computed as:
MathUtilities.asinh(x)
public static final AbstractFunction functionACosh
AbstractFunction to implement acosh.
acosh(x) is computed as:
MathUtilities.acosh(x)
public static final AbstractFunction functionATanh
AbstractFunction to implement atanh.
atanh(x) is computed as:
MathUtilities.atanh(x)
public static final NumericOperation operationPlus
NumericOperation to implement plus.
Symbol: "+".
Unary and binary.
public static final NumericOperation operationMinus
NumericOperation to implement minus.
Symbol: "-".
Unary and binary.
public static final NumericOperation operationTimes
NumericOperation to implement times.
Symbol: "*".
Binary.
public static final NumericOperation operationSlash
NumericOperation to implement division.
Symbol: "/".
Binary.
public static final NumericOperation operationPercent
NumericOperation to implement remainder.
Symbol: "%".
Binary.
public static final NumericOperation operationCaret
NumericOperation to implement exponentiation.
Symbol: "^".
Binary.
If the arguments are integral, that is, of type
XBigInteger, then an effort will be
made to carry out the exponentiation in integral
arithmetic.
If the arguments are not integral or if it is
impossible to do an integral computation, then
this method reverts to using Math.pow.
This operation is more subtle than the function
functionPower introduced in this class.
The power function always uses Math.pow
and makes no attempt to handle integral arguments in
a special way.
It is intentional that this operation and the power function operate differently. In some cases, the user may want an integral computation but in other cases if the internal BigInteger would be extremely large may actually perfer to do the computation using double precision floating point.
functionPowerpublic static final BooleanOperation operationEQ
BooleanOperation to implement equals.
Symbol: "==".
Binary. All types.
public static final BooleanOperation operationNE
BooleanOperation to implement not equals.
Symbol: "!=".
Binary. All types.
public static final BooleanOperation operationLT
BooleanOperation to implement less than.
Symbol: "<".
Binary. All types.
public static final BooleanOperation operationGT
BooleanOperation to implement greater than.
Symbol: ">".
Binary. All types.
public static final BooleanOperation operationLE
BooleanOperation to implement less than or equals.
Symbol: "<=".
Binary. All types.
public static final BooleanOperation operationGE
BooleanOperation to implement greater than or equals.
Symbol: ">=".
Binary. All types.
public static final BooleanOperation operationAND
BooleanOperation to implement "and".
Symbol: "&&".
Binary. Boolean only.
public static final BooleanOperation operationOR
BooleanOperation to implement "or".
Symbol: "||".
Binary. Boolean only.
public static final BooleanOperation operationNOT
BooleanOperation to implement "not".
Symbol: "!".
Binary. Boolean only.
| Constructor Detail |
public JPTParser()
| Method Detail |
protected void addConstants()
Adds the standard constants for this parser to the environment.
| Identifier | Type | Definition |
true |
XBoolean |
true |
false |
XBoolean |
false |
pi |
XDouble |
Math.PI |
e |
XDouble |
Math.E |
MaxInt |
XInt |
Integer.MAX_VALUE |
maxint |
XInt |
Integer.MAX_VALUE |
MinInt |
XInt |
Integer.MIN_VALUE |
minint |
XInt |
Integer.MIN_VALUE |
MaxLong |
XLong |
Long.MAX_VALUE |
maxlong |
XLong |
Long.MAX_VALUE |
MinLong |
XLong |
Long.MIN_VALUE |
minlong |
XLong |
Long.MIN_VALUE |
MaxDouble |
XDouble |
Double.MAX_VALUE |
maxdouble |
XDouble |
Double.MAX_VALUE |
MinDouble |
XDouble |
Double.MIN_VALUE |
mindouble |
XDouble |
Double.MIN_VALUE |
Infinity |
XDouble |
Double.POSITIVE_INFINITY |
infinity |
XDouble |
Double.POSITIVE_INFINITY |
NaN |
XDouble |
Double.NaN |
nan |
XDouble |
Double.NaN |
addConstants in class BaseParserprotected void addFunctions()
Adds the standard functions for this parser to the function table.
| Function Name | Typical Usage |
abs |
abs(x) |
ceiling |
ceiling(x) |
floor |
floor(x) |
round |
round(x) |
max |
max(x,y) |
min |
min(x,y) |
sqrt |
sqrt(x) |
power |
power(x,y) |
root |
root(x,y) |
todegrees |
todegrees(theta) |
toradians |
toradians(angle) |
sin |
sin(theta) |
sindeg |
sindeg(angle) |
cos |
cos(theta) |
cosdeg |
cosdeg(angle) |
tan |
tan(theta) |
tandeg |
tandeg(angle) |
asin |
asin(s) |
asindeg |
asindeg(s) |
acos |
acos(c) |
acosdeg |
acosdeg(c) |
atan |
atan(t) |
atandeg(t) |
atandeg(t) |
atan2 |
atan2(y,x) |
atan2deg |
atan2deg(y,x) |
exp |
exp(x) |
log |
log(x) |
ln |
ln(x) |
log2 |
log2(x) |
log10 |
log10(x) |
logtobase |
logtobase(x,b) |
sinh |
sinh(x) |
cosh |
cosh(x) |
tanh |
tanh(x) |
asinh |
asinh(x) |
acosh |
acosh(x) |
atanh |
atanh(x) |
In the above table:
x and y
stand for generic variables;
theta
is an angle in radians;
angle
is an angle in degrees;
s, c, t
stand for possible values of
sin, cos, tan;
and b
is the base for a logarithm.
In 2.5.0, random was removed from the
list of functions because as implemented in the class
AbstractFunction a function has a fixed
number of arguments. Instead, random is
now implemented directly in BaseParser
to take one of three forms with the following
interpretations.
| Function Name | Typical Usage | Interpretation |
random |
random() |
Random number between 0 and 1 |
random |
random(x) |
Random number between 0 and x |
random |
random(x,y) |
Random number between x and y |
addFunctions in class BaseParserprotected void addOperations()
Adds the standard operations for this parser to the operation table.
Except for the introduction of the ^
operation, follows Arnold, Gosling, Holmes:
The Java Programming Language, Third Edition, 6.10
| Precedence | Operations | Symbols |
| 0 | IDENTITY |
None |
| 1 | operationOR |
|| |
| 2 | operationAND |
&& |
| 3 | operationEQ |
== |
| 4 | operationLT |
< |
| 5 | operationPlus |
+ |
| 6 | operationTimes |
* |
| 7 | operationCaret |
^ |
| 8 | operationNOT |
! |
addOperations in class BaseParseroperationCaret
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||