-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathABS.cf
284 lines (217 loc) · 8.8 KB
/
ABS.cf
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
-- COMMENTS
-----------
comment "//" ;
comment "/*" "*/" ;
-- LITERALS
-----------
LNull. Literal ::= "null" ;
LThis. Literal ::= "this" ;
LStr. Literal ::= String ;
LInt. Literal ::= Integer ;
LFloat. Literal ::= Double ;
-- IDENTIFIER TOKENS
--------------------
position token U (upper (letter | digit | '_')*) ;
position token L (lower (letter | digit | '_')*) ;
-- MAYBE-QUALIFIED IDENTIFIERS
------------------------------
-- upper
U_. QU ::= U ;
QU. QU ::= U "." QU ;
-- lower
L_. QL ::= L ;
QL. QL ::= U "." QL ;
-- any
LA. QA ::= L ;
UA. QA ::= U ;
QA. QA ::= U "." QA;
separator nonempty U "," ; -- for <Typevar1,..>
separator nonempty QU "," ; -- for list of types/constructors
separator nonempty QA "," ; -- for imports/exports
-- TYPES
--------
TSimple. T ::= QU ;
TPoly. T ::= QU "<" [T] ">" ;
TInfer. T ::= "_" ; -- habs-only: for type inference
separator nonempty T "," ;
-- FORMAL PARAMETERS
--------------------
FormalPar. FormalPar ::= T L ;
separator FormalPar "," ; -- for list of formal parameters
-- ENTRY PROGRAM
----------------
entrypoints Program ;
Program. Program ::= [Module] ; -- multiple modules inside a single file
-- MODULES
----------
Module. Module ::= "module" QU ";" [Export] [Import] [AnnDecl] MaybeBlock ;
separator Module "";
-- EXPORTS
----------
StarExport. Export ::= "export" "*" ;
StarFromExport. Export ::= "export" "*" "from" QU ;
AnyExport. Export ::= "export" [QA] ;
AnyFromExport. Export ::= "export" [QA] "from" QU ; -- note to self: should be unqualified, but for parser issues do the check it at codegen
terminator Export ";" ;
-- IMPORTS
----------
StarFromImport. Import ::= IsForeign "*" "from" QU ;
AnyImport. Import ::= IsForeign [QA] ;
AnyFromImport. Import ::= IsForeign [QA] "from" QU ; -- note to self: should be unqualified, but for parser issues do the check it at codegen
terminator Import ";" ;
NoForeign. IsForeign ::= "import" ;
YesForeign. IsForeign ::= "fimport" ; -- habs-only: is used to FFI to Haskell libraries
-- DECLARATIONS
---------------
-- ADT DECLARATIONS
-------------------
DType. Decl ::= "type" U "=" T ";" ;
DTypePoly. Decl ::= "type" U "<" [U] ">" "=" T ";" ;
DData. Decl ::= "data" U "=" [ConstrIdent] ";" ;
DDataPoly. Decl ::= "data" U "<" [U] ">" "=" [ConstrIdent] ";" ;
separator nonempty ConstrIdent "|" ;
SinglConstrIdent. ConstrIdent ::= U ;
ParamConstrIdent. ConstrIdent ::= U "(" [ConstrType] ")" ;
separator ConstrType "," ;
EmptyConstrType. ConstrType ::= T ;
RecordConstrType. ConstrType ::= T L ;
-- FUNCTION DECLARATIONS
------------------------
DFun. Decl ::= "def" T L "(" [FormalPar] ")" "=" FunBody ";" ;
DFunPoly. Decl ::= "def" T L "<" [U] ">" "(" [FormalPar] ")" "=" FunBody ";" ;
BuiltinFunBody. FunBody ::= "builtin" ;
NormalFunBody. FunBody ::= PureExp ;
-- INTERFACE DECLARATIONS
-------------------------
DInterf. Decl ::= "interface" U "{" [MethSig] "}" ;
DExtends. Decl ::= "interface" U "extends" [QU] "{" [MethSig] "}" ;
terminator MethSig ";" ;
MethSig. MethSig ::= [Ann] T L "(" [FormalPar] ")" ;
-- CLASS DECLARATIONS
---------------------
DClass. Decl ::= "class" U "{" [ClassBody] MaybeBlock [ClassBody] "}" ;
DClassPar. Decl ::= "class" U "(" [FormalPar] ")" "{" [ClassBody] MaybeBlock [ClassBody] "}" ;
DClassImplements. Decl ::= "class" U "implements" [QU] "{" [ClassBody] MaybeBlock [ClassBody] "}" ;
DClassParImplements. Decl ::= "class" U "(" [FormalPar] ")" "implements" [QU] "{" [ClassBody] MaybeBlock [ClassBody] "}" ;
separator ClassBody "" ;
FieldClassBody. ClassBody ::= T L ";" ;
FieldAssignClassBody. ClassBody ::= T L "=" PureExp ";" ;
MethClassBody. ClassBody ::= T L "(" [FormalPar] ")" "{" [AnnStm] "}" ; -- braces are required
-- STATEMENTS
--------------
SSkip. Stm ::= "skip" ";" ;
SSuspend. Stm ::= "suspend" ";" ;
SReturn. Stm ::= "return" Exp ";" ;
SAssert. Stm ::= "assert" PureExp ";" ;
SAwait. Stm ::= "await" AwaitGuard ";" ;
SAss. Stm ::= L "=" Exp ";" ;
SFieldAss. Stm ::= "this" "." L "=" Exp ";" ;
SDec. Stm ::= T L ";" ;
SDecAss. Stm ::= T L "=" Exp ";" ;
SWhile. Stm ::= "while" "(" PureExp ")" AnnStm ;
SIf. Stm ::= "if" "(" PureExp ")" Stm ; -- annstm here makes rr conflict
SIfElse. Stm ::= "if" "(" PureExp ")" Stm "else" Stm ; -- annstm here makes rr conflict
SCase. Stm ::= "case" PureExp "{" [SCaseBranch] "}" ;
SCaseBranch. SCaseBranch ::= Pattern "=>" AnnStm ;
separator nonempty SCaseBranch "" ; -- cannot be empty, does not have to be terminated by ";"
SBlock. Stm ::= "{" [AnnStm] "}" ;
SExp. Stm ::= Exp ";" ; -- standalone expression
-- AWAIT GUARDS
---------------
GFut. AwaitGuard ::= L "?" ;
GFutField. AwaitGuard ::= "this" "." L "?" ;
GExp. AwaitGuard ::= PureExp ;
GAnd. AwaitGuard ::= AwaitGuard "&" AwaitGuard ;
-- EXPRESSIONS
--------------
ExpP. Exp ::= PureExp ;
ExpE. Exp ::= EffExp ;
-- PURE EXPRESSIONS
-------------------
EOr. PureExp ::= PureExp "||" PureExp1 ;
EAnd. PureExp1 ::= PureExp1 "&&" PureExp2 ;
EEq. PureExp2 ::= PureExp2 "==" PureExp3 ;
ENeq. PureExp2 ::= PureExp2 "!=" PureExp3 ;
ELt. PureExp3 ::= PureExp3 "<" PureExp4 ;
ELe. PureExp3 ::= PureExp3 "<=" PureExp4 ;
EGt. PureExp3 ::= PureExp3 ">" PureExp4 ;
EGe. PureExp3 ::= PureExp3 ">=" PureExp4 ;
EAdd. PureExp4 ::= PureExp4 "+" PureExp5 ;
ESub. PureExp4 ::= PureExp4 "-" PureExp5 ;
EMul. PureExp5 ::= PureExp5 "*" PureExp6 ;
EDiv. PureExp5 ::= PureExp5 "/" PureExp6 ;
EMod. PureExp5 ::= PureExp5 "%" PureExp6 ;
ELogNeg. PureExp6 ::= "!" PureExp6 ;
EIntNeg. PureExp6 ::= "-" PureExp6 ;
EFunCall. PureExp7 ::= QL "(" [PureExp] ")" ;
ENaryFunCall. PureExp7 ::= QL "[" [PureExp] "]" ;
EVar. PureExp7 ::= L ;
EField. PureExp7 ::= "this" "." L ;
ESinglConstr. PureExp7 ::= QU ;
EParamConstr. PureExp7 ::= QU "(" [PureExp] ")" ;
ELit. PureExp7 ::= Literal ;
ELet. PureExp7 ::= "let" "(" FormalPar ")" "=" PureExp "in" PureExp ;
EIf. PureExp7 ::= "if" PureExp "then" PureExp "else" PureExp ;
ECase. PureExp7 ::= "case" PureExp "{" [ECaseBranch] "}" ;
coercions PureExp 7 ;
separator PureExp "," ; -- for passing arguments to function/method calls
ECaseBranch. ECaseBranch ::= Pattern "=>" PureExp ;
terminator nonempty ECaseBranch ";" ;
-- PATTERN MATCHING
-------------------
separator Pattern "," ;
PLit. Pattern ::= Literal ;
PVar. Pattern ::= L ;
PSinglConstr. Pattern ::= QU ;
PParamConstr. Pattern ::= QU "(" [Pattern] ")" ;
PWildCard. Pattern ::= "_" ;
-- EFFECTFUL EXPRESSIONS
------------------------
New. EffExp ::= "new" QU "(" [PureExp] ")" ;
NewLocal. EffExp ::= "new" "local" QU "(" [PureExp] ")" ;
SyncMethCall. EffExp ::= PureExp "." L "(" [PureExp] ")" ;
ThisSyncMethCall. EffExp ::= "this" "." L "(" [PureExp] ")" ; -- needed because of ambiguity with PureExp.EThis
AsyncMethCall. EffExp ::= PureExp "!" L "(" [PureExp] ")" ;
AwaitMethCall. EffExp ::= "await" PureExp "!" L "(" [PureExp] ")" ;
Get. EffExp ::= PureExp "." "get" ;
-- ANNOTATIONS
--------------
Ann. Ann ::= "[" Ann_ "]";
separator Ann "" ;
AnnNoType. Ann_ ::= PureExp ;
AnnWithType. Ann_ ::= T ":" PureExp ;
AnnStm. AnnStm ::= [Ann] Stm;
separator AnnStm "" ;
AnnDecl. AnnDecl ::= [Ann] Decl;
separator AnnDecl "" ;
-- missing: classbody and type annotations
-- both yield many rr conflicts
-- EXTENSION, Input/Output
SPrint. Stm ::= "print" PureExp ";" ;
SPrintln. Stm ::= "println" PureExp ";" ;
Readln. EffExp ::= "readln" "(" ")" ";" ;
-- EXTENSION, EXCEPTIONS
------------------------
DException. Decl ::= "exception" ConstrIdent ";" ;
SThrow. Stm ::= "throw" PureExp ";" ;
STryCatchFinally. Stm ::= "try" AnnStm "catch" "{" [SCaseBranch] "}" MaybeFinally ;
JustFinally. MaybeFinally ::= "finally" AnnStm ;
NoFinally. MaybeFinally ::= ;
-- EXTENSION, PROMISES
------------------------
SGive. Stm ::= PureExp "." "pro_give" "(" PureExp ")" ";" ; -- habs-only
ProNew. EffExp ::= "pro_new" ; -- habs-only
ProTry. EffExp ::= PureExp "." "pro_try" ; -- habs-only
-- EXTENSION, DC
----------------
ThisDC. EffExp ::= "thisDC" "(" ")"; -- not in StdLib of habs, because it would break purity
-- EXTENSION, REALTIME
SDuration. Stm ::= "duration" "(" PureExp "," PureExp ")" ";" ;
GDuration. AwaitGuard ::= "duration" "(" PureExp "," PureExp ")" ;
Now. EffExp ::= "now" "(" ")" ; -- not in StdLib of habs, because it would break purity
Currentms. EffExp ::= "currentms" "(" ")" ; -- not in StdLib of habs, because it would break purity
Random. EffExp ::= "random" "(" PureExp")" ; -- not in StdLib of habs, because it would break purity
-- UTILS
--------------
JustBlock. MaybeBlock ::= "{" [AnnStm] "}" ;
NoBlock. MaybeBlock ::= ;