-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.mly
More file actions
executable file
·50 lines (39 loc) · 1.03 KB
/
Copy pathparser.mly
File metadata and controls
executable file
·50 lines (39 loc) · 1.03 KB
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
%{
(* parser.mly*)
open Syntax
open Localizing
(*
let lift_array t l = List.fold_left (fun t' () -> Array_type t') t l
*)
%}
%token <bool*Localizing.extent> BOOLEAN_LITERAL
%token <string*Localizing.extent> IDENTIFIER INT
%token <Localizing.extent> LET REC IN FUN ARROW TRUE FALSE LEFT RIGHT IF THEN ELSE
%token <unit*Localizing.extent> ANDAND OROR PLUS MINUS MULT EQ
%token EOF
%start exp
%type <Syntax.exp> exp
%type <Syntax.oper> operation
%type <Syntax.cste> constant
%%
exp:
| IDENTIFIER {Inst(fst $1)}
| constant {Cste($1)}
| exp operation exp {Oper($2,$1,$3)}
| exp exp {Appl($1,$2)}
| IF exp THEN exp ELSE exp {Cond($2,$4,$6)}
| FUN IDENTIFIER ARROW exp {Fun((fst $2),$4)}
| LET REC IDENTIFIER IDENTIFIER EQ exp IN exp {Letrec((fst $3),(fst $4),$6,$8)}
| LET IDENTIFIER EQ exp IN exp {Let((fst $2),$4,$6)}
| LEFT exp RIGHT {$2}
operation:
| ANDAND {And}
| OROR {Or}
| PLUS {Plus}
| MINUS {Minus}
| MULT {Times}
| EQ {Equals}
constant:
| TRUE {True}
| FALSE {False}
| INT {Int(int_of_string(fst $1))}