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.
Files changed (91) hide show
  1. checksums.yaml +7 -0
  2. data/README.en +4 -19
  3. data/README.ja +42 -79
  4. data/bin/depager +42 -45
  5. data/examples/action_pl0d/pl0d.action.dr +421 -0
  6. data/examples/action_pl0d/test.pl0ds +49 -0
  7. data/examples/c89/c89.dr +493 -496
  8. data/examples/c89/test.c89 +10 -10
  9. data/examples/extension/astdf.rb +10 -0
  10. data/examples/extension/atree.dr +55 -0
  11. data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
  12. data/examples/extension/calc.simple_action.dr +33 -0
  13. data/examples/extension/paction.dr +16 -15
  14. data/examples/extension/pactiontest.dr +14 -14
  15. data/examples/extension/simple_action.rb +44 -0
  16. data/examples/pl0d/pl0ds.dr +337 -334
  17. data/examples/pl0d/test.pl0ds +33 -33
  18. data/examples/rie_calc/calc.rie.dr +57 -0
  19. data/examples/rie_calc/test.calc +4 -0
  20. data/examples/rie_dcuse/dcuse.rie.dr +71 -0
  21. data/examples/rie_dcuse/test.dcuse +1 -0
  22. data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
  23. data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
  24. data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
  25. data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
  26. data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
  27. data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
  28. data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
  29. data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
  30. data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
  31. data/examples/rie_pl0/pl0.rie.dr +450 -0
  32. data/examples/rie_pl0/test.pl0 +10 -0
  33. data/examples/sample_calc/calc.action.dr +33 -33
  34. data/examples/sample_calc/calc.ast.action.dr +65 -66
  35. data/examples/sample_calc/calc.ast.dr +55 -55
  36. data/examples/sample_calc/calc.cst.dr +45 -45
  37. data/examples/sample_calc/calc.dr +43 -43
  38. data/examples/sample_calc/calc.lex.dr +29 -29
  39. data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
  40. data/examples/slex_test/divreg.slex.dr +29 -29
  41. data/examples/slex_test/ljoin.slex.dr +36 -36
  42. data/examples/slex_test/test.divreg +1 -1
  43. data/examples/slex_test/test.ljoin +3 -3
  44. data/lib/depager.rb +582 -670
  45. data/lib/depager/grammar.rb +256 -291
  46. data/lib/depager/lr.rb +574 -579
  47. data/lib/depager/parser.rb +282 -277
  48. data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
  49. data/lib/depager/ruby/plugins/action.rb +53 -43
  50. data/lib/depager/ruby/plugins/ast.dr +364 -269
  51. data/lib/depager/ruby/plugins/ast.rb +1367 -1308
  52. data/lib/depager/ruby/plugins/cst.dr +172 -180
  53. data/lib/depager/ruby/plugins/cst.rb +587 -626
  54. data/lib/depager/ruby/plugins/lex.dr +85 -89
  55. data/lib/depager/ruby/plugins/lex.rb +310 -336
  56. data/lib/depager/ruby/plugins/rie.dr +723 -0
  57. data/lib/depager/ruby/plugins/rie.rb +1653 -0
  58. data/lib/depager/ruby/plugins/slex.dr +202 -200
  59. data/lib/depager/ruby/plugins/slex.rb +780 -817
  60. data/lib/depager/ruby/plugins/srp.rb +56 -51
  61. data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
  62. data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
  63. data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
  64. data/lib/depager/utils.rb +148 -318
  65. data/lib/depager/version.rb +4 -3
  66. metadata +52 -60
  67. data/ChangeLog +0 -16
  68. data/data/depager/pre-setup.rb +0 -3
  69. data/examples/c89/c89.tab.rb +0 -7127
  70. data/examples/pl0d/pl0ds.tab.rb +0 -2698
  71. data/examples/sample_calc/calc.action.tab.rb +0 -457
  72. data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
  73. data/examples/sample_calc/calc.ast.tab.rb +0 -665
  74. data/examples/sample_calc/calc.astdf.dr +0 -54
  75. data/examples/sample_calc/calc.astdf.tab.rb +0 -672
  76. data/examples/sample_calc/calc.atree.tab.rb +0 -451
  77. data/examples/sample_calc/calc.cst.tab.rb +0 -644
  78. data/examples/sample_calc/calc.lex.tab.rb +0 -374
  79. data/examples/sample_calc/calc.nvaction.dr +0 -33
  80. data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
  81. data/examples/sample_calc/calc.tab.rb +0 -365
  82. data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
  83. data/examples/slex_test/divreg.slex.tab.rb +0 -303
  84. data/examples/slex_test/ljoin.slex.tab.rb +0 -370
  85. data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
  86. data/lib/depager/ruby/plugins/astdf.rb +0 -6
  87. data/lib/depager/ruby/plugins/atree.dr +0 -55
  88. data/lib/depager/ruby/plugins/atree.rb +0 -347
  89. data/lib/depager/ruby/plugins/nvaction.rb +0 -19
  90. data/lib/depager/ruby/templates/simple.erb +0 -23
  91. data/setup.rb +0 -1585
