depager 0.2.3 → 0.3.0.b20160729
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.en +4 -19
- data/README.ja +42 -79
- data/bin/depager +42 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +49 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +10 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/extension/calc.simple_action.dr +33 -0
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +44 -0
- data/examples/pl0d/pl0ds.dr +337 -334
- data/examples/pl0d/test.pl0ds +33 -33
- data/examples/rie_calc/calc.rie.dr +57 -0
- data/examples/rie_calc/test.calc +4 -0
- data/examples/rie_dcuse/dcuse.rie.dr +71 -0
- data/examples/rie_dcuse/test.dcuse +1 -0
- data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
- data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
- data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
- data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
- data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
- data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
- data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
- data/examples/rie_pl0/pl0.rie.dr +450 -0
- data/examples/rie_pl0/test.pl0 +10 -0
- data/examples/sample_calc/calc.action.dr +33 -33
- data/examples/sample_calc/calc.ast.action.dr +65 -66
- data/examples/sample_calc/calc.ast.dr +55 -55
- data/examples/sample_calc/calc.cst.dr +45 -45
- data/examples/sample_calc/calc.dr +43 -43
- data/examples/sample_calc/calc.lex.dr +29 -29
- data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
- data/examples/slex_test/divreg.slex.dr +29 -29
- data/examples/slex_test/ljoin.slex.dr +36 -36
- data/examples/slex_test/test.divreg +1 -1
- data/examples/slex_test/test.ljoin +3 -3
- data/lib/depager.rb +582 -670
- data/lib/depager/grammar.rb +256 -291
- data/lib/depager/lr.rb +574 -579
- data/lib/depager/parser.rb +282 -277
- data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
- data/lib/depager/ruby/plugins/action.rb +53 -43
- data/lib/depager/ruby/plugins/ast.dr +364 -269
- data/lib/depager/ruby/plugins/ast.rb +1367 -1308
- data/lib/depager/ruby/plugins/cst.dr +172 -180
- data/lib/depager/ruby/plugins/cst.rb +587 -626
- data/lib/depager/ruby/plugins/lex.dr +85 -89
- data/lib/depager/ruby/plugins/lex.rb +310 -336
- data/lib/depager/ruby/plugins/rie.dr +723 -0
- data/lib/depager/ruby/plugins/rie.rb +1653 -0
- data/lib/depager/ruby/plugins/slex.dr +202 -200
- data/lib/depager/ruby/plugins/slex.rb +780 -817
- data/lib/depager/ruby/plugins/srp.rb +56 -51
- data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
- data/lib/depager/utils.rb +148 -318
- data/lib/depager/version.rb +4 -3
- metadata +52 -60
- data/ChangeLog +0 -16
- data/data/depager/pre-setup.rb +0 -3
- data/examples/c89/c89.tab.rb +0 -7127
- data/examples/pl0d/pl0ds.tab.rb +0 -2698
- data/examples/sample_calc/calc.action.tab.rb +0 -457
- data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
- data/examples/sample_calc/calc.ast.tab.rb +0 -665
- data/examples/sample_calc/calc.astdf.dr +0 -54
- data/examples/sample_calc/calc.astdf.tab.rb +0 -672
- data/examples/sample_calc/calc.atree.tab.rb +0 -451
- data/examples/sample_calc/calc.cst.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.dr +0 -33
- data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
- data/examples/sample_calc/calc.tab.rb +0 -365
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
- data/examples/slex_test/divreg.slex.tab.rb +0 -303
- data/examples/slex_test/ljoin.slex.tab.rb +0 -370
- data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
- data/lib/depager/ruby/plugins/astdf.rb +0 -6
- data/lib/depager/ruby/plugins/atree.dr +0 -55
- data/lib/depager/ruby/plugins/atree.rb +0 -347
- data/lib/depager/ruby/plugins/nvaction.rb +0 -19
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
@@ -0,0 +1,49 @@
|
|
1
|
+
const m = 7, n = 85;
|
2
|
+
var x,y;
|
3
|
+
|
4
|
+
function puts_ntimes(x, n)
|
5
|
+
var i;
|
6
|
+
begin
|
7
|
+
i := 0;
|
8
|
+
while i < n do
|
9
|
+
begin
|
10
|
+
write x; writeln;
|
11
|
+
i := i + 1;
|
12
|
+
end;
|
13
|
+
return i
|
14
|
+
end;
|
15
|
+
|
16
|
+
function fact(x)
|
17
|
+
begin
|
18
|
+
write x; writeln;
|
19
|
+
|
20
|
+
if x = 1 then return 1;
|
21
|
+
return x * fact(x - 1)
|
22
|
+
end;
|
23
|
+
|
24
|
+
function outer(x, z)
|
25
|
+
function inner(x)
|
26
|
+
begin
|
27
|
+
write x; write y; write z; writeln;
|
28
|
+
return outer(x + 1, z - 1)
|
29
|
+
end;
|
30
|
+
begin
|
31
|
+
if z = 0 then return 0;
|
32
|
+
return inner(x)
|
33
|
+
end;
|
34
|
+
|
35
|
+
|
36
|
+
begin
|
37
|
+
x := m; y := n;
|
38
|
+
write x; write y; writeln;
|
39
|
+
x := 84; y := 36;
|
40
|
+
write x; write y; writeln;
|
41
|
+
|
42
|
+
y := puts_ntimes(5, 10);
|
43
|
+
write y; writeln;
|
44
|
+
|
45
|
+
y := fact(5);
|
46
|
+
write y; writeln;
|
47
|
+
|
48
|
+
y := outer(5, 5);
|
49
|
+
end.
|
data/examples/c89/c89.dr
CHANGED
@@ -1,496 +1,493 @@
|
|
1
|
-
%class CParser
|
2
|
-
# from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html and
|
3
|
-
# http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
|
4
|
-
%extend Lexer ('plugins/lex.rb')
|
5
|
-
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
6
|
-
%inner{
|
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
|
-
/0
|
59
|
-
/0[0-9]+/
|
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
|
-
postfix_expression
|
118
|
-
|
119
|
-
| postfix_expression '
|
120
|
-
| postfix_expression
|
121
|
-
| postfix_expression
|
122
|
-
| postfix_expression
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
unary_expression
|
134
|
-
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
| '
|
145
|
-
| '
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
multiplicative_expression
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
additive_expression
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
shift_expression
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
relational_expression
|
176
|
-
|
177
|
-
| relational_expression
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
equality_expression
|
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
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
;
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
specifier_qualifier_list
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
direct_declarator
|
359
|
-
|
360
|
-
| '('
|
361
|
-
| direct_declarator '
|
362
|
-
| direct_declarator '
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
pointer
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
| '[' ']'
|
416
|
-
| '
|
417
|
-
|
|
418
|
-
| direct_abstract_declarator '
|
419
|
-
| '(' ')'
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
;
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
;
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
%%
|
495
|
-
p = CParser::createDecoratedParser
|
496
|
-
p.parse(STDIN)
|
1
|
+
%class CParser::Parser
|
2
|
+
# from http://www.lysator.liu.se/c/ANSI-C-grammar-y.html and
|
3
|
+
# http://www.lysator.liu.se/c/ANSI-C-grammar-l.html
|
4
|
+
%extend Depager::Lexer ('plugins/lex.rb')
|
5
|
+
#%decorate Depager::LALR::ShiftReducePrinter ('plugins/srp.rb')
|
6
|
+
%inner{
|
7
|
+
KEYWORDS = {
|
8
|
+
"auto" => :AUTO,
|
9
|
+
"break" => :BREAK,
|
10
|
+
"case" => :CASE,
|
11
|
+
"char" => :CHAR,
|
12
|
+
"const" => :CONST,
|
13
|
+
"continue" => :CONTINUE,
|
14
|
+
"default" => :DEFAULT,
|
15
|
+
"do" => :DO,
|
16
|
+
"double" => :DOUBLE,
|
17
|
+
"else" => :ELSE,
|
18
|
+
"enum" => :ENUM,
|
19
|
+
"extern" => :EXTERN,
|
20
|
+
"float" => :FLOAT,
|
21
|
+
"for" => :FOR,
|
22
|
+
"goto" => :GOTO,
|
23
|
+
"if" => :IF,
|
24
|
+
"int" => :INT,
|
25
|
+
"long" => :LONG,
|
26
|
+
"register" => :REGISTER,
|
27
|
+
"return" => :RETURN,
|
28
|
+
"short" => :SHORT,
|
29
|
+
"signed" => :SIGNED,
|
30
|
+
"sizeof" => :SIZEOF,
|
31
|
+
"static" => :STATIC,
|
32
|
+
"struct" => :STRUCT,
|
33
|
+
"switch" => :SWITCH,
|
34
|
+
"typedef" => :TYPEDEF,
|
35
|
+
"union" => :UNION,
|
36
|
+
"unsigned" => :UNSIGNED,
|
37
|
+
"void" => :VOID,
|
38
|
+
"volatile" => :VOLATILE,
|
39
|
+
"while" => :WHILE,
|
40
|
+
}
|
41
|
+
%}
|
42
|
+
%%
|
43
|
+
%LEX{
|
44
|
+
/#.*\n/ { @line_orig =~ /^#/ || raise }
|
45
|
+
'/*'
|
46
|
+
{
|
47
|
+
begin
|
48
|
+
break if @line =~ /\*\//
|
49
|
+
end while @line = file.gets
|
50
|
+
@line = $'
|
51
|
+
}
|
52
|
+
/\/\/[^\n]*/ { }
|
53
|
+
|
54
|
+
/[a-zA-Z_][a-zA-Z0-9_]*/ { yield token(KEYWORDS[$&] || :IDENTIFIER) }
|
55
|
+
/0[xX][0-9a-fA-F]+/ { yield token(:CONSTANT) }
|
56
|
+
/0[0-9]+/ { yield token(:CONSTANT) }
|
57
|
+
/[0-9]+/ { yield token(:CONSTANT) }
|
58
|
+
/[0-9]+/ { yield token(:CONSTANT) }
|
59
|
+
/[0-9]*\.[0-9]+/ { yield token(:CONSTANT) }
|
60
|
+
/"(\\.|[^"\\])*"/ { yield token(:STRING_LITERAL) }
|
61
|
+
|
62
|
+
'...' { yield token(:ELLIPSIS) }
|
63
|
+
'>>=' { yield token(:RIGHT_ASSIGN) }
|
64
|
+
'<<=' { yield token(:LEFT_ASSIGN) }
|
65
|
+
'+=' { yield token(:ADD_ASSIGN) }
|
66
|
+
'-=' { yield token(:SUB_ASSIGN) }
|
67
|
+
'*=' { yield token(:MUL_ASSIGN) }
|
68
|
+
'/=' { yield token(:DIV_ASSIGN) }
|
69
|
+
'%=' { yield token(:MOD_ASSIGN) }
|
70
|
+
'&=' { yield token(:AND_ASSIGN) }
|
71
|
+
'^=' { yield token(:XOR_ASSIGN) }
|
72
|
+
'|=' { yield token(:OR_ASSIGN) }
|
73
|
+
'>>' { yield token(:RIGHT_OP) }
|
74
|
+
'<<' { yield token(:LEFT_OP) }
|
75
|
+
'++' { yield token(:INC_OP) }
|
76
|
+
'--' { yield token(:DEC_OP) }
|
77
|
+
'->' { yield token(:PTR_OP) }
|
78
|
+
'&&' { yield token(:AND_OP) }
|
79
|
+
'||' { yield token(:OR_OP) }
|
80
|
+
'<=' { yield token(:LE_OP) }
|
81
|
+
'>=' { yield token(:GE_OP) }
|
82
|
+
'==' { yield token(:EQ_OP) }
|
83
|
+
'!=' { yield token(:NE_OP) }
|
84
|
+
|
85
|
+
/[ \t\v\r\n\f]/ { }
|
86
|
+
/./ { yield token($&) }
|
87
|
+
%}
|
88
|
+
|
89
|
+
#begin-rule
|
90
|
+
translation_unit
|
91
|
+
: external_declaration
|
92
|
+
| translation_unit external_declaration
|
93
|
+
;
|
94
|
+
|
95
|
+
external_declaration
|
96
|
+
: function_definition
|
97
|
+
| declaration
|
98
|
+
;
|
99
|
+
|
100
|
+
function_definition
|
101
|
+
: declaration_specifiers declarator declaration_list compound_statement
|
102
|
+
| declaration_specifiers declarator compound_statement
|
103
|
+
| declarator declaration_list compound_statement
|
104
|
+
| declarator compound_statement
|
105
|
+
;
|
106
|
+
|
107
|
+
primary_expression
|
108
|
+
: IDENTIFIER
|
109
|
+
| CONSTANT
|
110
|
+
| STRING_LITERAL
|
111
|
+
| '(' expression ')'
|
112
|
+
;
|
113
|
+
|
114
|
+
postfix_expression
|
115
|
+
: primary_expression
|
116
|
+
| postfix_expression '[' expression ']'
|
117
|
+
| postfix_expression '(' ')'
|
118
|
+
| postfix_expression '(' argument_expression_list ')'
|
119
|
+
| postfix_expression '.' IDENTIFIER
|
120
|
+
| postfix_expression PTR_OP IDENTIFIER
|
121
|
+
| postfix_expression INC_OP
|
122
|
+
| postfix_expression DEC_OP
|
123
|
+
;
|
124
|
+
|
125
|
+
argument_expression_list
|
126
|
+
: assignment_expression
|
127
|
+
| argument_expression_list ',' assignment_expression
|
128
|
+
;
|
129
|
+
|
130
|
+
unary_expression
|
131
|
+
: postfix_expression
|
132
|
+
| INC_OP unary_expression
|
133
|
+
| DEC_OP unary_expression
|
134
|
+
| unary_operator cast_expression
|
135
|
+
| SIZEOF unary_expression
|
136
|
+
| SIZEOF '(' type_name ')'
|
137
|
+
;
|
138
|
+
|
139
|
+
unary_operator
|
140
|
+
: '&'
|
141
|
+
| '*'
|
142
|
+
| '+'
|
143
|
+
| '-'
|
144
|
+
| '~'
|
145
|
+
| '!'
|
146
|
+
;
|
147
|
+
|
148
|
+
cast_expression
|
149
|
+
: unary_expression
|
150
|
+
| '(' type_name ')' cast_expression
|
151
|
+
;
|
152
|
+
|
153
|
+
multiplicative_expression
|
154
|
+
: cast_expression
|
155
|
+
| multiplicative_expression '*' cast_expression
|
156
|
+
| multiplicative_expression '/' cast_expression
|
157
|
+
| multiplicative_expression '%' cast_expression
|
158
|
+
;
|
159
|
+
|
160
|
+
additive_expression
|
161
|
+
: multiplicative_expression
|
162
|
+
| additive_expression '+' multiplicative_expression
|
163
|
+
| additive_expression '-' multiplicative_expression
|
164
|
+
;
|
165
|
+
|
166
|
+
shift_expression
|
167
|
+
: additive_expression
|
168
|
+
| shift_expression LEFT_OP additive_expression
|
169
|
+
| shift_expression RIGHT_OP additive_expression
|
170
|
+
;
|
171
|
+
|
172
|
+
relational_expression
|
173
|
+
: shift_expression
|
174
|
+
| relational_expression '<' shift_expression
|
175
|
+
| relational_expression '>' shift_expression
|
176
|
+
| relational_expression LE_OP shift_expression
|
177
|
+
| relational_expression GE_OP shift_expression
|
178
|
+
;
|
179
|
+
|
180
|
+
equality_expression
|
181
|
+
: relational_expression
|
182
|
+
| equality_expression EQ_OP relational_expression
|
183
|
+
| equality_expression NE_OP relational_expression
|
184
|
+
;
|
185
|
+
|
186
|
+
and_expression
|
187
|
+
: equality_expression
|
188
|
+
| and_expression '&' equality_expression
|
189
|
+
;
|
190
|
+
|
191
|
+
exclusive_or_expression
|
192
|
+
: and_expression
|
193
|
+
| exclusive_or_expression '^' and_expression
|
194
|
+
;
|
195
|
+
|
196
|
+
inclusive_or_expression
|
197
|
+
: exclusive_or_expression
|
198
|
+
| inclusive_or_expression '|' exclusive_or_expression
|
199
|
+
;
|
200
|
+
|
201
|
+
logical_and_expression
|
202
|
+
: inclusive_or_expression
|
203
|
+
| logical_and_expression AND_OP inclusive_or_expression
|
204
|
+
;
|
205
|
+
|
206
|
+
logical_or_expression
|
207
|
+
: logical_and_expression
|
208
|
+
| logical_or_expression OR_OP logical_and_expression
|
209
|
+
;
|
210
|
+
|
211
|
+
conditional_expression
|
212
|
+
: logical_or_expression
|
213
|
+
| logical_or_expression '?' expression ':' conditional_expression
|
214
|
+
;
|
215
|
+
|
216
|
+
assignment_expression
|
217
|
+
: conditional_expression
|
218
|
+
| unary_expression assignment_operator assignment_expression
|
219
|
+
;
|
220
|
+
|
221
|
+
assignment_operator
|
222
|
+
: '='
|
223
|
+
| MUL_ASSIGN
|
224
|
+
| DIV_ASSIGN
|
225
|
+
| MOD_ASSIGN
|
226
|
+
| ADD_ASSIGN
|
227
|
+
| SUB_ASSIGN
|
228
|
+
| LEFT_ASSIGN
|
229
|
+
| RIGHT_ASSIGN
|
230
|
+
| AND_ASSIGN
|
231
|
+
| XOR_ASSIGN
|
232
|
+
| OR_ASSIGN
|
233
|
+
;
|
234
|
+
|
235
|
+
expression
|
236
|
+
: assignment_expression
|
237
|
+
| expression ',' assignment_expression
|
238
|
+
;
|
239
|
+
|
240
|
+
constant_expression
|
241
|
+
: conditional_expression
|
242
|
+
;
|
243
|
+
|
244
|
+
declaration
|
245
|
+
: declaration_specifiers ';'
|
246
|
+
| declaration_specifiers init_declarator_list ';'
|
247
|
+
;
|
248
|
+
|
249
|
+
declaration_specifiers
|
250
|
+
: storage_class_specifier
|
251
|
+
| storage_class_specifier declaration_specifiers
|
252
|
+
| type_specifier
|
253
|
+
| type_specifier declaration_specifiers
|
254
|
+
| type_qualifier
|
255
|
+
| type_qualifier declaration_specifiers
|
256
|
+
;
|
257
|
+
|
258
|
+
init_declarator_list
|
259
|
+
: init_declarator
|
260
|
+
| init_declarator_list ',' init_declarator
|
261
|
+
;
|
262
|
+
|
263
|
+
init_declarator
|
264
|
+
: declarator
|
265
|
+
| declarator '=' initializer
|
266
|
+
;
|
267
|
+
|
268
|
+
storage_class_specifier
|
269
|
+
: TYPEDEF
|
270
|
+
| EXTERN
|
271
|
+
| STATIC
|
272
|
+
| AUTO
|
273
|
+
| REGISTER
|
274
|
+
;
|
275
|
+
|
276
|
+
type_specifier
|
277
|
+
: VOID
|
278
|
+
| CHAR
|
279
|
+
| SHORT
|
280
|
+
| INT
|
281
|
+
| LONG
|
282
|
+
| FLOAT
|
283
|
+
| DOUBLE
|
284
|
+
| SIGNED
|
285
|
+
| UNSIGNED
|
286
|
+
| struct_or_union_specifier
|
287
|
+
| enum_specifier
|
288
|
+
| TYPE_NAME
|
289
|
+
;
|
290
|
+
|
291
|
+
struct_or_union_specifier
|
292
|
+
: struct_or_union IDENTIFIER '{' struct_declaration_list '}'
|
293
|
+
| struct_or_union '{' struct_declaration_list '}'
|
294
|
+
| struct_or_union IDENTIFIER
|
295
|
+
;
|
296
|
+
|
297
|
+
struct_or_union
|
298
|
+
: STRUCT
|
299
|
+
| UNION
|
300
|
+
;
|
301
|
+
|
302
|
+
struct_declaration_list
|
303
|
+
: struct_declaration
|
304
|
+
| struct_declaration_list struct_declaration
|
305
|
+
;
|
306
|
+
|
307
|
+
struct_declaration
|
308
|
+
: specifier_qualifier_list struct_declarator_list ';'
|
309
|
+
;
|
310
|
+
|
311
|
+
specifier_qualifier_list
|
312
|
+
: type_specifier specifier_qualifier_list
|
313
|
+
| type_specifier
|
314
|
+
| type_qualifier specifier_qualifier_list
|
315
|
+
| type_qualifier
|
316
|
+
;
|
317
|
+
|
318
|
+
struct_declarator_list
|
319
|
+
: struct_declarator
|
320
|
+
| struct_declarator_list ',' struct_declarator
|
321
|
+
;
|
322
|
+
|
323
|
+
struct_declarator
|
324
|
+
: declarator
|
325
|
+
| ':' constant_expression
|
326
|
+
| declarator ':' constant_expression
|
327
|
+
;
|
328
|
+
|
329
|
+
enum_specifier
|
330
|
+
: ENUM '{' enumerator_list '}'
|
331
|
+
| ENUM IDENTIFIER '{' enumerator_list '}'
|
332
|
+
| ENUM IDENTIFIER
|
333
|
+
;
|
334
|
+
|
335
|
+
enumerator_list
|
336
|
+
: enumerator
|
337
|
+
| enumerator_list ',' enumerator
|
338
|
+
;
|
339
|
+
|
340
|
+
enumerator
|
341
|
+
: IDENTIFIER
|
342
|
+
| IDENTIFIER '=' constant_expression
|
343
|
+
;
|
344
|
+
|
345
|
+
type_qualifier
|
346
|
+
: CONST
|
347
|
+
| VOLATILE
|
348
|
+
;
|
349
|
+
|
350
|
+
declarator
|
351
|
+
: pointer direct_declarator
|
352
|
+
| direct_declarator
|
353
|
+
;
|
354
|
+
|
355
|
+
direct_declarator
|
356
|
+
: IDENTIFIER
|
357
|
+
| '(' declarator ')'
|
358
|
+
| direct_declarator '[' constant_expression ']'
|
359
|
+
| direct_declarator '[' ']'
|
360
|
+
| direct_declarator '(' parameter_type_list ')'
|
361
|
+
| direct_declarator '(' identifier_list ')'
|
362
|
+
| direct_declarator '(' ')'
|
363
|
+
;
|
364
|
+
|
365
|
+
pointer
|
366
|
+
: '*'
|
367
|
+
| '*' type_qualifier_list
|
368
|
+
| '*' pointer
|
369
|
+
| '*' type_qualifier_list pointer
|
370
|
+
;
|
371
|
+
|
372
|
+
type_qualifier_list
|
373
|
+
: type_qualifier
|
374
|
+
| type_qualifier_list type_qualifier
|
375
|
+
;
|
376
|
+
|
377
|
+
|
378
|
+
parameter_type_list
|
379
|
+
: parameter_list
|
380
|
+
| parameter_list ',' ELLIPSIS
|
381
|
+
;
|
382
|
+
|
383
|
+
parameter_list
|
384
|
+
: parameter_declaration
|
385
|
+
| parameter_list ',' parameter_declaration
|
386
|
+
;
|
387
|
+
|
388
|
+
parameter_declaration
|
389
|
+
: declaration_specifiers declarator
|
390
|
+
| declaration_specifiers abstract_declarator
|
391
|
+
| declaration_specifiers
|
392
|
+
;
|
393
|
+
|
394
|
+
identifier_list
|
395
|
+
: IDENTIFIER
|
396
|
+
| identifier_list ',' IDENTIFIER
|
397
|
+
;
|
398
|
+
|
399
|
+
type_name
|
400
|
+
: specifier_qualifier_list
|
401
|
+
| specifier_qualifier_list abstract_declarator
|
402
|
+
;
|
403
|
+
|
404
|
+
abstract_declarator
|
405
|
+
: pointer
|
406
|
+
| direct_abstract_declarator
|
407
|
+
| pointer direct_abstract_declarator
|
408
|
+
;
|
409
|
+
|
410
|
+
direct_abstract_declarator
|
411
|
+
: '(' abstract_declarator ')'
|
412
|
+
| '[' ']'
|
413
|
+
| '[' constant_expression ']'
|
414
|
+
| direct_abstract_declarator '[' ']'
|
415
|
+
| direct_abstract_declarator '[' constant_expression ']'
|
416
|
+
| '(' ')'
|
417
|
+
| '(' parameter_type_list ')'
|
418
|
+
| direct_abstract_declarator '(' ')'
|
419
|
+
| direct_abstract_declarator '(' parameter_type_list ')'
|
420
|
+
;
|
421
|
+
|
422
|
+
initializer
|
423
|
+
: assignment_expression
|
424
|
+
| '{' initializer_list '}'
|
425
|
+
| '{' initializer_list ',' '}'
|
426
|
+
;
|
427
|
+
|
428
|
+
initializer_list
|
429
|
+
: initializer
|
430
|
+
| initializer_list ',' initializer
|
431
|
+
;
|
432
|
+
|
433
|
+
statement
|
434
|
+
: labeled_statement
|
435
|
+
| compound_statement
|
436
|
+
| expression_statement
|
437
|
+
| selection_statement
|
438
|
+
| iteration_statement
|
439
|
+
| jump_statement
|
440
|
+
;
|
441
|
+
|
442
|
+
labeled_statement
|
443
|
+
: IDENTIFIER ':' statement
|
444
|
+
| CASE constant_expression ':' statement
|
445
|
+
| DEFAULT ':' statement
|
446
|
+
;
|
447
|
+
|
448
|
+
compound_statement
|
449
|
+
: '{' '}'
|
450
|
+
| '{' statement_list '}'
|
451
|
+
| '{' declaration_list '}'
|
452
|
+
| '{' declaration_list statement_list '}'
|
453
|
+
;
|
454
|
+
|
455
|
+
declaration_list
|
456
|
+
: declaration
|
457
|
+
| declaration_list declaration
|
458
|
+
;
|
459
|
+
|
460
|
+
statement_list
|
461
|
+
: statement
|
462
|
+
| statement_list statement
|
463
|
+
;
|
464
|
+
|
465
|
+
expression_statement
|
466
|
+
: ';'
|
467
|
+
| expression ';'
|
468
|
+
;
|
469
|
+
|
470
|
+
selection_statement
|
471
|
+
: IF '(' expression ')' statement
|
472
|
+
| IF '(' expression ')' statement ELSE statement
|
473
|
+
| SWITCH '(' expression ')' statement
|
474
|
+
;
|
475
|
+
|
476
|
+
iteration_statement
|
477
|
+
: WHILE '(' expression ')' statement
|
478
|
+
| DO statement WHILE '(' expression ')' ';'
|
479
|
+
| FOR '(' expression_statement expression_statement ')' statement
|
480
|
+
| FOR '(' expression_statement expression_statement expression ')' statement
|
481
|
+
;
|
482
|
+
|
483
|
+
jump_statement
|
484
|
+
: GOTO IDENTIFIER ';'
|
485
|
+
| CONTINUE ';'
|
486
|
+
| BREAK ';'
|
487
|
+
| RETURN ';'
|
488
|
+
| RETURN expression ';'
|
489
|
+
;
|
490
|
+
#end-rule
|
491
|
+
%%
|
492
|
+
p = CParser.create_decorated_parser
|
493
|
+
p.parse(STDIN)
|