depager 0.2.3 → 0.3.0.b20160729

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 (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,451 +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
- include Depager
12
-
13
- ### Reduce Table
14
- reduce_table = [
15
- [ -1, 1 ], # ( 0) $start : expr
16
- [ 0, 3 ], # ( 1) expr : expr '+' term
17
- [ 0, 3 ], # ( 2) expr : expr '-' term
18
- [ 0, 1 ], # ( 3) expr : term
19
- [ 1, 3 ], # ( 4) term : term '*' fact
20
- [ 1, 3 ], # ( 5) term : term '/' fact
21
- [ 1, 1 ], # ( 6) term : fact
22
- [ 2, 1 ], # ( 7) fact : NUM
23
- [ 2, 3 ], # ( 8) fact : '(' expr ')'
24
- ]
25
- ### Extension Params
26
- nparams = {
27
- 'ATreeBuilder' => 2,
28
- }
29
- ### Term to Int
30
- t2i = {
31
- nil => 0,
32
- false => 1,
33
- "+" => 2,
34
- "-" => 3,
35
- "*" => 4,
36
- "/" => 5,
37
- :NUM => 6,
38
- "(" => 7,
39
- ")" => 8,
40
- }
41
- ### Int to Term
42
- i2t = [
43
- nil,
44
- false,
45
- "+",
46
- "-",
47
- "*",
48
- "/",
49
- :NUM,
50
- "(",
51
- ")",
52
- ]
53
- ### Action Table
54
- action_table = [
55
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
56
- [ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
57
- [ ACC, nil, 7, 8, nil, nil, nil, nil, nil, ],
58
- [ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
59
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
60
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
61
- [ nil, nil, 7, 8, nil, nil, nil, nil, 11, ],
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, 5, 1, nil, ],
66
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
67
- [ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
68
- [ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
69
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
70
- [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
71
- ]
72
- ### Default Reduce Table
73
- defred_table = [
74
- nil,
75
- nil,
76
- nil,
77
- -3,
78
- -6,
79
- -7,
80
- nil,
81
- nil,
82
- nil,
83
- nil,
84
- nil,
85
- -8,
86
- -1,
87
- -2,
88
- -4,
89
- -5,
90
- ]
91
- defred_after_shift_table = [
92
- nil,
93
- nil,
94
- nil,
95
- nil,
96
- -6,
97
- -7,
98
- nil,
99
- nil,
100
- nil,
101
- nil,
102
- nil,
103
- -8,
104
- nil,
105
- nil,
106
- -4,
107
- -5,
108
- ]
109
- ### Nonterm to Int
110
- nt2i = {
111
- :expr => 0,
112
- :term => 1,
113
- :fact => 2,
114
- }
115
- ### Int to Nonterm
116
- i2nt = [
117
- :expr,
118
- :term,
119
- :fact,
120
- ]
121
- ### Goto Table
122
- goto_table = [
123
- [ 2, 3, 4, ],
124
- [ 6, 3, 4, ],
125
- [ nil, nil, nil, ],
126
- [ nil, nil, nil, ],
127
- [ nil, nil, nil, ],
128
- [ nil, nil, nil, ],
129
- [ nil, nil, nil, ],
130
- [ nil, 12, 4, ],
131
- [ nil, 13, 4, ],
132
- [ nil, nil, 14, ],
133
- [ nil, nil, 15, ],
134
- [ nil, nil, nil, ],
135
- [ nil, nil, nil, ],
136
- [ nil, nil, nil, ],
137
- [ nil, nil, nil, ],
138
- [ nil, nil, nil, ],
139
- ]
140
-
141
-
142
- alias orig_error error
143
- def error
144
- orig_error
145
- warn "current state: #{StateInfo[@stack.last]}"
146
- end
147
-
148
- ### States
149
- StateInfo = [
150
- <<'----------',
151
- I000 =
152
- ( 0) $start : _ expr
153
-
154
- NUM shift, and goto to state 5
155
- '(' shift, and goto to state 1
156
-
157
-
158
- ----------
159
-
160
- <<'----------',
161
- I001 =
162
- ( 8) fact : '(' _ expr ')'
163
-
164
- NUM shift, and goto to state 5
165
- '(' shift, and goto to state 1
166
-
167
-
168
- ----------
169
-
170
- <<'----------',
171
- I002 =
172
- ( 0) $start : expr _
173
- ( 1) expr : expr _ '+' term
174
- ( 2) expr : expr _ '-' term
175
-
176
- '+' shift, and goto to state 7
177
- '-' shift, and goto to state 8
178
-
179
-
180
- $end accept
181
-
182
- ----------
183
-
184
- <<'----------',
185
- I003 =
186
- ( 3) expr : term _
187
- ( 4) term : term _ '*' fact
188
- ( 5) term : term _ '/' fact
189
-
190
- '*' shift, and goto to state 9
191
- '/' shift, and goto to state 10
192
-
193
- $default reduce using rule 3 (expr)
194
-
195
- ----------
196
-
197
- <<'----------',
198
- I004 =
199
- ( 6) term : fact _
200
-
201
-
202
- $default reduce using rule 6 (term) [after shift]
203
-
204
- ----------
205
-
206
- <<'----------',
207
- I005 =
208
- ( 7) fact : NUM _
209
-
210
-
211
- $default reduce using rule 7 (fact) [after shift]
212
-
213
- ----------
214
-
215
- <<'----------',
216
- I006 =
217
- ( 8) fact : '(' expr _ ')'
218
- ( 1) expr : expr _ '+' term
219
- ( 2) expr : expr _ '-' term
220
-
221
- '+' shift, and goto to state 7
222
- '-' shift, and goto to state 8
223
- ')' shift, and goto to state 11
224
-
225
-
226
- ----------
227
-
228
- <<'----------',
229
- I007 =
230
- ( 1) expr : expr '+' _ term
231
-
232
- NUM shift, and goto to state 5
233
- '(' shift, and goto to state 1
234
-
235
-
236
- ----------
237
-
238
- <<'----------',
239
- I008 =
240
- ( 2) expr : expr '-' _ term
241
-
242
- NUM shift, and goto to state 5
243
- '(' shift, and goto to state 1
244
-
245
-
246
- ----------
247
-
248
- <<'----------',
249
- I009 =
250
- ( 4) term : term '*' _ fact
251
-
252
- NUM shift, and goto to state 5
253
- '(' shift, and goto to state 1
254
-
255
-
256
- ----------
257
-
258
- <<'----------',
259
- I010 =
260
- ( 5) term : term '/' _ fact
261
-
262
- NUM shift, and goto to state 5
263
- '(' shift, and goto to state 1
264
-
265
-
266
- ----------
267
-
268
- <<'----------',
269
- I011 =
270
- ( 8) fact : '(' expr ')' _
271
-
272
-
273
- $default reduce using rule 8 (fact) [after shift]
274
-
275
- ----------
276
-
277
- <<'----------',
278
- I012 =
279
- ( 1) expr : expr '+' term _
280
- ( 4) term : term _ '*' fact
281
- ( 5) term : term _ '/' fact
282
-
283
- '*' shift, and goto to state 9
284
- '/' shift, and goto to state 10
285
-
286
- $default reduce using rule 1 (expr)
287
-
288
- ----------
289
-
290
- <<'----------',
291
- I013 =
292
- ( 2) expr : expr '-' term _
293
- ( 4) term : term _ '*' fact
294
- ( 5) term : term _ '/' fact
295
-
296
- '*' shift, and goto to state 9
297
- '/' shift, and goto to state 10
298
-
299
- $default reduce using rule 2 (expr)
300
-
301
- ----------
302
-
303
- <<'----------',
304
- I014 =
305
- ( 4) term : term '*' fact _
306
-
307
-
308
- $default reduce using rule 4 (term) [after shift]
309
-
310
- ----------
311
-
312
- <<'----------',
313
- I015 =
314
- ( 5) term : term '/' fact _
315
-
316
-
317
- $default reduce using rule 5 (term) [after shift]
318
-
319
- ----------
320
- ]
321
-
322
-
323
- Tables = [ reduce_table, nparams, action_table,
324
- defred_table, defred_after_shift_table, goto_table,
325
- t2i, i2t, nt2i, i2nt ]
326
-
327
- def self.createDecoratedParser
328
- D4TinyCalc::ATreeBuilder.new(TinyCalc.new())
329
- end
330
-
331
- ### Inner Code
332
-
333
- def lex
334
- begin
335
- until @line.empty?
336
- case @line
337
-
338
- when /\A\s+/, /\A\#.*/
339
- @oldline = @line; @line = $'
340
-
341
-
342
-
343
- when /\A[1-9][0-9]*/
344
- @oldline = @line; @line = $'
345
- yield token(:NUM, $&.to_i)
346
-
347
-
348
- when /\A./
349
- @oldline = @line; @line = $'
350
- yield token($&, $&)
351
-
352
-
353
- else
354
- raise RuntimeError, "must not happen #{@line}"
355
- end
356
- end
357
- end while @line0 = @line = getline
358
- yield nil, nil
359
- end
360
-
361
- end
362
-
363
- ### Outer Code
364
-
365
- class D4TinyCalc::ATreeBuilder < Depager::LALR::Action #:nodoc:all
366
- include Depager::DecoratorUtils
367
-
368
- on_reduce = [
369
- nil,
370
- :_atree_0,
371
- :_atree_1,
372
- :_atree_2,
373
- :_atree_3,
374
- :_atree_4,
375
- :_atree_5,
376
- :_atree_6,
377
- :_atree_7,
378
-
379
- ]
380
- Tables = [on_reduce]
381
- def initialize inside
382
- super inside, 'ATreeBuilder'
383
- @on_reduce, = self.class::Tables
384
- init_parser
385
- end
386
-
387
-
388
- module_eval <<-'.,.,122745803830157.,.,', 'sample_calc/calc.atree.dr', 17
389
- def _atree_0 val
390
- [:add, val[0],val[2]]
391
- end
392
- .,.,122745803830157.,.,
393
-
394
- module_eval <<-'.,.,122745803819966.,.,', 'sample_calc/calc.atree.dr', 19
395
- def _atree_1 val
396
- [:sub, val[0],val[2]]
397
- end
398
- .,.,122745803819966.,.,
399
-
400
- module_eval <<-'.,.,122745803811215.,.,', 'sample_calc/calc.atree.dr', 21
401
- def _atree_2 val
402
- val[0]
403
- end
404
- .,.,122745803811215.,.,
405
-
406
- module_eval <<-'.,.,122745803854915.,.,', 'sample_calc/calc.atree.dr', 25
407
- def _atree_3 val
408
- [:mul, val[0],val[2]]
409
- end
410
- .,.,122745803854915.,.,
411
-
412
- module_eval <<-'.,.,12274580384152.,.,', 'sample_calc/calc.atree.dr', 27
413
- def _atree_4 val
414
- [:div, val[0],val[2]]
415
- end
416
- .,.,12274580384152.,.,
417
-
418
- module_eval <<-'.,.,122745803842692.,.,', 'sample_calc/calc.atree.dr', 29
419
- def _atree_5 val
420
- val[0]
421
- end
422
- .,.,122745803842692.,.,
423
-
424
- module_eval <<-'.,.,122745803834536.,.,', 'sample_calc/calc.atree.dr', 33
425
- def _atree_6 val
426
- [:literal, val[0]]
427
- end
428
- .,.,122745803834536.,.,
429
-
430
- module_eval <<-'.,.,122745803843700.,.,', 'sample_calc/calc.atree.dr', 35
431
- def _atree_7 val
432
- val[1]
433
- end
434
- .,.,122745803843700.,.,
435
-
436
- end
437
-
438
-
439
- def createDecoratedTinyCalc
440
- D4TinyCalc::ATreeBuilder.new(TinyCalc.new())
441
- end
442
-
443
- ### main
444
- if __FILE__ == $0
445
- ### Main Code
446
- require 'pp'
447
- parser = createDecoratedTinyCalc
448
- r, = parser.parse(STDIN)
449
- pp r
450
-
451
- end
@@ -1,644 +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
- 'CSTBuilder' => 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::CSTBuilder.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 Node
365
- def accept
366
- end
367
- end
368
-
369
- class Visitor
370
-
371
- module_eval <<-'.,.,122745803928929.,.,', 'sample_calc/calc.cst.dr', 23
372
- def visit_Node_expr_0 node
373
- node.value = node.expr.value + node.term.value
374
-
375
- end
376
- .,.,122745803928929.,.,
377
-
378
- module_eval <<-'.,.,12274580395023.,.,', 'sample_calc/calc.cst.dr', 24
379
- def visit_Node_expr_1 node
380
- node.value = node.expr.value + node.term.value
381
-
382
- end
383
- .,.,12274580395023.,.,
384
-
385
- module_eval <<-'.,.,12274580391475.,.,', 'sample_calc/calc.cst.dr', 25
386
- def visit_Node_expr_2 node
387
- node.value = node.term.value
388
-
389
- end
390
- .,.,12274580391475.,.,
391
-
392
- module_eval <<-'.,.,122745803963610.,.,', 'sample_calc/calc.cst.dr', 28
393
- def visit_Node_term_0 node
394
- node.value = node.term.value * node.fact.value
395
-
396
- end
397
- .,.,122745803963610.,.,
398
-
399
- module_eval <<-'.,.,122745803936130.,.,', 'sample_calc/calc.cst.dr', 29
400
- def visit_Node_term_1 node
401
- node.value = node.term.value / node.fact.value
402
-
403
- end
404
- .,.,122745803936130.,.,
405
-
406
- module_eval <<-'.,.,122745803926151.,.,', 'sample_calc/calc.cst.dr', 30
407
- def visit_Node_term_2 node
408
- node.value = node.fact.value
409
-
410
- end
411
- .,.,122745803926151.,.,
412
-
413
- module_eval <<-'.,.,122745803911098.,.,', 'sample_calc/calc.cst.dr', 33
414
- def visit_Node_fact_0 node
415
- node.value = node.num.value
416
-
417
- end
418
- .,.,122745803911098.,.,
419
-
420
- module_eval <<-'.,.,122745803942330.,.,', 'sample_calc/calc.cst.dr', 34
421
- def visit_Node_fact_1 node
422
- node.value = node.expr
423
-
424
- end
425
- .,.,122745803942330.,.,
426
-
427
- end
428
-
429
- class Node
430
-
431
- attr_accessor :value
432
- def initialize
433
- @value = nil
434
- end
435
-
436
- end
437
- class Visitor
438
-
439
- end
440
-
441
- class Node_expr < Node
442
- def initialize
443
- super()
444
- end
445
- end
446
-
447
- class Node_expr_0 < Node_expr
448
- attr_accessor :expr, :tx2b, :term
449
- def initialize expr, tx2b, term
450
- super()
451
- @expr = expr; @tx2b = tx2b; @term = term
452
- end
453
- def accept v
454
- expr.accept(v); term.accept(v);
455
- v.visit_Node_expr_0(self)
456
- end
457
- end
458
-
459
- class Node_expr_1 < Node_expr
460
- attr_accessor :expr, :tx2d, :term
461
- def initialize expr, tx2d, term
462
- super()
463
- @expr = expr; @tx2d = tx2d; @term = term
464
- end
465
- def accept v
466
- expr.accept(v); term.accept(v);
467
- v.visit_Node_expr_1(self)
468
- end
469
- end
470
-
471
- class Node_expr_2 < Node_expr
472
- attr_accessor :term
473
- def initialize term
474
- super()
475
- @term = term
476
- end
477
- def accept v
478
- term.accept(v);
479
- v.visit_Node_expr_2(self)
480
- end
481
- end
482
-
483
- class Node_term < Node
484
- def initialize
485
- super()
486
- end
487
- end
488
-
489
- class Node_term_0 < Node_term
490
- attr_accessor :term, :tx2a, :fact
491
- def initialize term, tx2a, fact
492
- super()
493
- @term = term; @tx2a = tx2a; @fact = fact
494
- end
495
- def accept v
496
- term.accept(v); fact.accept(v);
497
- v.visit_Node_term_0(self)
498
- end
499
- end
500
-
501
- class Node_term_1 < Node_term
502
- attr_accessor :term, :tx2f, :fact
503
- def initialize term, tx2f, fact
504
- super()
505
- @term = term; @tx2f = tx2f; @fact = fact
506
- end
507
- def accept v
508
- term.accept(v); fact.accept(v);
509
- v.visit_Node_term_1(self)
510
- end
511
- end
512
-
513
- class Node_term_2 < Node_term
514
- attr_accessor :fact
515
- def initialize fact
516
- super()
517
- @fact = fact
518
- end
519
- def accept v
520
- fact.accept(v);
521
- v.visit_Node_term_2(self)
522
- end
523
- end
524
-
525
- class Node_fact < Node
526
- def initialize
527
- super()
528
- end
529
- end
530
-
531
- class Node_fact_0 < Node_fact
532
- attr_accessor :num
533
- def initialize num
534
- super()
535
- @num = num
536
- end
537
- def accept v
538
-
539
- v.visit_Node_fact_0(self)
540
- end
541
- end
542
-
543
- class Node_fact_1 < Node_fact
544
- attr_accessor :tx28, :expr, :tx29
545
- def initialize tx28, expr, tx29
546
- super()
547
- @tx28 = tx28; @expr = expr; @tx29 = tx29
548
- end
549
- def accept v
550
- expr.accept(v);
551
- v.visit_Node_fact_1(self)
552
- end
553
- end
554
-
555
- class D4TinyCalc::CSTBuilder < Depager::LALR::Action #:nodoc:all
556
- include Depager::DecoratorUtils
557
-
558
- on_reduce = [
559
- nil,
560
- :_cst_0,
561
- :_cst_1,
562
- :_cst_2,
563
- :_cst_3,
564
- :_cst_4,
565
- :_cst_5,
566
- :_cst_6,
567
- :_cst_7,
568
-
569
- ]
570
- Tables = [on_reduce]
571
- def initialize inside
572
- super inside, 'CSTBuilder'
573
- @on_reduce, = self.class::Tables
574
- init_parser
575
- end
576
-
577
-
578
- module_eval <<-'.,.,122745803958185.,.,', 'sample_calc/calc.cst.dr', 23
579
- def _cst_0 val
580
- Node_expr_0.new(val[0], val[1], val[2])
581
- end
582
- .,.,122745803958185.,.,
583
-
584
- module_eval <<-'.,.,122745803928586.,.,', 'sample_calc/calc.cst.dr', 24
585
- def _cst_1 val
586
- Node_expr_1.new(val[0], val[1], val[2])
587
- end
588
- .,.,122745803928586.,.,
589
-
590
- module_eval <<-'.,.,122745803930636.,.,', 'sample_calc/calc.cst.dr', 25
591
- def _cst_2 val
592
- Node_expr_2.new(val[0])
593
- end
594
- .,.,122745803930636.,.,
595
-
596
- module_eval <<-'.,.,12274580392302.,.,', 'sample_calc/calc.cst.dr', 28
597
- def _cst_3 val
598
- Node_term_0.new(val[0], val[1], val[2])
599
- end
600
- .,.,12274580392302.,.,
601
-
602
- module_eval <<-'.,.,122745803915548.,.,', 'sample_calc/calc.cst.dr', 29
603
- def _cst_4 val
604
- Node_term_1.new(val[0], val[1], val[2])
605
- end
606
- .,.,122745803915548.,.,
607
-
608
- module_eval <<-'.,.,122745803944731.,.,', 'sample_calc/calc.cst.dr', 30
609
- def _cst_5 val
610
- Node_term_2.new(val[0])
611
- end
612
- .,.,122745803944731.,.,
613
-
614
- module_eval <<-'.,.,122745803920542.,.,', 'sample_calc/calc.cst.dr', 33
615
- def _cst_6 val
616
- Node_fact_0.new(val[0])
617
- end
618
- .,.,122745803920542.,.,
619
-
620
- module_eval <<-'.,.,12274580399969.,.,', 'sample_calc/calc.cst.dr', 34
621
- def _cst_7 val
622
- Node_fact_1.new(val[0], val[1], val[2])
623
- end
624
- .,.,12274580399969.,.,
625
-
626
- end
627
-
628
-
629
- def createDecoratedTinyCalc
630
- D4TinyCalc::CSTBuilder.new(TinyCalc.new())
631
- end
632
-
633
- ### main
634
- if __FILE__ == $0
635
- ### Main Code
636
- require 'pp'
637
- parser = createDecoratedTinyCalc
638
- r, = parser.parse(STDIN)
639
- v = Visitor.new
640
- r.accept(v)
641
- pp r
642
- puts r.value
643
-
644
- end