@@ -1,457 +0,0 @@
1
-
2
- begin; require 'rubygems'; rescue Exception; end
3
- require 'depager/parser.rb'
4
-
5
-
6
- module Depager::DecoratorUtils; end
7
- module D4TinyCalc; end
8
-
9
- class TinyCalc < Depager::LALR::Basis
10
-
11
-
12
- ### Reduce Table
13
- reduce_table = [
14
- [ -1, 1 ], # ( 0) $start : expr
15
- [ 0, 3 ], # ( 1) expr : expr '+' term
16
- [ 0, 3 ], # ( 2) expr : expr '-' term
17
- [ 0, 1 ], # ( 3) expr : term
18
- [ 1, 3 ], # ( 4) term : term '*' fact
19
- [ 1, 3 ], # ( 5) term : term '/' fact
20
- [ 1, 1 ], # ( 6) term : fact
21
- [ 2, 1 ], # ( 7) fact : NUM
22
- [ 2, 3 ], # ( 8) fact : '(' expr ')'
23
- ]
24
- ### Extension Params
25
- nparams = {
26
- 'Action' => 2,
27
- }
28
- ### Term to Int
29
- t2i = {
30
- nil => 0,
31
- false => 1,
32
- "+" => 2,
33
- "-" => 3,
34
- "*" => 4,
35
- "/" => 5,
36
- :NUM => 6,
37
- "(" => 7,
38
- ")" => 8,
39
- }
40
- ### Int to Term
41
- i2t = [
42
- nil,
43
- false,
44
- "+",
45
- "-",
46
- "*",
47
- "/",
48
- :NUM,
49
- "(",
50
- ")",
51
- ]
52
- ### Action Table
53
- action_table = [
54
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
55
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
56
- [ ACC, nil, 7, 8, nil, nil, nil, nil, nil, ],
57
- [ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
58
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
59
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
60
- [ nil, nil, 7, 8, nil, nil, nil, nil, 11, ],
61
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
62
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
63
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
64
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
65
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
66
- [ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
67
- [ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
68
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
69
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
70
- ]
71
- ### Default Reduce Table
72
- defred_table = [
73
- nil,
74
- nil,
75
- nil,
76
- -3,
77
- -6,
78
- -7,
79
- nil,
80
- nil,
81
- nil,
82
- nil,
83
- nil,
84
- -8,
85
- -1,
86
- -2,
87
- -4,
88
- -5,
89
- ]
90
- defred_after_shift_table = [
91
- nil,
92
- nil,
93
- nil,
94
- nil,
95
- -6,
96
- -7,
97
- nil,
98
- nil,
99
- nil,
100
- nil,
101
- nil,
102
- -8,
103
- nil,
104
- nil,
105
- -4,
106
- -5,
107
- ]
108
- ### Nonterm to Int
109
- nt2i = {
110
- :expr => 0,
111
- :term => 1,
112
- :fact => 2,
113
- }
114
- ### Int to Nonterm
115
- i2nt = [
116
- :expr,
117
- :term,
118
- :fact,
119
- ]
120
- ### Goto Table
121
- goto_table = [
122
- [ 2, 3, 4, ],
123
- [ 6, 3, 4, ],
124
- [ nil, nil, nil, ],
125
- [ nil, nil, nil, ],
126
- [ nil, nil, nil, ],
127
- [ nil, nil, nil, ],
128
- [ nil, nil, nil, ],
129
- [ nil, 12, 4, ],
130
- [ nil, 13, 4, ],
131
- [ nil, nil, 14, ],
132
- [ nil, nil, 15, ],
133
- [ nil, nil, nil, ],
134
- [ nil, nil, nil, ],
135
- [ nil, nil, nil, ],
136
- [ nil, nil, nil, ],
137
- [ nil, nil, nil, ],
138
- ]
139
-
140
-
141
- alias orig_error error
142
- def error
143
- orig_error
144
- warn "current state: #{StateInfo[@stack.last]}"
145
- end
146
-
147
- ### States
148
- StateInfo = [
149
- <<'----------',
150
- I000 =
151
- ( 0) $start : _ expr
152
-
153
- NUM shift, and goto to state 5
154
- '(' shift, and goto to state 1
155
-
156
-
157
- ----------
158
-
159
- <<'----------',
160
- I001 =
161
- ( 8) fact : '(' _ expr ')'
162
-
163
- NUM shift, and goto to state 5
164
- '(' shift, and goto to state 1
165
-
166
-
167
- ----------
168
-
169
- <<'----------',
170
- I002 =
171
- ( 0) $start : expr _
172
- ( 1) expr : expr _ '+' term
173
- ( 2) expr : expr _ '-' term
174
-
175
- '+' shift, and goto to state 7
176
- '-' shift, and goto to state 8
177
-
178
-
179
- $end accept
180
-
181
- ----------
182
-
183
- <<'----------',
184
- I003 =
185
- ( 3) expr : term _
186
- ( 4) term : term _ '*' fact
187
- ( 5) term : term _ '/' fact
188
-
189
- '*' shift, and goto to state 9
190
- '/' shift, and goto to state 10
191
-
192
- $default reduce using rule 3 (expr)
193
-
194
- ----------
195
-
196
- <<'----------',
197
- I004 =
198
- ( 6) term : fact _
199
-
200
-
201
- $default reduce using rule 6 (term) [after shift]
202
-
203
- ----------
204
-
205
- <<'----------',
206
- I005 =
207
- ( 7) fact : NUM _
208
-
209
-
210
- $default reduce using rule 7 (fact) [after shift]
211
-
212
- ----------
213
-
214
- <<'----------',
215
- I006 =
216
- ( 8) fact : '(' expr _ ')'
217
- ( 1) expr : expr _ '+' term
218
- ( 2) expr : expr _ '-' term
219
-
220
- '+' shift, and goto to state 7
221
- '-' shift, and goto to state 8
222
- ')' shift, and goto to state 11
223
-
224
-
225
- ----------
226
-
227
- <<'----------',
228
- I007 =
229
- ( 1) expr : expr '+' _ term
230
-
231
- NUM shift, and goto to state 5
232
- '(' shift, and goto to state 1
233
-
234
-
235
- ----------
236
-
237
- <<'----------',
238
- I008 =
239
- ( 2) expr : expr '-' _ term
240
-
241
- NUM shift, and goto to state 5
242
- '(' shift, and goto to state 1
243
-
244
-
245
- ----------
246
-
247
- <<'----------',
248
- I009 =
249
- ( 4) term : term '*' _ fact
250
-
251
- NUM shift, and goto to state 5
252
- '(' shift, and goto to state 1
253
-
254
-
255
- ----------
256
-
257
- <<'----------',
258
- I010 =
259
- ( 5) term : term '/' _ fact
260
-
261
- NUM shift, and goto to state 5
262
- '(' shift, and goto to state 1
263
-
264
-
265
- ----------
266
-
267
- <<'----------',
268
- I011 =
269
- ( 8) fact : '(' expr ')' _
270
-
271
-
272
- $default reduce using rule 8 (fact) [after shift]
273
-
274
- ----------
275
-
276
- <<'----------',
277
- I012 =
278
- ( 1) expr : expr '+' term _
279
- ( 4) term : term _ '*' fact
280
- ( 5) term : term _ '/' fact
281
-
282
- '*' shift, and goto to state 9
283
- '/' shift, and goto to state 10
284
-
285
- $default reduce using rule 1 (expr)
286
-
287
- ----------
288
-
289
- <<'----------',
290
- I013 =
291
- ( 2) expr : expr '-' term _
292
- ( 4) term : term _ '*' fact
293
- ( 5) term : term _ '/' fact
294
-
295
- '*' shift, and goto to state 9
296
- '/' shift, and goto to state 10
297
-
298
- $default reduce using rule 2 (expr)
299
-
300
- ----------
301
-
302
- <<'----------',
303
- I014 =
304
- ( 4) term : term '*' fact _
305
-
306
-
307
- $default reduce using rule 4 (term) [after shift]
308
-
309
- ----------
310
-
311
- <<'----------',
312
- I015 =
313
- ( 5) term : term '/' fact _
314
-
315
-
316
- $default reduce using rule 5 (term) [after shift]
317
-
318
- ----------
319
- ]
320
-
321
-
322
- Tables = [ reduce_table, nparams, action_table,
323
- defred_table, defred_after_shift_table, goto_table,
324
- t2i, i2t, nt2i, i2nt ]
325
-
326
- def self.createDecoratedParser
327
- D4TinyCalc::Action.new(TinyCalc.new())
328
- end
329
-
330
- ### Inner Code
331
-
332
- def lex
333
- begin
334
- until @line.empty?
335
- case @line
336
-
337
- when /\A\s+/, /\A\#.*/
338
- @oldline = @line; @line = $'
339
-
340
-
341
-
342
- when /\A[1-9][0-9]*/
343
- @oldline = @line; @line = $'
344
- yield token(:NUM, $&.to_i)
345
-
346
-
347
- when /\A./
348
- @oldline = @line; @line = $'
349
- yield token($&, $&)
350
-
351
-
352
- else
353
- raise RuntimeError, "must not happen #{@line}"
354
- end
355
- end
356
- end while @line0 = @line = getline
357
- yield nil, nil
358
- end
359
-
360
- end
361
-
362
- ### Outer Code
363
-
364
- class D4TinyCalc::Action < Depager::LALR::Action #:nodoc:all
365
- include Depager::DecoratorUtils
366
-
367
- on_reduce = [
368
- nil,
369
- :_act_0,
370
- :_act_1,
371
- :_act_2,
372
- :_act_3,
373
- :_act_4,
374
- :_act_5,
375
- :_act_6,
376
- :_act_7,
377
-
378
- ]
379
- Tables = [on_reduce]
380
- def initialize inside
381
- super inside, 'Action'
382
- @on_reduce, = self.class::Tables
383
- init_parser
384
- end
385
-
386
-
387
- module_eval <<-'.,.,122745803834649.,.,', 'sample_calc/calc.action.dr', 15
388
- def _act_0 val
389
- val[0] + val[2]
390
-
391
- end
392
- .,.,122745803834649.,.,
393
-
394
- module_eval <<-'.,.,12274580381706.,.,', 'sample_calc/calc.action.dr', 16
395
- def _act_1 val
396
- val[0] - val[2]
397
-
398
- end
399
- .,.,12274580381706.,.,
400
-
401
- module_eval <<-'.,.,122745803826799.,.,', 'sample_calc/calc.action.dr', 17
402
- def _act_2 val
403
- val[0]
404
-
405
- end
406
- .,.,122745803826799.,.,
407
-
408
- module_eval <<-'.,.,122745803847781.,.,', 'sample_calc/calc.action.dr', 20
409
- def _act_3 val
410
- val[0] * val[2]
411
-
412
- end
413
- .,.,122745803847781.,.,
414
-
415
- module_eval <<-'.,.,122745803847492.,.,', 'sample_calc/calc.action.dr', 21
416
- def _act_4 val
417
- val[0] / val[2]
418
-
419
- end
420
- .,.,122745803847492.,.,
421
-
422
- module_eval <<-'.,.,12274580382355.,.,', 'sample_calc/calc.action.dr', 22
423
- def _act_5 val
424
- val[0]
425
-
426
- end
427
- .,.,12274580382355.,.,
428
-
429
- module_eval <<-'.,.,122745803838328.,.,', 'sample_calc/calc.action.dr', 25
430
- def _act_6 val
431
- val[0].value
432
-
433
- end
434
- .,.,122745803838328.,.,
435
-
436
- module_eval <<-'.,.,122745803830249.,.,', 'sample_calc/calc.action.dr', 26
437
- def _act_7 val
438
- val[1]
439
-
440
- end
441
- .,.,122745803830249.,.,
442
-
443
- end
444
-
445
-
446
- def createDecoratedTinyCalc
447
- D4TinyCalc::Action.new(TinyCalc.new())
448
- end
449
-
450
- ### main
451
- if __FILE__ == $0
452
- ### Main Code
453
- parser = TinyCalc::createDecoratedParser
454
- r, = parser.parse(STDIN)
455
- puts r
456
-
457
- end