depager 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
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,15 +1,15 @@
1
1
  %class TinyCalc
2
- %extend Lexer ('depager/lex.rb')
3
- %extend ATreeBuilder ('depager/atree.rb')
2
+ %extend Lexer ('plugins/lex.rb')
3
+ %extend ATreeBuilder ('plugins/atree.rb')
4
4
  %decorate @ATreeBuilder
5
- #%decorate ShiftReducePrinter ('depager/srp.rb')
5
+ #%decorate ShiftReducePrinter ('plugins/srp.rb')
6
6
  %mixin Depager
7
7
  %%
8
8
 
9
9
  %LEX{
10
10
  /\s+/, /\#.*/ { }
11
- /[1-9][0-9]*/ { yield _Token(:NUM, $&.to_i) }
12
- /./ { yield _Token($&, $&) }
11
+ /[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
12
+ /./ { yield token($&, $&) }
13
13
  %}
14
14
 
15
15
  #begin-rule
@@ -39,5 +39,5 @@
39
39
  %%
40
40
  require 'pp'
41
41
  parser = createDecoratedTinyCalc
42
- r, = parser.yyparse(STDIN)
42
+ r, = parser.parse(STDIN)
43
43
  pp r
@@ -52,25 +52,26 @@ class TinyCalc < Depager::LALR::Basis
52
52
  ]
53
53
  ### Action Table
