grammar simpleCalc; options { output = AST; } tokens { PLUS = '+' ; MINUS = '-' ; MULT = '*' ; DIV = '/' ; LPAREN = '('; RPAREN = ')'; EQUAL = '='; } @parser::header { package net.certiv.x.outputs; } @lexer::header { package net.certiv.x.outputs; } assign : lvalue EQUAL^ expr EOF; lvalue : IDENT ; expr : term ( ( PLUS^ | MINUS^ ) term )* ; term : operand ( ( MULT^ | DIV^ ) operand )* ; operands : operand+ ; operand : ident | digits | LPAREN! expr RPAREN! ; ident : i=IDENT { System.out.println("IDENT: " + $i.toString()); }; digits : DIGITS ; IDENT : LETTER (LETTER | DIGIT)* ; DIGITS : a+=DIGIT+ { System.out.println("DIGITS: " + $a.toString()); } ; WS : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ; fragment LETTER : UPPER | LOWER ; fragment DIGIT : '0'..'9'; fragment LOWER : 'a'..'z'; fragment UPPER : 'A'..'Z';