depager 0.2.3 → 0.3.0.b20250423

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +44 -0
  3. data/.simplecov +5 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE.gpl +339 -0
  6. data/Manifest.txt +73 -0
  7. data/README.en +7 -21
  8. data/README.ja +19 -99
  9. data/Rakefile +31 -0
  10. data/bin/depager +7 -45
  11. data/examples/action_pl0d/pl0d.action.dr +421 -0
  12. data/examples/action_pl0d/test.pl0ds +48 -0
  13. data/examples/c89/c89.dr +493 -496
  14. data/examples/c89/test.c89 +10 -10
  15. data/examples/extension/astdf.rb +9 -0
  16. data/examples/extension/atree.dr +55 -0
  17. data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
  18. data/examples/{sample_calc/calc.action.dr → extension/calc.simple_action.dr} +33 -33
  19. data/examples/extension/paction.dr +16 -15
  20. data/examples/extension/pactiontest.dr +14 -14
  21. data/examples/extension/simple_action.rb +46 -0
  22. data/examples/pl0d/pl0ds.dr +337 -334
  23. data/examples/pl0d/test.pl0ds +33 -33
  24. data/examples/rie_calc/calc.rie.dr +57 -0
  25. data/examples/rie_calc/test.calc +4 -0
  26. data/examples/rie_dcuse/dcuse.rie.dr +71 -0
  27. data/examples/rie_dcuse/test.dcuse +1 -0
  28. data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
  29. data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
  30. data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
  31. data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
  32. data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
  33. data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
  34. data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
  35. data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
  36. data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
  37. data/examples/rie_pl0/pl0.rie.dr +450 -0
  38. data/examples/rie_pl0/test.pl0 +10 -0
  39. data/examples/slex_test/divreg.slex.dr +29 -29
  40. data/examples/slex_test/ljoin.slex.dr +36 -36
  41. data/examples/slex_test/test.divreg +1 -1
  42. data/examples/slex_test/test.ljoin +3 -3
  43. data/examples/{sample_calc/calc.nvaction.dr → tiny_calc/calc.action.dr} +33 -33
  44. data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +76 -66
  45. data/examples/{sample_calc → tiny_calc}/calc.ast.dr +67 -55
  46. data/examples/tiny_calc/calc.cst.dr +50 -0
  47. data/examples/{sample_calc → tiny_calc}/calc.dr +43 -43
  48. data/examples/{sample_calc → tiny_calc}/calc.lex.dr +29 -29
  49. data/examples/{sample_calc/calc_prec.nvaction.dr → tiny_calc/calc_prec.action.dr} +31 -31
  50. data/lib/depager/cli.rb +44 -0
  51. data/lib/depager/grammar.rb +253 -291
  52. data/lib/depager/lr.rb +589 -579
  53. data/lib/depager/parser.rb +269 -277
  54. data/lib/depager/plugins/_rie_debug.rb +63 -0
  55. data/lib/depager/plugins/action.rb +47 -0
  56. data/lib/depager/plugins/ast.dr +367 -0
  57. data/lib/depager/plugins/ast.rb +1329 -0
  58. data/lib/depager/{ruby/plugins → plugins}/cst.dr +174 -180
  59. data/lib/depager/plugins/cst.rb +591 -0
  60. data/lib/depager/{ruby/plugins → plugins}/lex.dr +85 -89
  61. data/lib/depager/plugins/lex.rb +313 -0
  62. data/lib/depager/plugins/rie.dr +725 -0
  63. data/lib/depager/plugins/rie.rb +1614 -0
  64. data/lib/depager/{ruby/plugins → plugins}/slex.dr +201 -200
  65. data/lib/depager/plugins/slex.rb +769 -0
  66. data/lib/depager/plugins/srp.rb +46 -0
  67. data/lib/depager/ruby/templates/extension_lalr_master.erb +40 -51
  68. data/lib/depager/ruby/templates/extension_lalr_slave.erb +113 -107
  69. data/lib/depager/ruby/templates/single_lalr_parser.erb +124 -117
  70. data/lib/depager/utils.rb +158 -318
  71. data/lib/depager/version.rb +3 -3
  72. data/lib/depager.rb +572 -670
  73. metadata +77 -80
  74. data/ChangeLog +0 -16
  75. data/data/depager/pre-setup.rb +0 -3
  76. data/examples/c89/c89.tab.rb +0 -7127
  77. data/examples/pl0d/pl0ds.tab.rb +0 -2698
  78. data/examples/sample_calc/calc.action.tab.rb +0 -457
  79. data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
  80. data/examples/sample_calc/calc.ast.tab.rb +0 -665
  81. data/examples/sample_calc/calc.astdf.dr +0 -54
  82. data/examples/sample_calc/calc.astdf.tab.rb +0 -672
  83. data/examples/sample_calc/calc.atree.tab.rb +0 -451
  84. data/examples/sample_calc/calc.cst.dr +0 -45
  85. data/examples/sample_calc/calc.cst.tab.rb +0 -644
  86. data/examples/sample_calc/calc.lex.tab.rb +0 -374
  87. data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
  88. data/examples/sample_calc/calc.tab.rb +0 -365
  89. data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
  90. data/examples/slex_test/divreg.slex.tab.rb +0 -303
  91. data/examples/slex_test/ljoin.slex.tab.rb +0 -370
  92. data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
  93. data/lib/depager/ruby/plugins/action.rb +0 -43
  94. data/lib/depager/ruby/plugins/ast.dr +0 -269
  95. data/lib/depager/ruby/plugins/ast.rb +0 -1308
  96. data/lib/depager/ruby/plugins/astdf.rb +0 -6
  97. data/lib/depager/ruby/plugins/atree.dr +0 -55
  98. data/lib/depager/ruby/plugins/atree.rb +0 -347
  99. data/lib/depager/ruby/plugins/cst.rb +0 -626
  100. data/lib/depager/ruby/plugins/lex.rb +0 -336
  101. data/lib/depager/ruby/plugins/nvaction.rb +0 -19
  102. data/lib/depager/ruby/plugins/slex.rb +0 -817
  103. data/lib/depager/ruby/plugins/srp.rb +0 -51
  104. data/lib/depager/ruby/templates/simple.erb +0 -23
  105. data/setup.rb +0 -1585
  106. /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
