-
Notifications
You must be signed in to change notification settings - Fork 5
/
abt.grm
125 lines (105 loc) · 4.09 KB
/
abt.grm
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
open AbbotSyntax
open Util
%%
%term EOF | SORT | ABT | EQUAL | BAR | LPAREN | RPAREN | COMMA | SYMBOL | DOT | STAR | TICK | OF | BINDING
| Name of string
%nonterm start
of string list StringTable.table
* StringTable.Set.set
* (string list * AbbotSyntax.oper list) StringTable.table
* AbbotSyntax.oper list StringTable.table
| decls
of string list StringTable.table
* StringTable.Set.set
* (string list * AbbotSyntax.oper list) StringTable.table
* AbbotSyntax.oper list StringTable.table
| decl of (string * string list,
string,
string * (string list * AbbotSyntax.oper list),
string * AbbotSyntax.oper list)
Util.Sum4.t
| symbol_decl of string
| abt_decl of string * (string list * AbbotSyntax.oper list option)
| abt_arg of string list
| abt_args of string list
| sort_decl of string * AbbotSyntax.oper list
| cases of AbbotSyntax.oper list
| oper of AbbotSyntax.oper
| arity of AbbotSyntax.arity
| simple_arity of AbbotSyntax.arity
| aritys of AbbotSyntax.arity list
| prod_arity of AbbotSyntax.arity list
%nonassoc COMMA
%nonassoc STAR
%right DOT
%left Name
%verbose
%pos int
%start start
%eop EOF
%noshift EOF
%name Abt
%%
start: decls (decls)
decls: (* empty *) ((StringTable.empty (), StringTable.Set.empty (), StringTable.empty (), StringTable.empty ()))
| decl decls (let
val (exts, symbs, abts, sorts) = decls
in
case decl of
Sum4.In1 ext =>
(StringTable.insert
(fn _ => raise Fail "Duplicate abt defined.")
ext exts,
symbs,
abts,
sorts)
| Sum4.In2 symb =>
(exts, StringTable.Set.insert symb symbs, abts, sorts)
| Sum4.In3 abt =>
(exts,
symbs,
StringTable.insert
(fn _ => raise Fail "Duplicate abt defined.")
abt abts,
sorts)
| Sum4.In4 sort =>
(exts,
symbs,
abts,
StringTable.insert
(fn _ => raise Fail "Duplicate sort defined.")
sort sorts)
end)
decl: symbol_decl (Sum4.In2 symbol_decl)
| abt_decl (case abt_decl of
(abt, (args, NONE)) => Sum4.In1 (abt, args)
| (abt, (args, SOME opers)) => Sum4.In3 (abt, (args, opers)))
| sort_decl (Sum4.In4 sort_decl)
symbol_decl: SYMBOL Name (Name)
abt_decl: ABT abt_arg Name ((Name, (abt_arg, NONE)))
| ABT abt_arg Name EQUAL cases ((Name, (abt_arg, SOME cases)))
| ABT abt_arg Name EQUAL BAR cases ((Name, (abt_arg, SOME cases)))
abt_arg: (* empty *) ([])
| TICK Name ([Name])
| LPAREN abt_args RPAREN (abt_args)
abt_args: TICK Name ([Name])
| TICK Name COMMA abt_args (Name :: abt_args)
sort_decl: SORT Name EQUAL cases ((Name, cases))
| SORT Name EQUAL BAR cases ((Name, cases))
cases: oper ([oper])
| oper BAR cases (oper :: cases)
oper: Name ((Name, NONE))
| Name OF arity ((Name, SOME arity))
arity: simple_arity (simple_arity)
| prod_arity (Prod prod_arity)
| arity DOT arity (Dot (arity1, arity2))
simple_arity: Name (Use Name)
| TICK Name (Param Name)
| Name BINDING (Binding Name)
| simple_arity Name (App (Name, [simple_arity]))
| LPAREN aritys RPAREN Name (App (Name, aritys))
| LPAREN arity RPAREN (arity)
aritys: arity COMMA arity ([arity1, arity2])
| arity COMMA aritys (arity :: aritys)
prod_arity: simple_arity STAR simple_arity ([simple_arity1, simple_arity2])
| simple_arity STAR prod_arity (simple_arity :: prod_arity)