-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.mly
98 lines (80 loc) · 2.13 KB
/
parser.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
%{
open Error
open Ktype
%}
/* keywords */
%token <Error.info> TYPE
/* symbolic tokens */
%token <Error.info> COL
%token <Error.info> SCOL
%token <Error.info> LBRA
%token <Error.info> RBRA
%token <Error.info> LPAR
%token <Error.info> RPAR
%token <Error.info> LBR
%token <Error.info> RBR
%token <Error.info> COM
%token <Error.info> DOT
%token <Error.info> EQ
%token <Error.info> ABS
%token <Error.info> PRE
%token <Error.info> PERCENT
%token <Error.info> ARROW
%token <Error.info> BARROW
%token <Error.info> EOF
/* identifiers and constant values */
%token <string Error.withinfo> VAR
%token <string Error.withinfo> NAME
%token <string Error.withinfo> UNAME
%start main
%type <Ktype.t> ktype
%type <string Error.withinfo> name
%type <Ktype.constraints> main
%%
main:
types constraints EOF { { compdecl = $1.v ; consts = $2.v } }
;
ktype:
name { TBase $1.v }
| LBR row BARROW row RBR { TRecord ($2,$4) }
| LBR row RBR { TRecord ( TAbsR, $2 ) }
| VAR { TVr $1.v }
;
row:
ABS { TAbsR }
| VAR { TVr $1.v }
| name COL field SCOL row { TRow ($1.v, $3, $5) }
;
field:
ABS { TAbsF }
| PRE LPAR ktype RPAR { TPres $3 }
| NAME { TBase $1.v }
| LBR row BARROW row RBR { TRecord ($2, $4) }
| VAR { TVr $1.v }
;
listassoc:
{ [] }
| name COL ktype { ($1.v, $3) :: [] }
| name COL ktype SCOL listassoc
{ ($1.v, $3) :: $5 }
;
comptype:
LBR listassoc RBR ARROW LBR listassoc RBR
{ {input = $2 ; output = $6 } }
;
types:
{ { i = dummyinfo ; v = [] } }
| name COL comptype types { { i = $1.i ; v = ($1.v, $3) :: $4.v } }
;
constraints:
{ { i = dummyinfo ; v = [] } }
| PERCENT consts { $2 }
;
consts:
{ { i = dummyinfo ; v = [] } }
| name DOT name EQ name DOT name consts
{ { i = $1.i ; v = ($1.v, $3.v, $5.v, $7.v) :: $8.v } }
name:
NAME { $1 }
| UNAME { $1 }
;