@@ -1,465 +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
- 'NVAction' => 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::NVAction.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::NVAction < 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, 'NVAction'
382
- @on_reduce, = self.class::Tables
383
- init_parser
384
- end
385
-
386
-
387
- module_eval <<-'.,.,122745803961572.,.,', 'sample_calc/calc.nvaction.dr', 14
388
- def _act_0 val
389
- _expr, _, _term, = *val
390
- _expr + _term
391
-
392
- end
393
- .,.,122745803961572.,.,
394
-
395
- module_eval <<-'.,.,122745803917671.,.,', 'sample_calc/calc.nvaction.dr', 15
396
- def _act_1 val
397
- _expr, _, _term, = *val
398
- _expr - _term
399
-
400
- end
401
- .,.,122745803917671.,.,
402
-
403
- module_eval <<-'.,.,12274580397247.,.,', 'sample_calc/calc.nvaction.dr', 16
404
- def _act_2 val
405
- _term, = *val
406
- _term
407
-
408
- end
409
- .,.,12274580397247.,.,
410
-
411
- module_eval <<-'.,.,122745803926497.,.,', 'sample_calc/calc.nvaction.dr', 19
412
- def _act_3 val
413
- _term, _, _fact, = *val
414
- _term * _fact
415
-
416
- end
417
- .,.,122745803926497.,.,
418
-
419
- module_eval <<-'.,.,122745803919971.,.,', 'sample_calc/calc.nvaction.dr', 20
420
- def _act_4 val
421
- _term, _, _fact, = *val
422
- _term / _fact
423
-
424
- end
425
- .,.,122745803919971.,.,
426
-
427
- module_eval <<-'.,.,122745803920937.,.,', 'sample_calc/calc.nvaction.dr', 21
428
- def _act_5 val
429
- _fact, = *val
430
- _fact
431
-
432
- end
433
- .,.,122745803920937.,.,
434
-
435
- module_eval <<-'.,.,122745803940791.,.,', 'sample_calc/calc.nvaction.dr', 24
436
- def _act_6 val
437
- _NUM, = *val
438
- _NUM.value
439
-
440
- end
441
- .,.,122745803940791.,.,
442
-
443
- module_eval <<-'.,.,122745803911472.,.,', 'sample_calc/calc.nvaction.dr', 25
444
- def _act_7 val
445
- _, _expr, _, = *val
446
- _expr
447
-
448
- end
449
- .,.,122745803911472.,.,
450
-
451
- end
452
-
453
-
454
- def createDecoratedTinyCalc
455
- D4TinyCalc::NVAction.new(TinyCalc.new())
456
- end
457
-
458
- ### main
459
- if __FILE__ == $0
460
- ### Main Code
461
- parser = createDecoratedTinyCalc
462
- r, = parser.parse(STDIN)
463
- puts r
464
-
465
- end