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