-
Notifications
You must be signed in to change notification settings - Fork 0
/
miniml_parse.mly
54 lines (47 loc) · 1.38 KB
/
miniml_parse.mly
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
%{
open Expr ;;
%}
%token EOF
%token OPEN CLOSE
%token LET DOT IN REC
%token NEG
%token PLUS MINUS
%token TIMES
%token LESSTHAN EQUALS
%token IF THEN ELSE
%token FUNCTION
%token RAISE
%token <string> ID
%token <string> STRING
%token <int> INT
%token TRUE FALSE
%nonassoc IF
%left LESSTHAN EQUALS
%left PLUS MINUS
%left TIMES
%nonassoc NEG
%start input
%type <Expr.expr> input
%%
input: exp EOF { $1 }
exp: exp expnoapp { App($1, $2) }
| expnoapp { $1 }
expnoapp: INT { Num $1 }
| TRUE { Bool true }
| FALSE { Bool false }
| ID { Var $1 }
| STRING { String $1 }
| exp PLUS exp { Binop(Plus, $1, $3) }
| exp MINUS exp { Binop(Minus, $1, $3) }
| exp TIMES exp { Binop(Times, $1, $3) }
| exp EQUALS exp { Binop(Equals, $1, $3) }
| exp LESSTHAN exp { Binop(LessThan, $1, $3) }
| NEG exp { Unop(Negate, $2) }
| IF exp THEN exp ELSE exp { Conditional($2, $4, $6) }
| LET ID EQUALS exp IN exp { Let($2, $4, $6) }
| LET REC ID EQUALS exp IN exp { Letrec($3, $5, $7) }
| FUNCTION ID DOT exp { Fun($2, $4) }
| RAISE { Raise }
| OPEN exp CLOSE { $2 }
;
%%