22 lines
491 B
ANTLR
22 lines
491 B
ANTLR
// A small expression grammar in one combined file.
|
|
// antlrlab examples/combined/Expr.g4 examples/combined/input.txt
|
|
grammar Expr;
|
|
|
|
prog : expr EOF ;
|
|
|
|
expr
|
|
: expr op=(MUL | DIV) expr # MulDiv
|
|
| expr op=(ADD | SUB) expr # AddSub
|
|
| INT # Int
|
|
| ID # Id
|
|
| '(' expr ')' # Parens
|
|
;
|
|
|
|
MUL : '*' ;
|
|
DIV : '/' ;
|
|
ADD : '+' ;
|
|
SUB : '-' ;
|
|
INT : [0-9]+ ;
|
|
ID : [a-zA-Z_] [a-zA-Z_0-9]* ;
|
|
WS : [ \t\r\n]+ -> skip ;
|