aboutsummaryrefslogtreecommitdiff
path: root/runtime/Perl5/examples/simplecalc/SimpleCalc.g
blob: a819e416dfb47510f6f5a55431944f233381af51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
grammar SimpleCalc;
options { language = Perl5; }

tokens {
    PLUS  = '+' ;
    MINUS = '-' ;
    MULT  = '*' ;
    DIV   = '/' ;
}

/*------------------------------------------------------------------
 * PARSER RULES
 *------------------------------------------------------------------*/

expr    : term ( ( PLUS | MINUS )  term )* ;

term    : factor ( ( MULT | DIV ) factor )* ;

factor  : NUMBER ;

/*------------------------------------------------------------------
 * LEXER RULES
 *------------------------------------------------------------------*/

NUMBER : (DIGIT)+ ;

WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = $self->HIDDEN; } ;

fragment DIGIT : '0'..'9' ;