ANF.g4 (1003B)
1 grammar ANF; 2 3 prog: def+; 4 5 def: 'def' IDENT '('(IDENT (',' IDENT)*)? ')' ':' cexp; 6 7 aexp 8 : 'true' #true 9 | 'false' # false 10 | IDENT #var 11 | NUMBER #num 12 | STRING #str 13 | '(' aexp '+' aexp ')' #add 14 | '(' aexp '-' aexp ')' #sub 15 | '(' aexp '*' aexp ')' #mul 16 | '(' aexp '/' aexp ')' #div 17 | '(' aexp '>' aexp ')' #gt 18 | '(' aexp '<' aexp ')' #lt 19 | '(' aexp '==' aexp ')' #eq 20 | '(' aexp '<<' aexp ')' #bsl 21 | '(' aexp '>>' aexp ')' #bsr 22 | '(' aexp '&&' aexp ')' #and 23 | '(' aexp '||' aexp ')' #or 24 | '(' aexp '^^' aexp ')' #xor 25 | '(' IDENT (',' IDENT)* ':' cexp ')' #lam 26 ; 27 28 funcall 29 : IDENT '(' aexp (',' aexp)* ')' #call 30 | aexp #atom 31 ; 32 cexp 33 : 'let' IDENT '=' funcall 'in' cexp #let 34 | 'if' aexp 'then' cexp 'else' cexp #if 35 | funcall #fc 36 ; 37 38 39 IDENT: Letter (Letter | Digit)*; 40 NUMBER: Digit+; 41 STRING: '"' ([^"]|'\\'.)* '"'; 42 43 fragment Letter: 'A' .. 'Z' | 'a' .. 'z'; 44 fragment Digit: '0'..'9'; 45 46 WS: [ \t\n\r]+ -> skip;