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.
- data/ChangeLog +4 -0
- data/README.ja +27 -28
- data/examples/c89/c89.dr +34 -34
- data/examples/c89/c89.tab.rb +3074 -3074
- data/examples/extension/paction.dr +4 -4
- data/examples/extension/pactiontest.dr +1 -1
- data/examples/pl0d/pl0ds.dr +27 -27
- data/examples/pl0d/pl0ds.tab.rb +626 -643
- data/examples/sample_calc/calc.action.dr +6 -6
- data/examples/sample_calc/calc.action.tab.rb +90 -90
- data/examples/sample_calc/calc.ast.action.dr +7 -7
- data/examples/sample_calc/calc.ast.action.tab.rb +121 -127
- data/examples/sample_calc/calc.ast.dr +6 -6
- data/examples/sample_calc/calc.ast.tab.rb +102 -109
- data/examples/sample_calc/calc.astdf.dr +6 -6
- data/examples/sample_calc/calc.astdf.tab.rb +102 -109
- data/examples/sample_calc/calc.atree.dr +6 -6
- data/examples/sample_calc/calc.atree.tab.rb +90 -90
- data/examples/sample_calc/calc.cst.dr +5 -5
- data/examples/sample_calc/calc.cst.tab.rb +106 -106
- data/examples/sample_calc/calc.dr +1 -1
- data/examples/sample_calc/calc.lex.dr +4 -4
- data/examples/sample_calc/calc.lex.tab.rb +73 -73
- data/examples/sample_calc/calc.nvaction.dr +6 -6
- data/examples/sample_calc/calc.nvaction.tab.rb +90 -90
- data/examples/sample_calc/calc.tab.rb +71 -71
- data/examples/sample_calc/calc_prec.nvaction.dr +6 -6
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +46 -46
- data/examples/slex_test/divreg.slex.dr +7 -7
- data/examples/slex_test/divreg.slex.tab.rb +20 -20
- data/examples/slex_test/ljoin.slex.dr +7 -7
- data/examples/slex_test/ljoin.slex.tab.rb +15 -15
- data/lib/depager.rb +45 -83
- data/lib/depager/grammar.rb +3 -7
- data/lib/depager/lr.rb +123 -1
- data/lib/depager/parser.rb +29 -48
- data/lib/depager/{template/ast.erbs → ruby/plugins/_ast_tmpl.rb} +11 -7
- data/lib/depager/{action.rb → ruby/plugins/action.rb} +7 -11
- data/lib/depager/{ast.dr → ruby/plugins/ast.dr} +24 -25
- data/lib/depager/{ast.rb → ruby/plugins/ast.rb} +241 -243
- data/lib/depager/{astdf.rb → ruby/plugins/astdf.rb} +1 -2
- data/lib/depager/{atree.dr → ruby/plugins/atree.dr} +5 -5
- data/lib/depager/{atree.rb → ruby/plugins/atree.rb} +39 -39
- data/lib/depager/{cst.dr → ruby/plugins/cst.dr} +17 -21
- data/lib/depager/{cst.rb → ruby/plugins/cst.rb} +62 -68
- data/lib/depager/{lex.dr → ruby/plugins/lex.dr} +3 -4
- data/lib/depager/{lex.rb → ruby/plugins/lex.rb} +29 -31
- data/lib/depager/{nvaction.rb → ruby/plugins/nvaction.rb} +1 -3
- data/lib/depager/{slex.dr → ruby/plugins/slex.dr} +16 -17
- data/lib/depager/{slex.rb → ruby/plugins/slex.rb} +115 -117
- data/lib/depager/{srp.rb → ruby/plugins/srp.rb} +4 -4
- data/lib/depager/{template → ruby/templates}/extension_lalr_master.erb +6 -6
- data/lib/depager/{template → ruby/templates}/extension_lalr_slave.erb +0 -0
- data/lib/depager/{template → ruby/templates}/simple.erb +0 -0
- data/lib/depager/{template → ruby/templates}/single_lalr_parser.erb +0 -0
- data/lib/depager/utils.rb +30 -69
- data/lib/depager/version.rb +1 -1
- metadata +59 -56
- data/examples/Rakefile +0 -36
- data/lib/depager/Rakefile +0 -34
- data/lib/depager/lr_put_table.rb +0 -116
- data/lib/depager/parse_action.rb +0 -24
@@ -1,15 +1,15 @@
|
|
1
1
|
%class TinyCalc
|
2
|
-
%extend Lexer ('
|
3
|
-
%extend ATreeBuilder ('
|
2
|
+
%extend Lexer ('plugins/lex.rb')
|
3
|
+
%extend ATreeBuilder ('plugins/atree.rb')
|
4
4
|
%decorate @ATreeBuilder
|
5
|
-
#%decorate ShiftReducePrinter ('
|
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
|
12
|
-
/./ { yield
|
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.
|
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,
|
56
|
-
[
|
57
|
-
[
|
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,
|
61
|
-
[ nil, nil, nil, nil, nil, nil,
|
62
|
-
[ nil, nil, nil, nil, nil, nil,
|
63
|
-
[ nil, nil, nil, nil, nil, nil,
|
64
|
-
[ nil, nil, nil, nil, nil, 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
|
-
|
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
|
-
|
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
|
-
[
|
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
|
155
|
-
'(' shift, and goto to state
|
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
|
167
|
-
'-' shift, and goto to state
|
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
|
-
|
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
|
181
|
-
'/' shift, and goto to state
|
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
|
-
|
198
|
+
I004 =
|
189
199
|
( 6) term : fact _
|
190
200
|
|
191
201
|
|
@@ -194,7 +204,7 @@ I003 =
|
|
194
204
|
----------
|
195
205
|
|
196
206
|
<<'----------',
|
197
|
-
|
207
|
+
I005 =
|
198
208
|
( 7) fact : NUM _
|
199
209
|
|
200
210
|
|
@@ -203,96 +213,95 @@ I004 =
|
|
203
213
|
----------
|
204
214
|
|
205
215
|
<<'----------',
|
206
|
-
|
207
|
-
( 8) fact : '(' _
|
216
|
+
I006 =
|
217
|
+
( 8) fact : '(' expr _ ')'
|
218
|
+
( 1) expr : expr _ '+' term
|
219
|
+
( 2) expr : expr _ '-' term
|
208
220
|
|
209
|
-
|
210
|
-
'
|
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
|
-
|
229
|
+
I007 =
|
217
230
|
( 1) expr : expr '+' _ term
|
218
231
|
|
219
|
-
NUM shift, and goto to state
|
220
|
-
'(' shift, and goto to state
|
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
|
-
|
239
|
+
I008 =
|
227
240
|
( 2) expr : expr '-' _ term
|
228
241
|
|
229
|
-
NUM shift, and goto to state
|
230
|
-
'(' shift, and goto to state
|
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
|
-
|
249
|
+
I009 =
|
237
250
|
( 4) term : term '*' _ fact
|
238
251
|
|
239
|
-
NUM shift, and goto to state
|
240
|
-
'(' shift, and goto to state
|
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
|
-
|
259
|
+
I010 =
|
247
260
|
( 5) term : term '/' _ fact
|
248
261
|
|
249
|
-
NUM shift, and goto to state
|
250
|
-
'(' shift, and goto to state
|
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
|
-
|
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
|
-
|
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
|
275
|
-
'/' shift, and goto to state
|
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
|
-
|
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
|
288
|
-
'/' shift, and goto to state
|
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
|
-
|
304
|
+
I014 =
|
296
305
|
( 4) term : term '*' fact _
|
297
306
|
|
298
307
|
|
@@ -301,21 +310,12 @@ I013 =
|
|
301
310
|
----------
|
302
311
|
|
303
312
|
<<'----------',
|
304
|
-
|
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
|
345
|
+
yield token(:NUM, $&.to_i)
|
346
346
|
|
347
347
|
|
348
348
|
when /\A./
|
349
349
|
@oldline = @line; @line = $'
|
350
|
-
yield
|
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 <<-'.,.,
|
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
|
-
.,.,
|
392
|
+
.,.,122745803830157.,.,
|
393
393
|
|
394
|
-
module_eval <<-'.,.,
|
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
|
-
.,.,
|
398
|
+
.,.,122745803819966.,.,
|
399
399
|
|
400
|
-
module_eval <<-'.,.,
|
400
|
+
module_eval <<-'.,.,122745803811215.,.,', 'sample_calc/calc.atree.dr', 21
|
401
401
|
def _atree_2 val
|
402
402
|
val[0]
|
403
403
|
end
|
404
|
-
.,.,
|
404
|
+
.,.,122745803811215.,.,
|
405
405
|
|
406
|
-
module_eval <<-'.,.,
|
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
|
-
.,.,
|
410
|
+
.,.,122745803854915.,.,
|
411
411
|
|
412
|
-
module_eval <<-'.,.,
|
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
|
-
.,.,
|
416
|
+
.,.,12274580384152.,.,
|
417
417
|
|
418
|
-
module_eval <<-'.,.,
|
418
|
+
module_eval <<-'.,.,122745803842692.,.,', 'sample_calc/calc.atree.dr', 29
|
419
419
|
def _atree_5 val
|
420
420
|
val[0]
|
421
421
|
end
|
422
|
-
.,.,
|
422
|
+
.,.,122745803842692.,.,
|
423
423
|
|
424
|
-
module_eval <<-'.,.,
|
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
|
-
.,.,
|
428
|
+
.,.,122745803834536.,.,
|
429
429
|
|
430
|
-
module_eval <<-'.,.,
|
430
|
+
module_eval <<-'.,.,122745803843700.,.,', 'sample_calc/calc.atree.dr', 35
|
431
431
|
def _atree_7 val
|
432
432
|
val[1]
|
433
433
|
end
|
434
|
-
.,.,
|
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.
|
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 ('
|
3
|
-
%extend CSTBuilder ('
|
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
|
10
|
-
/./ { yield
|
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.
|
41
|
+
r, = parser.parse(STDIN)
|
42
42
|
v = Visitor.new
|
43
43
|
r.accept(v)
|
44
44
|
pp r
|