depager 0.2.2 → 0.2.3

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 (62) hide show
  1. data/ChangeLog +4 -0
  2. data/README.ja +27 -28
  3. data/examples/c89/c89.dr +34 -34
  4. data/examples/c89/c89.tab.rb +3074 -3074
  5. data/examples/extension/paction.dr +4 -4
  6. data/examples/extension/pactiontest.dr +1 -1
  7. data/examples/pl0d/pl0ds.dr +27 -27
  8. data/examples/pl0d/pl0ds.tab.rb +626 -643
  9. data/examples/sample_calc/calc.action.dr +6 -6
  10. data/examples/sample_calc/calc.action.tab.rb +90 -90
  11. data/examples/sample_calc/calc.ast.action.dr +7 -7
  12. data/examples/sample_calc/calc.ast.action.tab.rb +121 -127
  13. data/examples/sample_calc/calc.ast.dr +6 -6
  14. data/examples/sample_calc/calc.ast.tab.rb +102 -109
  15. data/examples/sample_calc/calc.astdf.dr +6 -6
  16. data/examples/sample_calc/calc.astdf.tab.rb +102 -109
  17. data/examples/sample_calc/calc.atree.dr +6 -6
  18. data/examples/sample_calc/calc.atree.tab.rb +90 -90
  19. data/examples/sample_calc/calc.cst.dr +5 -5
  20. data/examples/sample_calc/calc.cst.tab.rb +106 -106
  21. data/examples/sample_calc/calc.dr +1 -1
  22. data/examples/sample_calc/calc.lex.dr +4 -4
  23. data/examples/sample_calc/calc.lex.tab.rb +73 -73
  24. data/examples/sample_calc/calc.nvaction.dr +6 -6
  25. data/examples/sample_calc/calc.nvaction.tab.rb +90 -90
  26. data/examples/sample_calc/calc.tab.rb +71 -71
  27. data/examples/sample_calc/calc_prec.nvaction.dr +6 -6
  28. data/examples/sample_calc/calc_prec.nvaction.tab.rb +46 -46
  29. data/examples/slex_test/divreg.slex.dr +7 -7
  30. data/examples/slex_test/divreg.slex.tab.rb +20 -20
  31. data/examples/slex_test/ljoin.slex.dr +7 -7
  32. data/examples/slex_test/ljoin.slex.tab.rb +15 -15
  33. data/lib/depager.rb +45 -83
  34. data/lib/depager/grammar.rb +3 -7
  35. data/lib/depager/lr.rb +123 -1
  36. data/lib/depager/parser.rb +29 -48
  37. data/lib/depager/{template/ast.erbs → ruby/plugins/_ast_tmpl.rb} +11 -7
  38. data/lib/depager/{action.rb → ruby/plugins/action.rb} +7 -11
  39. data/lib/depager/{ast.dr → ruby/plugins/ast.dr} +24 -25
  40. data/lib/depager/{ast.rb → ruby/plugins/ast.rb} +241 -243
  41. data/lib/depager/{astdf.rb → ruby/plugins/astdf.rb} +1 -2
  42. data/lib/depager/{atree.dr → ruby/plugins/atree.dr} +5 -5
  43. data/lib/depager/{atree.rb → ruby/plugins/atree.rb} +39 -39
  44. data/lib/depager/{cst.dr → ruby/plugins/cst.dr} +17 -21
  45. data/lib/depager/{cst.rb → ruby/plugins/cst.rb} +62 -68
  46. data/lib/depager/{lex.dr → ruby/plugins/lex.dr} +3 -4
  47. data/lib/depager/{lex.rb → ruby/plugins/lex.rb} +29 -31
  48. data/lib/depager/{nvaction.rb → ruby/plugins/nvaction.rb} +1 -3
  49. data/lib/depager/{slex.dr → ruby/plugins/slex.dr} +16 -17
  50. data/lib/depager/{slex.rb → ruby/plugins/slex.rb} +115 -117
  51. data/lib/depager/{srp.rb → ruby/plugins/srp.rb} +4 -4
  52. data/lib/depager/{template → ruby/templates}/extension_lalr_master.erb +6 -6
  53. data/lib/depager/{template → ruby/templates}/extension_lalr_slave.erb +0 -0
  54. data/lib/depager/{template → ruby/templates}/simple.erb +0 -0
  55. data/lib/depager/{template → ruby/templates}/single_lalr_parser.erb +0 -0
  56. data/lib/depager/utils.rb +30 -69
  57. data/lib/depager/version.rb +1 -1
  58. metadata +59 -56
  59. data/examples/Rakefile +0 -36
  60. data/lib/depager/Rakefile +0 -34
  61. data/lib/depager/lr_put_table.rb +0 -116
  62. data/lib/depager/parse_action.rb +0 -24
