forked from CakeML/cakeml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.txt
More file actions
165 lines (120 loc) · 3.7 KB
/
grammar.txt
File metadata and controls
165 lines (120 loc) · 3.7 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
V ::= "op" ID | ID
InfixOp ::= "*" | "+" | "-" | "/" | "::" | ":=" | "<" | "<="
| "<>" | "=" | ">" | ">=" | "@" | "before" | "div"
| "mod" | "o"
// some of these are boolean (Opb), some numeric (Opn)
Error ::= "Bind" // Bind_error
| "Div" // Div_error
LogicalOp ::= "andalso" // And
| "orelse" // Or
Literal ::= IntegerLiteral // IntLit i
| "true" // Bool T
| "false" // Bool F
| "()" // Unit
| StringLiteral // String s
(* See http://www.mlton.org/OperatorPrecedence *)
Ebase ::=
"(" E ")"
| V
| Literal
| "let" LetDecs "in" Eseq "end"
Eseq ::= E | E ";" Eseq
Eapp ::=
Eapp Ebase | Ebase | ConstructorName Etuple
Etuple ::= "(" Elist2 ")"
Elist2 ::= Elist1 "," E
Elist1 ::= E | Elist1 "," E
(* level 7 *)
Emult ::=
Emult MultOp Ebase | Ebase
(* level 6 *)
Eadd ::=
Eadd AddOp Emult | Emult
(* level 5 - note, right associative *)
Econs ::=
Eadd ConsOp Econs | Eadd
(* level 4 *)
Erel ::=
Erel RelOp Econs | Econs
(* level 3 *)
Ecomp ::=
Ecomp CompOp Erel | Erel
(* level 0 *)
Ebefore ::=
Ebefore BeforeOp Ecomp | Ecomp
Etyped ::=
Ebefore
| Ebefore ":" Type
(* logical connectives *)
ElogicAND ::=
ElogicAND "andalso" Etyped
| Etyped
ElogicOR ::=
| ElogicOR "orelse" ElogicAND
| ElogicAND
E ::=
"if" E "then" E "else" E
| "case" E "of" PEs
| "fn" V "=>" E
| "raise" E
| ElogicOR
Fdecl ::= V V "=" E // (V,V,E)
// second V is parameter
AndFDecls ::= FDecl // ([FDecl])
| FDecl "and" AndFDecls // FDecl :: AndFDecls
LetDec ::= "val" V "=" E
| "fun" AndFDecls
LetDecs ::= LetDec LetDecs
| ";" LetDecs
|
PEs ::= PE // ([PE])
| PE "|" PEs // PE::PEs
PE ::= Pattern "=>" E // (Pattern, E)
Pattern ::= E
// operators must be constructors and variables used linearly.
// constructors are Pvar, Plit and Pcon
Type ::=
DType // DType
| DType "->" Type // Ast_Tfn DType Type
DType ::=
TyVar // Ast_Tvar
| DType TyOp // Ast_Tapp [DType] TyOp
| "(" TypeList ")" Tyop // Ast_Tapp TypeList TyOp
| "(" Type ")" // Type
TypeList ::=
Type // [Type]
| Type "," TypeList // Type::TypeList
TypeDec ::=
"datatype" DtypeDecls // DtypeDeclList
DtypeDecls ::=
DtypeDecl // [DtypeDecl]
| DtypeDecl "and" DtypeDecls // DtypeDecl :: DtypeDecls
DtypeDecl ::= TypeName "=" DtypeCons
TypeName ::= TyOp
| TyVar TyOp
| "(" TyVarList ")" TyOp
TyVarList ::= TyVar | TyVarList "," TyVar
Dconstructor ::= ConstructorName "of" StarTypesP
| ConstructorName
DtypeCons ::= Dconstructor
| Dconstructor "|" DtypeCons
StarTypesP ::= "(" StarTypes ")" | StarTypes
StarTypes ::=
| DType
| StarTypes "*" DType
Decl ::= "val" Pattern "=" E
| "fun" AndFDecls
| TypeDec
| "type" TypeName "=" Type
SpecLine ::= "val" V ":" Type
| "type" TypeName OptTypEqn
| "exception" Dconstructor
| TypeDec
OptTypEqn ::= "=" Type |
SpecLineList ::= SpecLine SpecLineList
| ";" SpecLineList
|
SignatureValue ::= "sig" SpecLineList "end"
OptionalSignatureAscription ::= ":>" SignatureValue
|
Structure ::= "structure" StructName OptionalSignatureAscription "=" "struct" Decls "end"