CAP/TP02/demo_files/ex2/Example2.g4

18 lines
320 B
Plaintext
Raw Normal View History

2024-09-23 11:04:28 +02:00
//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