FormulaParserLL3Constants
, IFormulaParser
public class FormulaParserLL3 extends java.lang.Object implements IFormulaParser, FormulaParserLL3Constants
Support almost the same syntax as defined in the LibSBML L3 parser. The things not supported for now are the units associated with numbers.
Parsing of the various MathML functions and constants are all
case-sensitive by default: names such as
Cos
and COS
are not parsed as the MathML cosine
operator, <cos>
.
You can change this behaviour by using the setCaseSensitive(boolean)
method.
Token | Operation | Class | Precedence | Associates |
---|---|---|---|---|
name | symbol reference | operand | 8 | n/a |
( expression) | expression grouping | operand | 8 | n/a |
f( ...) | function call | prefix | 8 | left |
^ | power | binary | 7 | left |
-, ! | negation and boolean 'not' | unary | 6 | right |
*, /, % | multiplication, division, and modulo | binary | 5 | left |
+, - | addition and subtraction | binary | 4 | left |
==, <, >, <=, >=, != | boolean equality, inequality, and comparison | binary | 3 | left |
&&, || | boolean 'and' and 'or' | binary | 2 | left |
, | argument delimiter | binary | 1 | left |
In the table above, operand implies the construct is an operand,
prefix implies the operation is applied to the following arguments,
unary implies there is one argument, and binary implies there are
two arguments. The values in the Precedence column show how the
order of different types of operation are determined. For example, the
expression a + b * c
is evaluated as a + (b * c)
because the @c * operator has higher precedence. The
Associates column shows how the order of similar precedence
operations is determined; for example, a && b || c
is
evaluated as (a && b) || c
because the &&
and ||
operators are left-associative and have the same precedence.
The function call syntax consists of a function name, followed by an opening parenthesis token, followed by a sequence of zero or more arguments separated by commas (with each comma optionally preceded and/or followed by zero or more white space characters), followed by a closing parenthesis token. The function name must be chosen from one of the pre-defined functions in SBML or a user-defined function in the model. The following table lists the names of certain common mathematical functions; this table corresponds to Table 6 in the SBML Level 1 Version 2 specification with additions based on the functions added in SBML Level 2 and Level 3:
Name | Argument(s) | Formula or meaning | Argument Constraints | Result constraints |
---|---|---|---|---|
abs |
x | Absolute value of x. | ||
acos , arccos |
x | Arccosine of x in radians. | –1.0 ≤ x ≤ 1.0 | 0 ≤ acos(x) ≤ π |
acosh , arccosh |
x | Hyperbolic arccosine of x in radians. | ||
acot , arccot |
x | Arccotangent of x in radians. | ||
acoth , arccoth |
x | Hyperbolic arccotangent of x in radians. | ||
acsc , arccsc |
x | Arccosecant of x in radians. | ||
acsch , arccsch |
x | Hyperbolic arccosecant of x in radians. | ||
asec , arcsec |
x | Arcsecant of x in radians. | ||
asech , arcsech |
x | Hyperbolic arcsecant of x in radians. | ||
asin , arcsin |
x | Arcsine of x in radians. | –1.0 ≤ x ≤ 1.0 | 0 ≤ asin(x) ≤ π |
atan , arctan |
x | Arctangent of x in radians. | 0 ≤ atan(x) ≤ π | |
atanh , arctanh |
x | Hyperbolic arctangent of x in radians. | ||
ceil , ceiling |
x | Smallest number not less than x whose value is an exact integer. | ||
cos |
x | Cosine of x | ||
cosh |
x | Hyperbolic cosine of x. | ||
cot |
x | Cotangent of x. | ||
coth |
x | Hyperbolic cotangent of x. | ||
csc |
x | Cosecant of x. | ||
csch |
x | Hyperbolic cosecant of x. | ||
delay |
x, y | The value of x at y time units in the past. | ||
factorial |
n | The factorial of n. Factorials are defined by n! = n*(n–1)* ... * 1. | n must be an integer. | |
exp |
x | e x, where e is the base of the natural logarithm. | ||
floor |
x | The largest number not greater than x whose value is an exact integer. | ||
ln |
x | Natural logarithm of x. | x > 0 | |
log |
x | By default, the base 10 logarithm of x, but can be set to be the natural logarithm of x, or to be an illegal construct. | x > 0 | |
log |
x, y | The base x logarithm of y. | y > 0 | |
log10 |
x | Base 10 logarithm of x. | x > 0 | |
piecewise |
x1, y1, [x2, y2,] [...] [z] | A piecewise function: if (y1), x1. Otherwise, if (y2), x2, etc. Otherwise, z. | y1, y2, y3 [etc] must be boolean | |
pow , power |
x, y | x y. | ||
root |
b, x | The root base b of x. | ||
sec |
x | Secant of x. | ||
sech |
x | Hyperbolic secant of x. | ||
sqr |
x | x2. | ||
sqrt |
x | √x. | x > 0 | sqrt(x) ≥ 0 |
sin |
x | Sine of x. | ||
sinh |
x | Hyperbolic sine of x. | ||
tan |
x | Tangent of x. | x ≠ n*π/2, for odd integer n | |
tanh |
x | Hyperbolic tangent of x. | ||
and |
x, y, z... | Boolean and(x, y, z...): returns true if all of its arguments are true. Note that and is an n-ary function, taking 0 or more arguments, and that and() returns true . |
All arguments must be boolean | |
not |
x | Boolean not(x) | x must be boolean | |
or |
x, y, z... | Boolean or(x, y, z...): returns true if at least one of its arguments is true. Note that or is an n-ary function, taking 0 or more arguments, and that or() returns false . |
All arguments must be boolean | |
xor |
x, y, z... | Boolean xor(x, y, z...): returns true if an odd number of its arguments is true. Note that xor is an n-ary function, taking 0 or more arguments, and that xor() returns false . |
All arguments must be boolean | |
eq |
x, y, z... | Boolean eq(x, y, z...): returns true if all arguments are equal. Note that eq is an n-ary function, but must take 2 or more arguments. |
||
geq |
x, y, z... | Boolean geq(x, y, z...): returns true if each argument is greater than or equal to the argument following it. Note that geq is an n-ary function, but must take 2 or more arguments. |
||
gt |
x, y, z... | Boolean gt(x, y, z...): returns true if each argument is greater than the argument following it. Note that gt is an n-ary function, but must take 2 or more arguments. |
||
leq |
x, y, z... | Boolean leq(x, y, z...): returns true if each argument is less than or equal to the argument following it. Note that leq is an n-ary function, but must take 2 or more arguments. |
||
lt |
x, y, z... | Boolean lt(x, y, z...): returns true if each argument is less than the argument following it. Note that lt is an n-ary function, but must take 2 or more arguments. |
||
neq |
x, y | Boolean x != y: returns true unless x and y are equal. |
||
plus |
x, y, z... | x + y + z + ...: The sum of the arguments of the function. Note that plus is an n-ary function taking 0 or more arguments, and that plus() returns 0 . |
||
times |
x, y, z... | x * y * z * ...: The product of the arguments of the function. Note that times is an n-ary function taking 0 or more arguments, and that times() returns 1 . |
||
minus |
x, y | x – y. | ||
divide |
x, y | x / y. |
Modifier and Type | Field | Description |
---|---|---|
Token |
jj_nt |
Next token.
|
static java.util.Properties |
stringToType |
|
Token |
token |
Current token.
|
FormulaParserLL3TokenManager |
token_source |
Generated Token Manager.
|
AND, BOOLEAN_LOGIC, CLOSE_PAR, COMPARISON, DEFAULT, DIGIT, DIVIDE, EOF, EOL, EXPNUMBER, IDCHAR, INTEGER, LEFT_BRACES, LEFT_BRACKET, LETTER, LOG, MINUS, MODULO, NOT, NUMBER, OPEN_PAR, OR, PLUS, POWER, RIGHT_BRACES, RIGHT_BRACKET, SPLITTER, STRING, TIMES, tokenImage, XOR
Constructor | Description |
---|---|
FormulaParserLL3(java.io.InputStream stream) |
Constructor with InputStream.
|
FormulaParserLL3(java.io.InputStream stream,
java.lang.String encoding) |
Constructor with InputStream and supplied encoding
|
FormulaParserLL3(java.io.Reader stream) |
Constructor.
|
FormulaParserLL3(FormulaParserLL3TokenManager tm) |
Constructor with generated Token Manager.
|
Modifier and Type | Method | Description |
---|---|---|
void |
disable_tracing() |
Disable tracing.
|
void |
enable_tracing() |
Enable tracing.
|
ParseException |
generateParseException() |
Generate ParseException.
|
Token |
getNextToken() |
Get the next Token.
|
Token |
getToken(int index) |
Get the specific Token.
|
ASTNode |
parse() |
|
void |
ReInit(java.io.InputStream stream) |
Reinitialise.
|
void |
ReInit(java.io.InputStream stream,
java.lang.String encoding) |
Reinitialise.
|
void |
ReInit(java.io.Reader stream) |
Reinitialise.
|
void |
ReInit(FormulaParserLL3TokenManager tm) |
Reinitialise.
|
void |
setCaseSensitive(boolean caseSensitive) |
Sets the case sensitivity of the parser, for the mathml elements.
|
Token |
string() |
public static java.util.Properties stringToType
public FormulaParserLL3TokenManager token_source
public Token token
public Token jj_nt
public FormulaParserLL3(java.io.InputStream stream)
public FormulaParserLL3(java.io.InputStream stream, java.lang.String encoding)
public FormulaParserLL3(java.io.Reader stream)
public FormulaParserLL3(FormulaParserLL3TokenManager tm)
public void setCaseSensitive(boolean caseSensitive)
The default behavior is to be case sensitive, meaning
'cos
' would be recognized as the mathematical cosinus but
'Cos
', 'cOs
' or any other alternatives would be recognized
as a name and read as a 'ci' element. If you pass false
to this method
all the different versions of cos
would be recognized as the mathematical
cosinus.
caseSensitive
- boolean to define if the parser should be case sensitive or not.public final Token string() throws ParseException
ParseException
public final ASTNode parse() throws ParseException
parse
in interface IFormulaParser
ParseException
public void ReInit(java.io.InputStream stream)
ReInit
in interface IFormulaParser
public void ReInit(java.io.InputStream stream, java.lang.String encoding)
ReInit
in interface IFormulaParser
public void ReInit(java.io.Reader stream)
ReInit
in interface IFormulaParser
public void ReInit(FormulaParserLL3TokenManager tm)
public final Token getNextToken()
public final Token getToken(int index)
public ParseException generateParseException()
public final void enable_tracing()
public final void disable_tracing()