CAP/TP02/demo_files/ex2/Example2.g4
Emma Nardino ff5f2319ec Add TPO2
2024-09-23 11:04:28 +02:00

18 lines
320 B
ANTLR

//define a tiny grammar for arith expressions with identifiers
grammar Example2;
full_expr: expr ';' EOF ;
expr: expr OP expr
| ID {print('oh an id : '+$ID.text)}
| INT
;
OP : '+'| '*' | '-' | '/' ;
INT : '0'..'9'+ ;
ID : ('a'..'z'|'A'..'Z')+ ;
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines