2020-07-20 16:40:03 +03:00
|
|
|
grammar ArithmeticsEvaluator;
|
|
|
|
|
|
|
|
fragment DIGIT: '0'..'9';
|
|
|
|
fragment LETTER: 'a'..'z';
|
2020-07-27 11:45:05 +03:00
|
|
|
fragment CAPITAL_LETTER: 'A'..'Z';
|
2020-07-20 16:40:03 +03:00
|
|
|
fragment UNDERSCORE: '_';
|
|
|
|
|
2020-07-27 11:37:18 +03:00
|
|
|
ID: (LETTER | UNDERSCORE | CAPITAL_LETTER) (LETTER | UNDERSCORE | DIGIT | CAPITAL_LETTER)*;
|
2020-07-27 11:58:09 +03:00
|
|
|
NUM: (DIGIT | '.')+ ([eE] [-+]? DIGIT+)?;
|
2020-07-20 16:40:03 +03:00
|
|
|
MUL: '*';
|
|
|
|
DIV: '/';
|
|
|
|
PLUS: '+';
|
|
|
|
MINUS: '-';
|
|
|
|
POW: '^';
|
|
|
|
COMMA: ',';
|
|
|
|
LPAR: '(';
|
|
|
|
RPAR: ')';
|
|
|
|
WS: [ \n\t\r]+ -> skip;
|
|
|
|
|
2020-07-27 11:45:05 +03:00
|
|
|
num
|
2020-07-20 16:40:03 +03:00
|
|
|
: NUM
|
|
|
|
;
|
|
|
|
|
|
|
|
singular
|
|
|
|
: ID
|
|
|
|
;
|
|
|
|
|
|
|
|
unaryFunction
|
|
|
|
: ID LPAR subSumChain RPAR
|
|
|
|
;
|
|
|
|
|
|
|
|
binaryFunction
|
|
|
|
: ID LPAR subSumChain COMMA subSumChain RPAR
|
|
|
|
;
|
|
|
|
|
|
|
|
term
|
2020-07-27 11:45:05 +03:00
|
|
|
: num
|
2020-07-20 16:40:03 +03:00
|
|
|
| singular
|
|
|
|
| unaryFunction
|
|
|
|
| binaryFunction
|
|
|
|
| MINUS term
|
|
|
|
| LPAR subSumChain RPAR
|
|
|
|
;
|
|
|
|
|
|
|
|
powChain
|
|
|
|
: term (POW term)*
|
|
|
|
;
|
|
|
|
|
|
|
|
divMulChain
|
2020-07-27 11:49:36 +03:00
|
|
|
: powChain ((DIV | MUL) powChain)*
|
2020-07-20 16:40:03 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
subSumChain
|
2020-07-27 11:49:36 +03:00
|
|
|
: divMulChain ((PLUS | MINUS) divMulChain)*
|
2020-07-20 16:40:03 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
rootParser
|
|
|
|
: subSumChain EOF
|
|
|
|
;
|