54
54
  action_table = [
55
- [ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
56
- [ ACC, nil, 6, 7, nil, nil, nil, nil, nil, ],
57
- [ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
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, ],
58
59
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
59
60
  [ nil, nil, nil, nil, nil, nil, nil, nil, 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, nil, nil, nil, nil, 4, 5, nil, ],
65
- [ nil, nil, 6, 7, nil, nil, nil, nil, 15, ],
66
- [ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
67
- [ nil, nil, nil, nil, 8, 9, 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, ],
68
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
69
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
70
70
  [ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
71
71
  ]
72
72
  ### Default Reduce Table
73
73
  defred_table = [
74
+ nil,
74
75
  nil,
75
76
  nil,
76
77
  -3,
@@ -81,17 +82,17 @@ class TinyCalc < Depager::LALR::Basis
81
82
  nil,
82
83
  nil,
83
84
  nil,
84
- nil,
85
+ -8,
85
86
  -1,
86
87
  -2,
87
88
  -4,
88
89
  -5,
89
- -8,
90
90
  ]
91
91
  defred_after_shift_table = [
92
92
  nil,
93
93
  nil,
94
94
  nil,
95
+ nil,
95
96
  -6,
96
97
  -7,
97
98
  nil,
@@ -99,12 +100,11 @@ class TinyCalc < Depager::LALR::Basis
99
100
  nil,
100
101
  nil,
101
102
  nil,
102
- nil,
103
+ -8,
103
104
  nil,
104
105
  nil,
105
106
  -4,
106
107
  -5,
107
- -8,
108
108
  ]
109
109
  ### Nonterm to Int
110
110
  nt2i = {
@@ -120,17 +120,17 @@ class TinyCalc < Depager::LALR::Basis
120
120
  ]
121
121
  ### Goto Table
122
122
  goto_table = [
123
- [ 1, 2, 3, ],
123
+ [ 2, 3, 4, ],
124
+ [ 6, 3, 4, ],
124
125
  [ nil, nil, nil, ],
125
126
  [ nil, nil, nil, ],
126
127
  [ nil, nil, nil, ],
127
128
  [ nil, nil, nil, ],
128
- [ 10, 2, 3, ],
129
- [ nil, 11, 3, ],
130
- [ nil, 12, 3, ],
131
- [ nil, nil, 13, ],
132
- [ nil, nil, 14, ],
133
129
  [ nil, nil, nil, ],
130
+ [ nil, 12, 4, ],
131
+ [ nil, 13, 4, ],
132
+ [ nil, nil, 14, ],
133
+ [ nil, nil, 15, ],
134
134
  [ nil, nil, nil, ],
135
135
  [ nil, nil, nil, ],
136
136
  [ nil, nil, nil, ],
@@ -151,20 +151,30 @@ class TinyCalc < Depager::LALR::Basis
151
151
  I000 =
152
152
  ( 0) $start : _ expr
153
153
 
154
- NUM shift, and goto to state 4
155
- '(' shift, and goto to state 5
154
+ NUM shift, and goto to state 5
155
+ '(' shift, and goto to state 1
156
156
 
157
157
 
158
158
  ----------
159
159
 
160
160
  <<'----------',
161
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 =
162
172
  ( 0) $start : expr _
163
173
  ( 1) expr : expr _ '+' term
164
174
  ( 2) expr : expr _ '-' term
165
175
 
166
- '+' shift, and goto to state 6
167
- '-' shift, and goto to state 7
176
+ '+' shift, and goto to state 7
177
+ '-' shift, and goto to state 8
168
178
 
169
179
 
170
180
  $end accept
@@ -172,20 +182,20 @@ I001 =
172
182
  ----------
173
183
 
174
184
  <<'----------',
175
- I002 =
185
+ I003 =
176
186
  ( 3) expr : term _
177
187
  ( 4) term : term _ '*' fact
178
188
  ( 5) term : term _ '/' fact
179
189
 
180
- '*' shift, and goto to state 8
181
- '/' shift, and goto to state 9
190
+ '*' shift, and goto to state 9
191
+ '/' shift, and goto to state 10
182
192
 
183
193
  $default reduce using rule 3 (expr)
184
194
 
185
195
  ----------
186
196
 
187
197
  <<'----------',
188
- I003 =
198
+ I004 =
189
199
  ( 6) term : fact _
190
200
 
191
201
 
@@ -194,7 +204,7 @@ I003 =
194
204
  ----------
195
205
 
196
206
  <<'----------',
197
- I004 =
207
+ I005 =
198
208
  ( 7) fact : NUM _
199
209
 
200
210
 
@@ -203,96 +213,95 @@ I004 =
203
213
  ----------
204
214
 
205
215
  <<'----------',
206
- I005 =
207
- ( 8) fact : '(' _ expr ')'
216
+ I006 =
217
+ ( 8) fact : '(' expr _ ')'
218
+ ( 1) expr : expr _ '+' term
219
+ ( 2) expr : expr _ '-' term
208
220
 
209
- NUM shift, and goto to state 4
210
- '(' shift, and goto to state 5
221
+ '+' shift, and goto to state 7
222
+ '-' shift, and goto to state 8
223
+ ')' shift, and goto to state 11
211
224
 
212
225
 
213
226
  ----------
214
227
 
215
228
  <<'----------',
216
- I006 =
229
+ I007 =
217
230
  ( 1) expr : expr '+' _ term
218
231
 
219
- NUM shift, and goto to state 4
220
- '(' shift, and goto to state 5
232
+ NUM shift, and goto to state 5
233
+ '(' shift, and goto to state 1
221
234
 
222
235
 
223
236
  ----------
224
237
 
225
238
  <<'----------',
226
- I007 =
239
+ I008 =
227
240
  ( 2) expr : expr '-' _ term
228
241
 
229
- NUM shift, and goto to state 4
230
- '(' shift, and goto to state 5
242
+ NUM shift, and goto to state 5
243
+ '(' shift, and goto to state 1
231
244
 
232
245
 
233
246
  ----------
234
247
 
235
248
  <<'----------',
236
- I008 =
249
+ I009 =
237
250
  ( 4) term : term '*' _ fact
238
251
 
239
- NUM shift, and goto to state 4
240
- '(' shift, and goto to state 5
252
+ NUM shift, and goto to state 5
253
+ '(' shift, and goto to state 1
241
254
 
242
255
 
243
256
  ----------
244
257
 
245
258
  <<'----------',
246
- I009 =
259
+ I010 =
247
260
  ( 5) term : term '/' _ fact
248
261
 
249
- NUM shift, and goto to state 4
250
- '(' shift, and goto to state 5
262
+ NUM shift, and goto to state 5
263
+ '(' shift, and goto to state 1
251
264
 
252
265
 
253
266
  ----------
254
267
 
255
268
  <<'----------',
256
- I010 =
257
- ( 8) fact : '(' expr _ ')'
258
- ( 1) expr : expr _ '+' term
259
- ( 2) expr : expr _ '-' term
269
+ I011 =
270
+ ( 8) fact : '(' expr ')' _
260
271
 
261
- '+' shift, and goto to state 6
262
- '-' shift, and goto to state 7
263
- ')' shift, and goto to state 15
264
272
 
273
+ $default reduce using rule 8 (fact) [after shift]
265
274
 
266
275
  ----------
267
276
 
268
277
  <<'----------',
269
- I011 =
278
+ I012 =
270
279
  ( 1) expr : expr '+' term _
271
280
  ( 4) term : term _ '*' fact
272
281
  ( 5) term : term _ '/' fact
273
282
 
274
- '*' shift, and goto to state 8
275
- '/' shift, and goto to state 9
283
+ '*' shift, and goto to state 9
284
+ '/' shift, and goto to state 10
276
285
 
277
286
  $default reduce using rule 1 (expr)
278
287
 
279
288
  ----------
280
289
 
281
290
  <<'----------',
282
- I012 =
291
+ I013 =
283
292
  ( 2) expr : expr '-' term _
284
293
  ( 4) term : term _ '*' fact
285
294
  ( 5) term : term _ '/' fact
286
295
 
287
- '*' shift, and goto to state 8
288
- '/' shift, and goto to state 9
296
+ '*' shift, and goto to state 9
297
+ '/' shift, and goto to state 10
289
298
 
290
299
  $default reduce using rule 2 (expr)
291
300
 
292
301
  ----------
293
302
 
294
303
  <<'----------',
295
- I013 =
304
+ I014 =
296
305
  ( 4) term : term '*' fact _
297
306
 
298
307
 
@@ -301,21 +310,12 @@ I013 =
301
310
  ----------
302
311
 
303
312
  <<'----------',
304
- I014 =
313
+ I015 =
305
314
  ( 5) term : term '/' fact _
306
315
 
307
316
 
308
317
  $default reduce using rule 5 (term) [after shift]
309
318
 
310
- ----------
311
-
312
- <<'----------',
313
- I015 =
314
- ( 8) fact : '(' expr ')' _
315
-
316
-
317
- $default reduce using rule 8 (fact) [after shift]
318
-
319
319
  ----------
320
320
  ]
321
321
 
@@ -342,12 +342,12 @@ I015 =
342
342
 
343
343
  when /\A[1-9][0-9]*/
344
344
  @oldline = @line; @line = $'
345
- yield _Token(:NUM, $&.to_i)
345
+ yield token(:NUM, $&.to_i)
346
346
 
347
347
 
348
348
  when /\A./
349
349
  @oldline = @line; @line = $'
350
- yield _Token($&, $&)
350
+ yield token($&, $&)
351
351
 
352
352
 
353
353
  else
@@ -364,7 +364,7 @@ end
364
364
 
365
365
  class D4TinyCalc::ATreeBuilder < Depager::LALR::Action #:nodoc:all
366
366
  include Depager::DecoratorUtils
367
- []
367
+
368
368
  on_reduce = [
369
369
  nil,
370
370
  :_atree_0,
@@ -385,53 +385,53 @@ class D4TinyCalc::ATreeBuilder < Depager::LALR::Action #:nodoc:all
385
385
  end
386
386
 
387
387
 
388
- module_eval <<-'.,.,120998293321400.,.,', 'sample_calc/calc.atree.dr', 17
388
+ module_eval <<-'.,.,122745803830157.,.,', 'sample_calc/calc.atree.dr', 17
389
389
  def _atree_0 val
390
390
  [:add, val[0],val[2]]
391
391
  end
392
- .,.,120998293321400.,.,
392
+ .,.,122745803830157.,.,
393
393
 
394
- module_eval <<-'.,.,120998293317716.,.,', 'sample_calc/calc.atree.dr', 19
394
+ module_eval <<-'.,.,122745803819966.,.,', 'sample_calc/calc.atree.dr', 19
395
395
  def _atree_1 val
396
396
  [:sub, val[0],val[2]]
397
397
  end
398
- .,.,120998293317716.,.,
398
+ .,.,122745803819966.,.,
399
399
 
400
- module_eval <<-'.,.,120998293311174.,.,', 'sample_calc/calc.atree.dr', 21
400
+ module_eval <<-'.,.,122745803811215.,.,', 'sample_calc/calc.atree.dr', 21
401
401
  def _atree_2 val
402
402
  val[0]
403
403
  end
404
- .,.,120998293311174.,.,
404
+ .,.,122745803811215.,.,
405
405
 
406
- module_eval <<-'.,.,120998293321022.,.,', 'sample_calc/calc.atree.dr', 25
406
+ module_eval <<-'.,.,122745803854915.,.,', 'sample_calc/calc.atree.dr', 25
407
407
  def _atree_3 val
408
408
  [:mul, val[0],val[2]]
409
409
  end
410
- .,.,120998293321022.,.,
410
+ .,.,122745803854915.,.,
411
411
 
412
- module_eval <<-'.,.,120998293362263.,.,', 'sample_calc/calc.atree.dr', 27
412
+ module_eval <<-'.,.,12274580384152.,.,', 'sample_calc/calc.atree.dr', 27
413
413
  def _atree_4 val
414
414
  [:div, val[0],val[2]]
415
415
  end
416
- .,.,120998293362263.,.,
416
+ .,.,12274580384152.,.,
417
417
 
418
- module_eval <<-'.,.,120998293338900.,.,', 'sample_calc/calc.atree.dr', 29
418
+ module_eval <<-'.,.,122745803842692.,.,', 'sample_calc/calc.atree.dr', 29
419
419
  def _atree_5 val
420
420
  val[0]
421
421
  end
422
- .,.,120998293338900.,.,
422
+ .,.,122745803842692.,.,
423
423
 
424
- module_eval <<-'.,.,120998293340705.,.,', 'sample_calc/calc.atree.dr', 33
424
+ module_eval <<-'.,.,122745803834536.,.,', 'sample_calc/calc.atree.dr', 33
425
425
  def _atree_6 val
426
426
  [:literal, val[0]]
427
427
  end
428
- .,.,120998293340705.,.,
428
+ .,.,122745803834536.,.,
429
429
 
430
- module_eval <<-'.,.,120998293327284.,.,', 'sample_calc/calc.atree.dr', 35
430
+ module_eval <<-'.,.,122745803843700.,.,', 'sample_calc/calc.atree.dr', 35
431
431
  def _atree_7 val
432
432
  val[1]
433
433
  end
434
- .,.,120998293327284.,.,
434
+ .,.,122745803843700.,.,
435
435
 
436
436
  end
437
437
 
@@ -445,7 +445,7 @@ if __FILE__ == $0
445
445
  ### Main Code
446
446
  require 'pp'
447
447
  parser = createDecoratedTinyCalc
448
- r, = parser.yyparse(STDIN)
448
+ r, = parser.parse(STDIN)
449
449
  pp r
450
450
 
451
451
  end
@@ -1,13 +1,13 @@
1
1
  %class TinyCalc
2
- %extend Lexer ('depager/lex.rb')
3
- %extend CSTBuilder ('depager/cst.rb')
2
+ %extend Lexer ('plugins/lex.rb')
3
+ %extend CSTBuilder ('plugins/cst.rb')
4
4
  %decorate @CSTBuilder
5
5
  %%
6
6
 
7
7
  %LEX{
8
8
  /\s+/, /\#.*/ { }
9
- /[1-9][0-9]*/ { yield _Token(:NUM, $&.to_i) }
10
- /./ { yield _Token($&, $&) }
9
+ /[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
10
+ /./ { yield token($&, $&) }
11
11
  %}
12
12
 
13
13
  %CST{
@@ -38,7 +38,7 @@
38
38
  %%
39
39
  require 'pp'
40
40
  parser = createDecoratedTinyCalc
41
- r, = parser.yyparse(STDIN)
41
+ r, = parser.parse(STDIN)
42
42
  v = Visitor.new
43
43
  r.accept(v)
44
44
  pp r