@@ -1,14 +1,14 @@
1
1
  %class TinyCalc
2
- %extend Lexer ('depager/lex.rb')
3
- %extend Action ('depager/action.rb')
2
+ %extend Lexer ('plugins/lex.rb')
3
+ %extend Action ('plugins/action.rb')
4
4
  %decorate @Action
5
- #%decorate ShiftReducePrinter ('depager/srp.rb')
5
+ #%decorate ShiftReducePrinter ('plugins/srp.rb')
6
6
  %%
7
7
 
8
8
  %LEX{
9
9
  /\s+/, /\#.*/ { }
10
- /[1-9][0-9]*/ { yield _Token(:NUM, $&.to_i) }
11
- /./ { yield _Token($&, $&) }
10
+ /[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
11
+ /./ { yield token($&, $&) }
12
12
  %}
13
13
 
14
14
  #begin-rule
@@ -29,5 +29,5 @@
29
29
  #end-rule
30
30
  %%
31
31
  parser = TinyCalc::createDecoratedParser
32
- r, = parser.yyparse(STDIN)
32
+ r, = parser.parse(STDIN)
33
33
  puts r
@@ -51,25 +51,26 @@ class TinyCalc < Depager::LALR::Basis
51
51
  ]
52
52
  ### Action Table
53
53
  action_table = [
54
- [ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
55
- [ ACC, nil, 6, 7, nil, nil, nil, nil, nil, ],
56
- [ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
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, ],
57
58
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
58
59
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
59
- [ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
60
- [ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
61
- [ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
62
- [ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
63
- [ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
64
- [ nil, nil, 6, 7, nil, nil, nil, nil, 15, ],
65
- [ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
66
- [ nil, nil, nil, nil, 8, 9, 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, ],
67
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
68
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
69
69
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
70
70
  ]
71
71
  ### Default Reduce Table
72
72
  defred_table = [
73
+ nil,
73
74
  nil,
74
75
  nil,
75
76
  -3,
@@ -80,17 +81,17 @@ class TinyCalc < Depager::LALR::Basis
80
81
  nil,
81
82
  nil,
82
83
  nil,
83
- nil,
84
+ -8,
84
85
  -1,
85
86
  -2,
86
87
  -4,
87
88
  -5,
88
- -8,
89
89
  ]
90
90
  defred_after_shift_table = [
91
91
  nil,
92
92
  nil,
93
93
  nil,
94
+ nil,
94
95
  -6,
95
96
  -7,
96
97
  nil,
@@ -98,12 +99,11 @@ class TinyCalc < Depager::LALR::Basis
98
99
  nil,
99
100
  nil,
100
101
  nil,
101
- nil,
102
+ -8,
102
103
  nil,
103
104
  nil,
104
105
  -4,
105
106
  -5,
106
- -8,
107
107
  ]
108
108
  ### Nonterm to Int
109
109
  nt2i = {
@@ -119,17 +119,17 @@ class TinyCalc < Depager::LALR::Basis
119
119
  ]
120
120
  ### Goto Table
121
121
  goto_table = [
122
- [ 1, 2, 3, ],
122
+ [ 2, 3, 4, ],
123
+ [ 6, 3, 4, ],
123
124
  [ nil, nil, nil, ],
124
125
  [ nil, nil, nil, ],
125
126
  [ nil, nil, nil, ],
126
127
  [ nil, nil, nil, ],
127
- [ 10, 2, 3, ],
128
- [ nil, 11, 3, ],
129
- [ nil, 12, 3, ],
130
- [ nil, nil, 13, ],
131
- [ nil, nil, 14, ],
132
128
  [ nil, nil, nil, ],
129
+ [ nil, 12, 4, ],
130
+ [ nil, 13, 4, ],
131
+ [ nil, nil, 14, ],
132
+ [ nil, nil, 15, ],
133
133
  [ nil, nil, nil, ],
134
134
  [ nil, nil, nil, ],
135
135
  [ nil, nil, nil, ],
@@ -150,20 +150,30 @@ class TinyCalc < Depager::LALR::Basis
150
150
  I000 =
151
151
  ( 0) $start : _ expr
152
152
 
153
- NUM shift, and goto to state 4
154
- '(' shift, and goto to state 5
153
+ NUM shift, and goto to state 5
154
+ '(' shift, and goto to state 1
155
155
 
156
156
 
157
157
  ----------
158
158
 
159
159
  <<'----------',
160
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 =
161
171
  ( 0) $start : expr _
162
172
  ( 1) expr : expr _ '+' term
163
173
  ( 2) expr : expr _ '-' term
164
174
 
165
- '+' shift, and goto to state 6
166
- '-' shift, and goto to state 7
175
+ '+' shift, and goto to state 7
176
+ '-' shift, and goto to state 8
167
177
 
168
178
 
169
179
  $end accept
@@ -171,20 +181,20 @@ I001 =
171
181
  ----------
172
182
 
173
183
  <<'----------',
174
- I002 =
184
+ I003 =
175
185
  ( 3) expr : term _
176
186
  ( 4) term : term _ '*' fact
177
187
  ( 5) term : term _ '/' fact
178
188
 
179
- '*' shift, and goto to state 8
180
- '/' shift, and goto to state 9
189
+ '*' shift, and goto to state 9
190
+ '/' shift, and goto to state 10
181
191
 
182
192
  $default reduce using rule 3 (expr)
183
193
 
184
194
  ----------
185
195
 
186
196
  <<'----------',
187
- I003 =
197
+ I004 =
188
198
  ( 6) term : fact _
189
199
 
190
200
 
@@ -193,7 +203,7 @@ I003 =
193
203
  ----------
194
204
 
195
205
  <<'----------',
196
- I004 =
206
+ I005 =
197
207
  ( 7) fact : NUM _
198
208
 
199
209
 
@@ -202,96 +212,95 @@ I004 =
202
212
  ----------
203
213
 
204
214
  <<'----------',
205
- I005 =
206
- ( 8) fact : '(' _ expr ')'
215
+ I006 =
216
+ ( 8) fact : '(' expr _ ')'
217
+ ( 1) expr : expr _ '+' term
218
+ ( 2) expr : expr _ '-' term
207
219
 
208
- NUM shift, and goto to state 4
209
- '(' shift, and goto to state 5
220
+ '+' shift, and goto to state 7
221
+ '-' shift, and goto to state 8
222
+ ')' shift, and goto to state 11
210
223
 
211
224
 
212
225
  ----------
213
226
 
214
227
  <<'----------',
215
- I006 =
228
+ I007 =
216
229
  ( 1) expr : expr '+' _ term
217
230
 
218
- NUM shift, and goto to state 4
219
- '(' shift, and goto to state 5
231
+ NUM shift, and goto to state 5
232
+ '(' shift, and goto to state 1
220
233
 
221
234
 
222
235
  ----------
223
236
 
224
237
  <<'----------',
225
- I007 =
238
+ I008 =
226
239
  ( 2) expr : expr '-' _ term
227
240
 
228
- NUM shift, and goto to state 4
229
- '(' shift, and goto to state 5
241
+ NUM shift, and goto to state 5
242
+ '(' shift, and goto to state 1
230
243
 
231
244
 
232
245
  ----------
233
246
 
234
247
  <<'----------',
235
- I008 =
248
+ I009 =
236
249
  ( 4) term : term '*' _ fact
237
250
 
238
- NUM shift, and goto to state 4
239
- '(' shift, and goto to state 5
251
+ NUM shift, and goto to state 5
252
+ '(' shift, and goto to state 1
240
253
 
241
254
 
242
255
  ----------
243
256
 
244
257
  <<'----------',
245
- I009 =
258
+ I010 =
246
259
  ( 5) term : term '/' _ fact
247
260
 
248
- NUM shift, and goto to state 4
249
- '(' shift, and goto to state 5
261
+ NUM shift, and goto to state 5
262
+ '(' shift, and goto to state 1
250
263
 
251
264
 
252
265
  ----------
253
266
 
254
267
  <<'----------',
255
- I010 =
256
- ( 8) fact : '(' expr _ ')'
257
- ( 1) expr : expr _ '+' term
258
- ( 2) expr : expr _ '-' term
268
+ I011 =
269
+ ( 8) fact : '(' expr ')' _
259
270
 
260
- '+' shift, and goto to state 6
261
- '-' shift, and goto to state 7
262
- ')' shift, and goto to state 15
263
271
 
272
+ $default reduce using rule 8 (fact) [after shift]
264
273
 
265
274
  ----------
266
275
 
267
276
  <<'----------',
268
- I011 =
277
+ I012 =
269
278
  ( 1) expr : expr '+' term _
270
279
  ( 4) term : term _ '*' fact
271
280
  ( 5) term : term _ '/' fact
272
281
 
273
- '*' shift, and goto to state 8
274
- '/' shift, and goto to state 9
282
+ '*' shift, and goto to state 9
283
+ '/' shift, and goto to state 10
275
284
 
276
285
  $default reduce using rule 1 (expr)
277
286
 
278
287
  ----------
279
288
 
280
289
  <<'----------',
281
- I012 =
290
+ I013 =
282
291
  ( 2) expr : expr '-' term _
283
292
  ( 4) term : term _ '*' fact
284
293
  ( 5) term : term _ '/' fact
285
294
 
286
- '*' shift, and goto to state 8
287
- '/' shift, and goto to state 9
295
+ '*' shift, and goto to state 9
296
+ '/' shift, and goto to state 10
288
297
 
289
298
  $default reduce using rule 2 (expr)
290
299
 
291
300
  ----------
292
301
 
293
302
  <<'----------',
294
- I013 =
303
+ I014 =
295
304
  ( 4) term : term '*' fact _
296
305
 
297
306
 
@@ -300,21 +309,12 @@ I013 =
300
309
  ----------
301
310
 
302
311
  <<'----------',
303
- I014 =
312
+ I015 =
304
313
  ( 5) term : term '/' fact _
305
314
 
306
315
 
307
316
  $default reduce using rule 5 (term) [after shift]
308
317
 
309
- ----------
310
-
311
- <<'----------',
312
- I015 =
313
- ( 8) fact : '(' expr ')' _
314
-
315
-
316
- $default reduce using rule 8 (fact) [after shift]
317
-
318
318
  ----------
319
319
  ]
320
320
 
@@ -341,12 +341,12 @@ I015 =
341
341
 
342
342
  when /\A[1-9][0-9]*/
343
343
  @oldline = @line; @line = $'
344
- yield _Token(:NUM, $&.to_i)
344
+ yield token(:NUM, $&.to_i)
345
345
 
346
346
 
347
347
  when /\A./
348
348
  @oldline = @line; @line = $'
349
- yield _Token($&, $&)
349
+ yield token($&, $&)
350
350
 
351
351
 
352
352
  else
@@ -363,7 +363,7 @@ end
363
363
 
364
364
  class D4TinyCalc::Action < Depager::LALR::Action #:nodoc:all
365
365
  include Depager::DecoratorUtils
366
- []
366
+
367
367
  on_reduce = [
368
368
  nil,
369
369
  :_act_0,
@@ -384,61 +384,61 @@ class D4TinyCalc::Action < Depager::LALR::Action #:nodoc:all
384
384
  end
385
385
 
386
386
 
387
- module_eval <<-'.,.,120998293115109.,.,', 'sample_calc/calc.action.dr', 15
387
+ module_eval <<-'.,.,122745803834649.,.,', 'sample_calc/calc.action.dr', 15
388
388
  def _act_0 val
389
389
  val[0] + val[2]
390
390
 
391
391
  end
392
- .,.,120998293115109.,.,
392
+ .,.,122745803834649.,.,
393
393
 
394
- module_eval <<-'.,.,12099829312650.,.,', 'sample_calc/calc.action.dr', 16
394
+ module_eval <<-'.,.,12274580381706.,.,', 'sample_calc/calc.action.dr', 16
395
395
  def _act_1 val
396
396
  val[0] - val[2]
397
397
 
398
398
  end
399
- .,.,12099829312650.,.,
399
+ .,.,12274580381706.,.,
400
400
 
401
- module_eval <<-'.,.,12099829313489.,.,', 'sample_calc/calc.action.dr', 17
401
+ module_eval <<-'.,.,122745803826799.,.,', 'sample_calc/calc.action.dr', 17
402
402
  def _act_2 val
403
403
  val[0]
404
404
 
405
405
  end
406
- .,.,12099829313489.,.,
406
+ .,.,122745803826799.,.,
407
407
 
408
- module_eval <<-'.,.,120998293125343.,.,', 'sample_calc/calc.action.dr', 20
408
+ module_eval <<-'.,.,122745803847781.,.,', 'sample_calc/calc.action.dr', 20
409
409
  def _act_3 val
410
410
  val[0] * val[2]
411
411
 
412
412
  end
413
- .,.,120998293125343.,.,
413
+ .,.,122745803847781.,.,
414
414
 
415
- module_eval <<-'.,.,120998293141013.,.,', 'sample_calc/calc.action.dr', 21
415
+ module_eval <<-'.,.,122745803847492.,.,', 'sample_calc/calc.action.dr', 21
416
416
  def _act_4 val
417
417
  val[0] / val[2]
418
418
 
419
419
  end
420
- .,.,120998293141013.,.,
420
+ .,.,122745803847492.,.,
421
421
 
422
- module_eval <<-'.,.,120998293143307.,.,', 'sample_calc/calc.action.dr', 22
422
+ module_eval <<-'.,.,12274580382355.,.,', 'sample_calc/calc.action.dr', 22
423
423
  def _act_5 val
424
424
  val[0]
425
425
 
426
426
  end
427
- .,.,120998293143307.,.,
427
+ .,.,12274580382355.,.,
428
428
 
429
- module_eval <<-'.,.,120998293124180.,.,', 'sample_calc/calc.action.dr', 25
429
+ module_eval <<-'.,.,122745803838328.,.,', 'sample_calc/calc.action.dr', 25
430
430
  def _act_6 val
431
431
  val[0].value
432
432
 
433
433
  end
434
- .,.,120998293124180.,.,
434
+ .,.,122745803838328.,.,
435
435
 
436
- module_eval <<-'.,.,120998293127174.,.,', 'sample_calc/calc.action.dr', 26
436
+ module_eval <<-'.,.,122745803830249.,.,', 'sample_calc/calc.action.dr', 26
437
437
  def _act_7 val
438
438
  val[1]
439
439
 
440
440
  end
441
- .,.,120998293127174.,.,
441
+ .,.,122745803830249.,.,
442
442
 
443
443
  end
444
444
 
@@ -451,7 +451,7 @@ end
451
451
  if __FILE__ == $0
452
452
  ### Main Code
453
453
  parser = TinyCalc::createDecoratedParser
454
- r, = parser.yyparse(STDIN)
454
+ r, = parser.parse(STDIN)
455
455
  puts r
456
456
 
457
457
  end
@@ -1,17 +1,17 @@
1
1
  %class TinyCalc
2
- %extend Lexer ('depager/lex.rb')
3
- %extend ASTBuilder ('depager/ast.rb')
4
- %extend Action ('depager/action.rb')
2
+ %extend Lexer ('plugins/lex.rb')
3
+ %extend ASTBuilder ('plugins/ast.rb')
4
+ %extend Action ('plugins/action.rb')
5
5
  %decorate @ASTBuilder
6
6
  %decorate @Action
7
- #%decorate ShiftReducePrinter ('depager/srp.rb')
7
+ #%decorate ShiftReducePrinter ('plugins/srp.rb')
8
8
  %mixin Depager
9
9
  %%
10
10
 
11
11
  %LEX{
12
12
  /\s+/, /\#.*/, /\n/ { }
13
- /[1-9][0-9]*/ { yield _Token(:NUM, $&.to_i) }
14
- /./ { yield _Token($&, $&) }
13
+ /[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
14
+ /./ { yield token($&, $&) }
15
15
  %}
16
16
 
17
17
  %AST{
@@ -59,7 +59,7 @@
59
59
  %%
60
60
  require 'pp'
61
61
  parser = createDecoratedTinyCalc()
62
- t, r = parser.yyparse(STDIN)
62
+ t, r = parser.parse(STDIN)
63
63
  v = Visitor.new
64
64
  pp r
65
65
  pp t.accept(v).value