Expr ::= Conditional
Conditional ::= LogicalOr ( '?' LogicalOr ':' LogicalOr ) ?
LogicalOr ::= LogicalAnd ( '||' LogicalAnd ) *
LogicalAnd ::= Equality ( '&&' Equality ) *
Equality ::= Compare ( ( '==' | '!=' ) Compare ) *
Compare ::= Sum ( ( '>=' | '>' | '<=' | '<' ) Sum ) *
Sum ::= Product ( ( '+' | '-' ) Product ) *
Product ::= Power ( ( '*' | '/' ) Power ) *
Power ::= Primary ( '^' Primary ) *
Primary ::= Number
| Function
| Constant
| '(' Expr ')'
| ( '-' | '!' ) Primary
Number ::= ( '-' ) ? ( ( [0-9]+ '.' [0-9]+ ) | [0-9]+ )
Function ::= [a-z]+ ( '(' ')' | '(' Expr ( ',' Expr ) * ')' )
Constant ::= [a-z]+
Discussed in #2084
Originally posted by stephenquan August 1, 2024
This is a Math Expression Converters #71 refactor enhancement to improve the parser by (1) using a Parsing expression grammar, and (2) to support boolean operations. The grammar is now:
Where
Conditional,LogicalOr,LogicalAnd,Equality, andCompareare new.trueandfalseboolean constants are also new.Sum,Product,Power,Primary,Number,Function, andConstantare a refactor of what was already supported by the original parser.The implementation can be found:
References: