-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.grammar
295 lines (295 loc) · 4.5 KB
/
mod.grammar
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
284
285
286
287
288
289
290
291
292
293
294
295
S
( S_PAR ) S_REC
: 1 3
string S_REC
: 0 1
int S_REC
: 0 1
real S_REC
: 0 1
bool S_REC
: 0 1
id S_REC
i ~ -> i : 0 @ 1
r ~ -> r : 0 f@ 1
b ~ -> b : 0 @ 1
s ~ -> s : 0 2@ 1
S_PAR@
( S_PAR ) S_REC
string S_REC
int S_REC
real S_REC
bool S_REC
id S_REC
:= id ASSIGNMENT
:= i i -> ~ : 2 1 !
:= r r -> ~ : 2 1 f!
:= b b -> ~ : 2 1 !
:= r i -> ~ : 2 s>f 1 f!
:= i r -> ~ : 2 f>s 1 !
:= s s -> ~ : 2 1 2!
+ RESR RESR
+ i i -> i : 1 2 +
+ r r -> r : 1 2 f+
+ i r -> i : 1 s>f 2 f+
+ r i -> r : 1 2 s>f f+
+ s s -> s : 1 2 s+
- RESR RESR_MIN
- i i -> i : 1 2 -
- r r -> r : 1 2 f-
- i r -> i : 1 s>f 2 f-
- r i -> r : 1 2 s>f f-
- i ~ -> i : 1 negate
- r ~ -> r : 1 fnegate
* RESR RESR
* i i -> i : 1 2 *
* r r -> r : 1 2 f*
* i r -> i : 1 s>f 2 f*
* r i -> r : 1 2 s>f f*
/ RESR RESR
/ i i -> i : 1 2 /
/ r r -> r : 1 2 f/
/ i r -> i : 1 s>f 2 f/
/ r i -> r : 1 2 s>f f/
% RESR RESR
% i i -> i : 1 2 /mod drop
^ RESR RESR
^ i i -> i : 1 s>f 2 s>f f** f>s
^ r r -> r : 1 2 f**
^ i r -> r : 1 s>f 2 f**
^ r i -> r : 1 2 s>f f**
= RESR RESR
= i i -> b : 1 2 =
= r r -> b : 1 2 f=
= i r -> b : 1 s>f 2 f=
= r i -> b : 1 2 s>f f=
= b b -> b : 1 2 0=
> RESR RESR
> i i -> b : 1 2 >
> r r -> b : 1 2 f>
> i r -> b : 1 s>f 2 f>
> r i -> b : 1 2 s>f f>
>= RESR RESR
>= i i -> b : 1 2 >=
>= r r -> b : 1 2 f>=
>= i r -> b : 1 s>f 2 f>=
>= r i -> b : 1 2 s>f f>=
< RESR RESR
< i i -> b : 1 2 <
< r r -> b : 1 2 f<
< i r -> b : 1 s>f 2 f<
< r i -> b : 1 2 s>f f<
<= RESR RESR
<= i i -> b : 1 2 <=
<= r r -> b : 1 2 f<=
<= i r -> b : 1 s>f 2 f<=
<= r i -> b : 1 2 s>f f<=
!= RESR RESR
<> i i -> b : 1 2 <>
<> r r -> b : 1 2 f<>
<> i r -> b : 1 s>f 2 f<>
<> r i -> b : 1 2 s>f f<>
or RESR RESR
or b b -> b : 1 2 or
and RESR RESR
or b b -> b : 1 2 and
not RESR
not b -> b : 1 invert
sin RESR
sin i -> r : 1 s>f fsin
sin r -> r : 1 fsin
cos RESR
cos i -> r : 1 s>f fcos
cos r -> r : 1 fcos
tan RESR
tan i -> r : 1 s>f ftan
tan r -> r : 1 ftan
if RESR EXPR ELSE
if b @ @ -> ~ : 1 if 2 else 3 then
while RESR EXPR EXPRLIST
while b @ @ -> ~ : begin 1 while 2 3 repeat
@ let ( ( id type ) VARLIST )
let ( ( ~ ~ ) ~ ) -> ~ :
# let ( ( id FUNLIST ) ( type FUNTYPE ) ) EXPR EXPRLIST
let ( ( ~ ~ ) ( ~ ~ ) ) @ @ -> ~ :
stdout RESR
stdout i -> ~ : 1 .
stdout r -> ~ : 1 f.
stdout b -> ~ : 1 .
stdout s -> ~ : 1 type
~
:
S_REC
( S_PAR ) S_REC
string S_REC
int S_REC
real S_REC
bool S_REC
id S_REC
~
EXPR
( EXPR_PAR )
: 1
string
s : 0
int
i : 0
real
r : 0
bool
b : 0
id
i -> i : 0 @
r -> r : 0 f@
b -> b : 0 @
s -> s : 0 2@
EXPR_PAR
:= id ASSIGNMENT
+ RESR RESR
- RESR RESR_MIN
* RESR RESR
/ RESR RESR
% RESR RESR
^ RESR RESR
= RESR RESR
> RESR RESR
>= RESR RESR
< RESR RESR
<= RESR RESR
!= RESR RESR
or RESR RESR
and RESR RESR
not RESR
sin RESR
cos RESR
tan RESR
if RESR EXPR ELSE
while RESR EXPR EXPRLIST
@ let ( ( id type ) VARLIST )
# let ( ( id FUNLIST ) ( type FUNTYPE ) ) EXPR EXPRLIST
stdout RESR
RESR
( OPER )
( s ) -> s : 1
( i ) -> i : 1
( b ) -> b : 1
( r ) -> r : 1
string
int
real
bool
id
OPER
:= id ASSIGNMENT
+ RESR RESR
- RESR RESR_MIN
* RESR RESR
/ RESR RESR
% RESR RESR
^ RESR RESR
= RESR RESR
> RESR RESR
>= RESR RESR
< RESR RESR
<= RESR RESR
!= RESR RESR
or RESR RESR
and RESR RESR
not RESR
sin RESR
cos RESR
tan RESR
RESR_MIN
( OPER )
string
int
real
bool
id
~
EXPRLIST
( EXPR_PAR ) EXPRLIST
: 1 3
string EXPRLIST
: 0 1
int EXPRLIST
: 0 1
real EXPRLIST
: 0 1
bool EXPRLIST
: 0 1
id EXPRLIST
i ~ -> i : 0 @ 1
r ~ -> r : 0 f@ 1
b ~ -> b : 0 @ 1
s ~ -> s : 0 2@ 1
~
VARLIST
@ ( id type ) VARLIST
( ~ i ) ~ -> ~ :
( ~ b ) ~ -> ~ :
( ~ r ) ~ -> ~ :
( ~ s ) ~ -> ~ :
~
ELSE
( EXPR_PAR )
string
int
real
bool
id
~
FUNLIST
id FUNLIST
:
~
FUNTYPE
type FUNTYPE
:
~
PARAMLIST
( OPER ) PARAMLIST
: 1 3
string PARAMLIST
: 0 1
int PARAMLIST
: 0 1
real PARAMLIST
: 0 1
bool PARAMLIST
: 0 1
id PARAMLIST
: 0 1
~
ASSIGNMENT
( ASSIGNMENT_PAREN )
( s ) -> s : 1
( i ) -> i : 1
( b ) -> b : 1
( r ) -> r : 1
string
int
real
bool
id
ASSIGNMENT_PAREN
+ RESR RESR
- RESR RESR_MIN
* RESR RESR
/ RESR RESR
% RESR RESR
^ RESR RESR
= RESR RESR
> RESR RESR
>= RESR RESR
< RESR RESR
<= RESR RESR
!= RESR RESR
or RESR RESR
and RESR RESR
not RESR
sin RESR
cos RESR
tan RESR
! id PARAMLIST
: