1grammar SimpleCalc;
2options { language = Perl5; }
3
4tokens {
5    PLUS  = '+' ;
6    MINUS = '-' ;
7    MULT  = '*' ;
8    DIV   = '/' ;
9}
10
11/*------------------------------------------------------------------
12 * PARSER RULES
13 *------------------------------------------------------------------*/
14
15expr    : term ( ( PLUS | MINUS )  term )* ;
16
17term    : factor ( ( MULT | DIV ) factor )* ;
18
19factor  : NUMBER ;
20
21/*------------------------------------------------------------------
22 * LEXER RULES
23 *------------------------------------------------------------------*/
24
25NUMBER : (DIGIT)+ ;
26
27WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = $self->HIDDEN; } ;
28
29fragment DIGIT : '0'..'9' ;
30