Skip to content

Instantly share code, notes, and snippets.

@shmatov
Last active December 25, 2015 16:59
Show Gist options
  • Save shmatov/7010232 to your computer and use it in GitHub Desktop.
Save shmatov/7010232 to your computer and use it in GitHub Desktop.
grammar MathExpression;
INT : [0-9]+;
DOUBLE : [0-9]+'.'[0-9]+;
PI : 'pi';
E : 'e';
POW : '^';
WS : [ \t\r\n]+ -> skip;
ID : [a-zA-Z_][a-zA-Z_0-9]*;
PLUS : '+';
MINUS : '-';
MULT : '*';
DIV : '/';
LPAR : '(';
RPAR : ')';
input
: expr EOF
;
expr
: term ((PLUS | MINUS) term)*
;
term
: factor ((MULT | DIV) factor)*
;
factor
: pow (POW factor)?
;
pow
: MINUS pow
| atom
;
atom
: PI
| E
| DOUBLE
| INT
| LPAR expr RPAR
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment