summary refs log tree commit diff
path: root/grammar/ANF.g4
blob: 07e199e9865298a4db6d0c08df056ea2e3ff00fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
grammar ANF;

aexp
    : 'true' #true
    | 'false' # false
    | IDENT #var
    | NUMBER #num
    | '(' aexp '+' aexp ')' #add
    | '(' aexp '-' aexp ')' #sub
    | '(' aexp '*' aexp ')' #mul
    | '(' aexp '/' aexp ')' #div
    | '(' aexp '>' aexp ')' #gt
    | '(' aexp '<' aexp ')' #lt
    | '(' aexp '==' aexp ')' #eq
    | '(' aexp '<<' aexp ')' #bsl
    | '(' aexp '>>' aexp ')' #bsr
    | '(' aexp '&&' aexp ')' #and
    | '(' aexp '||' aexp ')' #or
    | '(' aexp '^^' aexp ')' #xor
    | '(' IDENT ':' cexp ')' #lam
    ;

funcall
    : IDENT '(' aexp (',' aexp)* ')' #call
    | aexp #atom
    ;
cexp
    : 'let' IDENT '=' funcall 'in' cexp #let
    | 'if' aexp 'then' cexp 'else' cexp #if
    | funcall #fc
    ;

IDENT: Letter (Letter | Digit)*;
NUMBER: Digit+;

fragment Letter: 'A' .. 'Z' | 'a' .. 'z';
fragment Digit: '0'..'9';

WS: [ \t\n\r]+ -> skip;