This is a formerly online demonstration page of the STX Expression Parser framework. Due to changes to the website in 2012, the online demo has been taked offline. However, some static results have been retained for your information.
The input strings given below were parsed and evaluated by the library. Upon successful processing the evaluation result's type and value are displayed together with the expression's parse tree.
The results from the following examples are availabled below:
6 + 3 * 12
(5 + 3) * 5.25
(int)(30 * 1.4)
(5 + 1 + 1 + 1) * (4.25 + 0.4 * 2.5 / (3.1 - 0.525 * 4))
COS(2 * PI)
SQRT( COS(PI/4) * COS(PI/4) + SIN(PI/4) * SIN(PI/4) )
a == 6 * 9
a * 20000 <= c
e == EXP(1)
golden == (1 + SQRT(5)) / 2
(a - 28) * (int)(e + 0.4 * 2.5 / (PI() - EXP(-0.644) * 4))
a >= 5 OR (42 <= field2 AND field2 <= 48) || NOT(got == "yes")
The following variables are defined in the demo and used in the expressions:
a | 42 |
c | 299792458 |
e | 2.718281828459045 |
pi | 3.141592653589793 |
golden | 1.618033988749895 |
field1 | 12345678 |
field2 | 87654321 |
got | "no" |
6 + 3 * 12
Evaluated String 6 + 3 * 12 |
ParseTree Result as String 42 |
Evaluation Result (using the Variables Table) 42 (type: integer) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- 6 + 3 * 12 --> <parsetree version="1.0"> <parsenode rule="add_expr"> <value>+</value> <parsenode rule="integer_const"> <value>6</value> </parsenode> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="integer_const"> <value>3</value> </parsenode> <parsenode rule="integer_const"> <value>12</value> </parsenode> </parsenode> </parsenode> </parsetree> |
(5 + 3) * 5.25
Evaluated String (5 + 3) * 5.25 |
ParseTree Result as String 42 |
Evaluation Result (using the Variables Table) 42 (type: double) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- (5 + 3) * 5.25 --> <parsetree version="1.0"> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="add_expr"> <value>+</value> <parsenode rule="integer_const"> <value>5</value> </parsenode> <parsenode rule="integer_const"> <value>3</value> </parsenode> </parsenode> <parsenode rule="double_const"> <value>5.25</value> </parsenode> </parsenode> </parsetree> |
(int)(30 * 1.4)
Evaluated String (int)(30 * 1.4) |
ParseTree Result as String 42 |
Evaluation Result (using the Variables Table) 42 (type: integer) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- (int)(30 * 1.4) --> <parsetree version="1.0"> <parsenode rule="cast_spec"> <value>int</value> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="integer_const"> <value>30</value> </parsenode> <parsenode rule="double_const"> <value>1.4</value> </parsenode> </parsenode> </parsenode> </parsetree> |
(5 + 1 + 1 + 1) * (4.25 + 0.4 * 2.5 / (3.1 - 0.525 * 4))
Evaluated String (5 + 1 + 1 + 1) * (4.25 + 0.4 * 2.5 / (3.1 - 0.525 * 4)) |
ParseTree Result as String 42 |
Evaluation Result (using the Variables Table) 42 (type: double) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- (5 + 1 + 1 + 1) * (4.25 + 0.4 * 2.5 / (3.1 - 0.525 * 4)) --> <parsetree version="1.0"> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="add_expr"> <value>+</value> <parsenode rule="add_expr"> <value is_root="1">+</value> <parsenode rule="add_expr"> <value is_root="1">+</value> <parsenode rule="integer_const"> <value>5</value> </parsenode> <parsenode rule="integer_const"> <value>1</value> </parsenode> </parsenode> <parsenode rule="integer_const"> <value>1</value> </parsenode> </parsenode> <parsenode rule="integer_const"> <value>1</value> </parsenode> </parsenode> <parsenode rule="add_expr"> <value>+</value> <parsenode rule="double_const"> <value>4.25</value> </parsenode> <parsenode rule="mul_expr"> <value>/</value> <parsenode rule="mul_expr"> <value is_root="1">*</value> <parsenode rule="double_const"> <value>0.4</value> </parsenode> <parsenode rule="double_const"> <value>2.5</value> </parsenode> </parsenode> <parsenode rule="add_expr"> <value>-</value> <parsenode rule="double_const"> <value>3.1</value> </parsenode> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="double_const"> <value>0.525</value> </parsenode> <parsenode rule="integer_const"> <value>4</value> </parsenode> </parsenode> </parsenode> </parsenode> </parsenode> </parsenode> </parsetree> |
COS(2 * PI)
Evaluated String COS(2 * PI) |
ParseTree Result as String COS((2 * PI)) |
Evaluation Result (using the Variables Table) 1 (type: double) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- COS(2 * PI) --> <parsetree version="1.0"> <parsenode rule="function_identifier"> <value>COS</value> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="integer_const"> <value>2</value> </parsenode> <parsenode rule="varname"> <value>PI</value> </parsenode> </parsenode> </parsenode> </parsetree> |
SQRT( COS(PI/4) * COS(PI/4) + SIN(PI/4) * SIN(PI/4) )
Evaluated String SQRT( COS(PI/4) * COS(PI/4) + SIN(PI/4) * SIN(PI/4) ) |
ParseTree Result as String SQRT(((COS((PI / 4)) * COS((PI / 4))) + (SIN((PI / 4)) * SIN((PI / 4))))) |
Evaluation Result (using the Variables Table) 1 (type: double) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- SQRT( COS(PI/4) * COS(PI/4) + SIN(PI/4) * SIN(PI/4) ) --> <parsetree version="1.0"> <parsenode rule="function_identifier"> <value>SQRT</value> <parsenode rule="add_expr"> <value>+</value> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="function_identifier"> <value>COS</value> <parsenode rule="mul_expr"> <value>/</value> <parsenode rule="varname"> <value>PI</value> </parsenode> <parsenode rule="integer_const"> <value>4</value> </parsenode> </parsenode> </parsenode> <parsenode rule="function_identifier"> <value>COS</value> <parsenode rule="mul_expr"> <value>/</value> <parsenode rule="varname"> <value>PI</value> </parsenode> <parsenode rule="integer_const"> <value>4</value> </parsenode> </parsenode> </parsenode> </parsenode> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="function_identifier"> <value>SIN</value> <parsenode rule="mul_expr"> <value>/</value> <parsenode rule="varname"> <value>PI</value> </parsenode> <parsenode rule="integer_const"> <value>4</value> </parsenode> </parsenode> </parsenode> <parsenode rule="function_identifier"> <value>SIN</value> <parsenode rule="mul_expr"> <value>/</value> <parsenode rule="varname"> <value>PI</value> </parsenode> <parsenode rule="integer_const"> <value>4</value> </parsenode> </parsenode> </parsenode> </parsenode> </parsenode> </parsenode> </parsetree> |
a == 6 * 9
Evaluated String a == 6 * 9 |
ParseTree Result as String (a == 54) |
Evaluation Result (using the Variables Table) false (type: bool) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- a == 6 * 9 --> <parsetree version="1.0"> <parsenode rule="comp_expr"> <value>==</value> <parsenode rule="varname"> <value>a</value> </parsenode> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="integer_const"> <value>6</value> </parsenode> <parsenode rule="integer_const"> <value>9</value> </parsenode> </parsenode> </parsenode> </parsetree> |
a * 20000 <= c
Evaluated String a * 20000 <= c |
ParseTree Result as String ((a * 20000) <= c) |
Evaluation Result (using the Variables Table) true (type: bool) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- a * 20000 <= c --> <parsetree version="1.0"> <parsenode rule="comp_expr"> <value><=</value> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="varname"> <value>a</value> </parsenode> <parsenode rule="integer_const"> <value>20000</value> </parsenode> </parsenode> <parsenode rule="varname"> <value>c</value> </parsenode> </parsenode> </parsetree> |
e == EXP(1)
Evaluated String e == EXP(1) |
ParseTree Result as String (e == EXP(1)) |
Evaluation Result (using the Variables Table) true (type: bool) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- e == EXP(1) --> <parsetree version="1.0"> <parsenode rule="comp_expr"> <value>==</value> <parsenode rule="varname"> <value>e</value> </parsenode> <parsenode rule="function_identifier"> <value>EXP</value> <parsenode rule="integer_const"> <value>1</value> </parsenode> </parsenode> </parsenode> </parsetree> |
golden == (1 + SQRT(5)) / 2
Evaluated String golden == (1 + SQRT(5)) / 2 |
ParseTree Result as String (golden == ((1 + SQRT(5)) / 2)) |
Evaluation Result (using the Variables Table) true (type: bool) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- golden == (1 + SQRT(5)) / 2 --> <parsetree version="1.0"> <parsenode rule="comp_expr"> <value>==</value> <parsenode rule="varname"> <value>golden</value> </parsenode> <parsenode rule="mul_expr"> <value>/</value> <parsenode rule="add_expr"> <value>+</value> <parsenode rule="integer_const"> <value>1</value> </parsenode> <parsenode rule="function_identifier"> <value>SQRT</value> <parsenode rule="integer_const"> <value>5</value> </parsenode> </parsenode> </parsenode> <parsenode rule="integer_const"> <value>2</value> </parsenode> </parsenode> </parsenode> </parsetree> |
(a - 28) * (int)(e + 0.4 * 2.5 / (PI() - EXP(-0.644) * 4))
Evaluated String (a - 28) * (int)(e + 0.4 * 2.5 / (PI() - EXP(-0.644) * 4)) |
ParseTree Result as String ((a - 28) * ((integer)(e + (1 / (PI() - (EXP(-0.64400000000000002) * 4)))))) |
Evaluation Result (using the Variables Table) 42 (type: integer) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- (a - 28) * (int)(e + 0.4 * 2.5 / (PI() - EXP(-0.644) * 4)) --> <parsetree version="1.0"> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="add_expr"> <value>-</value> <parsenode rule="varname"> <value>a</value> </parsenode> <parsenode rule="integer_const"> <value>28</value> </parsenode> </parsenode> <parsenode rule="cast_spec"> <value>int</value> <parsenode rule="add_expr"> <value>+</value> <parsenode rule="varname"> <value>e</value> </parsenode> <parsenode rule="mul_expr"> <value>/</value> <parsenode rule="mul_expr"> <value is_root="1">*</value> <parsenode rule="double_const"> <value>0.4</value> </parsenode> <parsenode rule="double_const"> <value>2.5</value> </parsenode> </parsenode> <parsenode rule="add_expr"> <value>-</value> <parsenode rule="function_identifier"> <value>PI</value> </parsenode> <parsenode rule="mul_expr"> <value>*</value> <parsenode rule="function_identifier"> <value>EXP</value> <parsenode rule="unary_expr"> <value>-</value> <parsenode rule="double_const"> <value>0.644</value> </parsenode> </parsenode> </parsenode> <parsenode rule="integer_const"> <value>4</value> </parsenode> </parsenode> </parsenode> </parsenode> </parsenode> </parsenode> </parsenode> </parsetree> |
a >= 5 OR (42 <= field2 AND field2 <= 48) || NOT(got == "yes")
Evaluated String a >= 5 OR (42 <= field2 AND field2 <= 48) || NOT(got == "yes") |
ParseTree Result as String (((a >= 5) || ((42 <= field2) && (field2 <= 48))) || (! (got == "yes"))) |
Evaluation Result (using the Variables Table) true (type: bool) |
XML Node Tree<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE parsetree SYSTEM "parsetree.dtd"> <!-- a >= 5 OR (42 <= field2 AND field2 <= 48) || NOT(got == "yes") --> <parsetree version="1.0"> <parsenode rule="or_expr"> <value>||</value> <parsenode rule="or_expr"> <value is_root="1">OR</value> <parsenode rule="comp_expr"> <value>>=</value> <parsenode rule="varname"> <value>a</value> </parsenode> <parsenode rule="integer_const"> <value>5</value> </parsenode> </parsenode> <parsenode rule="and_expr"> <value>AND</value> <parsenode rule="comp_expr"> <value><=</value> <parsenode rule="integer_const"> <value>42</value> </parsenode> <parsenode rule="varname"> <value>field2</value> </parsenode> </parsenode> <parsenode rule="comp_expr"> <value><=</value> <parsenode rule="varname"> <value>field2</value> </parsenode> <parsenode rule="integer_const"> <value>48</value> </parsenode> </parsenode> </parsenode> </parsenode> <parsenode rule="unary_expr"> <value>NOT</value> <parsenode rule="comp_expr"> <value>==</value> <parsenode rule="varname"> <value>got</value> </parsenode> <parsenode rule="string_const"> <value>"yes"</value> </parsenode> </parsenode> </parsenode> </parsenode> </parsetree> |