depager 0.2.0 → 0.2.2
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.en +5 -10
- data/bin/depager +17 -20
- data/examples/c89/c89.tab.rb +5632 -702
- data/examples/pl0d/pl0ds.dr +41 -41
- data/examples/pl0d/pl0ds.tab.rb +1887 -874
- data/examples/sample_calc/calc.action.tab.rb +243 -69
- data/examples/sample_calc/{calc.astl.action.dr → calc.ast.action.dr} +7 -7
- data/examples/sample_calc/calc.ast.action.tab.rb +755 -0
- data/examples/sample_calc/{calc.astl.dr → calc.ast.dr} +7 -7
- data/examples/sample_calc/calc.ast.tab.rb +672 -0
- data/examples/sample_calc/calc.astdf.dr +5 -5
- data/examples/sample_calc/calc.astdf.tab.rb +405 -202
- data/examples/sample_calc/calc.atree.tab.rb +243 -69
- data/examples/sample_calc/calc.cst.tab.rb +275 -109
- data/examples/sample_calc/calc.lex.tab.rb +210 -28
- data/examples/sample_calc/calc.nvaction.tab.rb +251 -77
- data/examples/sample_calc/calc.tab.rb +210 -28
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +224 -50
- data/examples/slex_test/divreg.slex.tab.rb +97 -21
- data/examples/slex_test/ljoin.slex.tab.rb +128 -35
- data/lib/depager.rb +77 -44
- data/lib/depager/{ast_base.dr → ast.dr} +56 -18
- data/lib/depager/{ast_base.rb → ast.rb} +432 -424
- data/lib/depager/astdf.rb +3 -6
- data/lib/depager/atree.rb +54 -62
- data/lib/depager/cst.dr +2 -2
- data/lib/depager/cst.rb +64 -77
- data/lib/depager/grammar.rb +225 -66
- data/lib/depager/lex.dr +1 -1
- data/lib/depager/lex.rb +45 -54
- data/lib/depager/lr.rb +181 -262
- data/lib/depager/lr_put_table.rb +116 -0
- data/lib/depager/nvaction.rb +1 -1
- data/lib/depager/parser.rb +23 -2
- data/lib/depager/slex.dr +3 -3
- data/lib/depager/slex.rb +148 -169
- data/lib/depager/srp.rb +1 -1
- data/lib/depager/template/ast.erbs +69 -0
- data/lib/depager/template/extension_lalr_master.erb +3 -3
- data/lib/depager/template/extension_lalr_slave.erb +7 -7
- data/lib/depager/template/simple.erb +4 -2
- data/lib/depager/template/single_lalr_parser.erb +30 -10
- data/lib/depager/utils.rb +10 -9
- data/lib/depager/version.rb +2 -8
- metadata +10 -11
- data/examples/sample_calc/calc.astl.action.tab.rb +0 -593
- data/examples/sample_calc/calc.astl.tab.rb +0 -501
- data/lib/depager/astl.rb +0 -14
- data/lib/depager/template/astdf.erbs +0 -57
- data/lib/depager/template/astl.erbs +0 -57
@@ -3,8 +3,8 @@ begin; require 'rubygems'; rescue Exception; end
|
|
3
3
|
require 'depager/parser.rb'
|
4
4
|
|
5
5
|
|
6
|
-
module
|
7
|
-
end
|
6
|
+
module Depager::DecoratorUtils; end
|
7
|
+
module D4TinyCalc; end
|
8
8
|
|
9
9
|
class TinyCalc < Depager::LALR::Basis
|
10
10
|
|
@@ -13,14 +13,14 @@ class TinyCalc < Depager::LALR::Basis
|
|
13
13
|
### Reduce Table
|
14
14
|
reduce_table = [
|
15
15
|
[ -1, 1 ], # ( 0) $start : expr
|
16
|
-
[ 0, 3 ], # ( 1) expr : expr + term
|
17
|
-
[ 0, 3 ], # ( 2) expr : expr - term
|
16
|
+
[ 0, 3 ], # ( 1) expr : expr '+' term
|
17
|
+
[ 0, 3 ], # ( 2) expr : expr '-' term
|
18
18
|
[ 0, 1 ], # ( 3) expr : term
|
19
|
-
[ 1, 3 ], # ( 4) term : term * fact
|
20
|
-
[ 1, 3 ], # ( 5) term : term / fact
|
19
|
+
[ 1, 3 ], # ( 4) term : term '*' fact
|
20
|
+
[ 1, 3 ], # ( 5) term : term '/' fact
|
21
21
|
[ 1, 1 ], # ( 6) term : fact
|
22
22
|
[ 2, 1 ], # ( 7) fact : NUM
|
23
|
-
[ 2, 3 ], # ( 8) fact : ( expr )
|
23
|
+
[ 2, 3 ], # ( 8) fact : '(' expr ')'
|
24
24
|
]
|
25
25
|
### Extension Params
|
26
26
|
nparams = {
|
@@ -52,26 +52,25 @@ class TinyCalc < Depager::LALR::Basis
|
|
52
52
|
]
|
53
53
|
### Action Table
|
54
54
|
action_table = [
|
55
|
-
[ nil, nil, nil, nil, nil, nil,
|
56
|
-
[
|
57
|
-
[
|
58
|
-
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
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, ],
|
59
58
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
60
59
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
61
|
-
[ 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, 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, ],
|
66
68
|
[ 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,
|
75
74
|
nil,
|
76
75
|
nil,
|
77
76
|
-3,
|
@@ -82,17 +81,17 @@ class TinyCalc < Depager::LALR::Basis
|
|
82
81
|
nil,
|
83
82
|
nil,
|
84
83
|
nil,
|
85
|
-
|
84
|
+
nil,
|
86
85
|
-1,
|
87
86
|
-2,
|
88
87
|
-4,
|
89
88
|
-5,
|
89
|
+
-8,
|
90
90
|
]
|
91
91
|
defred_after_shift_table = [
|
92
92
|
nil,
|
93
93
|
nil,
|
94
94
|
nil,
|
95
|
-
nil,
|
96
95
|
-6,
|
97
96
|
-7,
|
98
97
|
nil,
|
@@ -100,11 +99,12 @@ class TinyCalc < Depager::LALR::Basis
|
|
100
99
|
nil,
|
101
100
|
nil,
|
102
101
|
nil,
|
103
|
-
|
102
|
+
nil,
|
104
103
|
nil,
|
105
104
|
nil,
|
106
105
|
-4,
|
107
106
|
-5,
|
107
|
+
-8,
|
108
108
|
]
|
109
109
|
### Nonterm to Int
|
110
110
|
nt2i = {
|
@@ -120,24 +120,206 @@ class TinyCalc < Depager::LALR::Basis
|
|
120
120
|
]
|
121
121
|
### Goto Table
|
122
122
|
goto_table = [
|
123
|
-
[ 2, 3,
|
124
|
-
[ 6, 3, 4, ],
|
123
|
+
[ 1, 2, 3, ],
|
125
124
|
[ nil, nil, nil, ],
|
126
125
|
[ nil, nil, nil, ],
|
127
126
|
[ nil, nil, nil, ],
|
128
127
|
[ nil, nil, nil, ],
|
129
|
-
[
|
130
|
-
[ nil,
|
131
|
-
[ nil,
|
128
|
+
[ 10, 2, 3, ],
|
129
|
+
[ nil, 11, 3, ],
|
130
|
+
[ nil, 12, 3, ],
|
131
|
+
[ nil, nil, 13, ],
|
132
132
|
[ nil, nil, 14, ],
|
133
|
-
[ nil, nil, 15, ],
|
134
133
|
[ nil, nil, nil, ],
|
135
134
|
[ nil, nil, nil, ],
|
136
135
|
[ nil, nil, nil, ],
|
137
136
|
[ nil, nil, nil, ],
|
138
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 4
|
155
|
+
'(' shift, and goto to state 5
|
156
|
+
|
157
|
+
|
158
|
+
----------
|
159
|
+
|
160
|
+
<<'----------',
|
161
|
+
I001 =
|
162
|
+
( 0) $start : expr _
|
163
|
+
( 1) expr : expr _ '+' term
|
164
|
+
( 2) expr : expr _ '-' term
|
165
|
+
|
166
|
+
'+' shift, and goto to state 6
|
167
|
+
'-' shift, and goto to state 7
|
168
|
+
|
169
|
+
|
170
|
+
$end accept
|
171
|
+
|
172
|
+
----------
|
173
|
+
|
174
|
+
<<'----------',
|
175
|
+
I002 =
|
176
|
+
( 3) expr : term _
|
177
|
+
( 4) term : term _ '*' fact
|
178
|
+
( 5) term : term _ '/' fact
|
179
|
+
|
180
|
+
'*' shift, and goto to state 8
|
181
|
+
'/' shift, and goto to state 9
|
182
|
+
|
183
|
+
$default reduce using rule 3 (expr)
|
184
|
+
|
185
|
+
----------
|
186
|
+
|
187
|
+
<<'----------',
|
188
|
+
I003 =
|
189
|
+
( 6) term : fact _
|
190
|
+
|
191
|
+
|
192
|
+
$default reduce using rule 6 (term) [after shift]
|
193
|
+
|
194
|
+
----------
|
195
|
+
|
196
|
+
<<'----------',
|
197
|
+
I004 =
|
198
|
+
( 7) fact : NUM _
|
199
|
+
|
200
|
+
|
201
|
+
$default reduce using rule 7 (fact) [after shift]
|
202
|
+
|
203
|
+
----------
|
204
|
+
|
205
|
+
<<'----------',
|
206
|
+
I005 =
|
207
|
+
( 8) fact : '(' _ expr ')'
|
208
|
+
|
209
|
+
NUM shift, and goto to state 4
|
210
|
+
'(' shift, and goto to state 5
|
211
|
+
|
212
|
+
|
213
|
+
----------
|
214
|
+
|
215
|
+
<<'----------',
|
216
|
+
I006 =
|
217
|
+
( 1) expr : expr '+' _ term
|
218
|
+
|
219
|
+
NUM shift, and goto to state 4
|
220
|
+
'(' shift, and goto to state 5
|
221
|
+
|
222
|
+
|
223
|
+
----------
|
224
|
+
|
225
|
+
<<'----------',
|
226
|
+
I007 =
|
227
|
+
( 2) expr : expr '-' _ term
|
228
|
+
|
229
|
+
NUM shift, and goto to state 4
|
230
|
+
'(' shift, and goto to state 5
|
231
|
+
|
232
|
+
|
233
|
+
----------
|
234
|
+
|
235
|
+
<<'----------',
|
236
|
+
I008 =
|
237
|
+
( 4) term : term '*' _ fact
|
238
|
+
|
239
|
+
NUM shift, and goto to state 4
|
240
|
+
'(' shift, and goto to state 5
|
241
|
+
|
242
|
+
|
243
|
+
----------
|
244
|
+
|
245
|
+
<<'----------',
|
246
|
+
I009 =
|
247
|
+
( 5) term : term '/' _ fact
|
248
|
+
|
249
|
+
NUM shift, and goto to state 4
|
250
|
+
'(' shift, and goto to state 5
|
251
|
+
|
252
|
+
|
253
|
+
----------
|
254
|
+
|
255
|
+
<<'----------',
|
256
|
+
I010 =
|
257
|
+
( 8) fact : '(' expr _ ')'
|
258
|
+
( 1) expr : expr _ '+' term
|
259
|
+
( 2) expr : expr _ '-' term
|
260
|
+
|
261
|
+
'+' shift, and goto to state 6
|
262
|
+
'-' shift, and goto to state 7
|
263
|
+
')' shift, and goto to state 15
|
264
|
+
|
265
|
+
|
266
|
+
----------
|
267
|
+
|
268
|
+
<<'----------',
|
269
|
+
I011 =
|
270
|
+
( 1) expr : expr '+' term _
|
271
|
+
( 4) term : term _ '*' fact
|
272
|
+
( 5) term : term _ '/' fact
|
273
|
+
|
274
|
+
'*' shift, and goto to state 8
|
275
|
+
'/' shift, and goto to state 9
|
276
|
+
|
277
|
+
$default reduce using rule 1 (expr)
|
278
|
+
|
279
|
+
----------
|
280
|
+
|
281
|
+
<<'----------',
|
282
|
+
I012 =
|
283
|
+
( 2) expr : expr '-' term _
|
284
|
+
( 4) term : term _ '*' fact
|
285
|
+
( 5) term : term _ '/' fact
|
286
|
+
|
287
|
+
'*' shift, and goto to state 8
|
288
|
+
'/' shift, and goto to state 9
|
289
|
+
|
290
|
+
$default reduce using rule 2 (expr)
|
291
|
+
|
292
|
+
----------
|
293
|
+
|
294
|
+
<<'----------',
|
295
|
+
I013 =
|
296
|
+
( 4) term : term '*' fact _
|
297
|
+
|
298
|
+
|
299
|
+
$default reduce using rule 4 (term) [after shift]
|
300
|
+
|
301
|
+
----------
|
302
|
+
|
303
|
+
<<'----------',
|
304
|
+
I014 =
|
305
|
+
( 5) term : term '/' fact _
|
306
|
+
|
307
|
+
|
308
|
+
$default reduce using rule 5 (term) [after shift]
|
309
|
+
|
310
|
+
----------
|
311
|
+
|
312
|
+
<<'----------',
|
313
|
+
I015 =
|
314
|
+
( 8) fact : '(' expr ')' _
|
315
|
+
|
316
|
+
|
317
|
+
$default reduce using rule 8 (fact) [after shift]
|
318
|
+
|
319
|
+
----------
|
139
320
|
]
|
140
321
|
|
322
|
+
|
141
323
|
Tables = [ reduce_table, nparams, action_table,
|
142
324
|
defred_table, defred_after_shift_table, goto_table,
|
143
325
|
t2i, i2t, nt2i, i2nt ]
|
@@ -182,7 +364,7 @@ end
|
|
182
364
|
|
183
365
|
class D4TinyCalc::ATreeBuilder < Depager::LALR::Action #:nodoc:all
|
184
366
|
include Depager::DecoratorUtils
|
185
|
-
|
367
|
+
[]
|
186
368
|
on_reduce = [
|
187
369
|
nil,
|
188
370
|
:_atree_0,
|
@@ -203,61 +385,53 @@ class D4TinyCalc::ATreeBuilder < Depager::LALR::Action #:nodoc:all
|
|
203
385
|
end
|
204
386
|
|
205
387
|
|
206
|
-
module_eval <<-'.,.,
|
207
|
-
|
388
|
+
module_eval <<-'.,.,120998293321400.,.,', 'sample_calc/calc.atree.dr', 17
|
389
|
+
def _atree_0 val
|
208
390
|
[:add, val[0],val[2]]
|
209
|
-
|
210
|
-
|
211
|
-
.,.,118754109027636.,.,
|
391
|
+
end
|
392
|
+
.,.,120998293321400.,.,
|
212
393
|
|
213
|
-
module_eval <<-'.,.,
|
214
|
-
|
394
|
+
module_eval <<-'.,.,120998293317716.,.,', 'sample_calc/calc.atree.dr', 19
|
395
|
+
def _atree_1 val
|
215
396
|
[:sub, val[0],val[2]]
|
216
|
-
|
217
|
-
|
218
|
-
.,.,118754109032509.,.,
|
397
|
+
end
|
398
|
+
.,.,120998293317716.,.,
|
219
399
|
|
220
|
-
module_eval <<-'.,.,
|
221
|
-
|
400
|
+
module_eval <<-'.,.,120998293311174.,.,', 'sample_calc/calc.atree.dr', 21
|
401
|
+
def _atree_2 val
|
222
402
|
val[0]
|
223
|
-
|
224
|
-
|
225
|
-
.,.,118754109043231.,.,
|
403
|
+
end
|
404
|
+
.,.,120998293311174.,.,
|
226
405
|
|
227
|
-
module_eval <<-'.,.,
|
228
|
-
|
406
|
+
module_eval <<-'.,.,120998293321022.,.,', 'sample_calc/calc.atree.dr', 25
|
407
|
+
def _atree_3 val
|
229
408
|
[:mul, val[0],val[2]]
|
230
|
-
|
231
|
-
|
232
|
-
.,.,11875410902130.,.,
|
409
|
+
end
|
410
|
+
.,.,120998293321022.,.,
|
233
411
|
|
234
|
-
module_eval <<-'.,.,
|
235
|
-
|
412
|
+
module_eval <<-'.,.,120998293362263.,.,', 'sample_calc/calc.atree.dr', 27
|
413
|
+
def _atree_4 val
|
236
414
|
[:div, val[0],val[2]]
|
237
|
-
|
238
|
-
|
239
|
-
.,.,11875410909726.,.,
|
415
|
+
end
|
416
|
+
.,.,120998293362263.,.,
|
240
417
|
|
241
|
-
module_eval <<-'.,.,
|
242
|
-
|
418
|
+
module_eval <<-'.,.,120998293338900.,.,', 'sample_calc/calc.atree.dr', 29
|
419
|
+
def _atree_5 val
|
243
420
|
val[0]
|
244
|
-
|
245
|
-
|
246
|
-
.,.,11875410909992.,.,
|
421
|
+
end
|
422
|
+
.,.,120998293338900.,.,
|
247
423
|
|
248
|
-
module_eval <<-'.,.,
|
249
|
-
|
424
|
+
module_eval <<-'.,.,120998293340705.,.,', 'sample_calc/calc.atree.dr', 33
|
425
|
+
def _atree_6 val
|
250
426
|
[:literal, val[0]]
|
251
|
-
|
252
|
-
|
253
|
-
.,.,118754109027407.,.,
|
427
|
+
end
|
428
|
+
.,.,120998293340705.,.,
|
254
429
|
|
255
|
-
module_eval <<-'.,.,
|
256
|
-
|
430
|
+
module_eval <<-'.,.,120998293327284.,.,', 'sample_calc/calc.atree.dr', 35
|
431
|
+
def _atree_7 val
|
257
432
|
val[1]
|
258
|
-
|
259
|
-
|
260
|
-
.,.,118754109041552.,.,
|
433
|
+
end
|
434
|
+
.,.,120998293327284.,.,
|
261
435
|
|
262
436
|
end
|
263
437
|
|
@@ -3,8 +3,8 @@ begin; require 'rubygems'; rescue Exception; end
|
|
3
3
|
require 'depager/parser.rb'
|
4
4
|
|
5
5
|
|
6
|
-
module
|
7
|
-
end
|
6
|
+
module Depager::DecoratorUtils; end
|
7
|
+
module D4TinyCalc; end
|
8
8
|
|
9
9
|
class TinyCalc < Depager::LALR::Basis
|
10
10
|
|
@@ -12,14 +12,14 @@ class TinyCalc < Depager::LALR::Basis
|
|
12
12
|
### Reduce Table
|
13
13
|
reduce_table = [
|
14
14
|
[ -1, 1 ], # ( 0) $start : expr
|
15
|
-
[ 0, 3 ], # ( 1) expr : expr + term
|
16
|
-
[ 0, 3 ], # ( 2) expr : expr - term
|
15
|
+
[ 0, 3 ], # ( 1) expr : expr '+' term
|
16
|
+
[ 0, 3 ], # ( 2) expr : expr '-' term
|
17
17
|
[ 0, 1 ], # ( 3) expr : term
|
18
|
-
[ 1, 3 ], # ( 4) term : term * fact
|
19
|
-
[ 1, 3 ], # ( 5) term : term / fact
|
18
|
+
[ 1, 3 ], # ( 4) term : term '*' fact
|
19
|
+
[ 1, 3 ], # ( 5) term : term '/' fact
|
20
20
|
[ 1, 1 ], # ( 6) term : fact
|
21
21
|
[ 2, 1 ], # ( 7) fact : NUM
|
22
|
-
[ 2, 3 ], # ( 8) fact : ( expr )
|
22
|
+
[ 2, 3 ], # ( 8) fact : '(' expr ')'
|
23
23
|
]
|
24
24
|
### Extension Params
|
25
25
|
nparams = {
|
@@ -51,26 +51,25 @@ class TinyCalc < Depager::LALR::Basis
|
|
51
51
|
]
|
52
52
|
### Action Table
|
53
53
|
action_table = [
|
54
|
-
[ nil, nil, nil, nil, nil, nil,
|
55
|
-
[
|
56
|
-
[
|
57
|
-
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
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, ],
|
58
57
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
59
58
|
[ 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,
|
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, ],
|
65
67
|
[ 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,
|
74
73
|
nil,
|
75
74
|
nil,
|
76
75
|
-3,
|
@@ -81,17 +80,17 @@ class TinyCalc < Depager::LALR::Basis
|
|
81
80
|
nil,
|
82
81
|
nil,
|
83
82
|
nil,
|
84
|
-
|
83
|
+
nil,
|
85
84
|
-1,
|
86
85
|
-2,
|
87
86
|
-4,
|
88
87
|
-5,
|
88
|
+
-8,
|
89
89
|
]
|
90
90
|
defred_after_shift_table = [
|
91
91
|
nil,
|
92
92
|
nil,
|
93
93
|
nil,
|
94
|
-
nil,
|
95
94
|
-6,
|
96
95
|
-7,
|
97
96
|
nil,
|
@@ -99,11 +98,12 @@ class TinyCalc < Depager::LALR::Basis
|
|
99
98
|
nil,
|
100
99
|
nil,
|
101
100
|
nil,
|
102
|
-
|
101
|
+
nil,
|
103
102
|
nil,
|
104
103
|
nil,
|
105
104
|
-4,
|
106
105
|
-5,
|
106
|
+
-8,
|
107
107
|
]
|
108
108
|
### Nonterm to Int
|
109
109
|
nt2i = {
|
@@ -119,24 +119,206 @@ class TinyCalc < Depager::LALR::Basis
|
|
119
119
|
]
|
120
120
|
### Goto Table
|
121
121
|
goto_table = [
|
122
|
-
[ 2, 3,
|
123
|
-
[ 6, 3, 4, ],
|
122
|
+
[ 1, 2, 3, ],
|
124
123
|
[ nil, nil, nil, ],
|
125
124
|
[ nil, nil, nil, ],
|
126
125
|
[ nil, nil, nil, ],
|
127
126
|
[ nil, nil, nil, ],
|
128
|
-
[
|
129
|
-
[ nil,
|
130
|
-
[ nil,
|
127
|
+
[ 10, 2, 3, ],
|
128
|
+
[ nil, 11, 3, ],
|
129
|
+
[ nil, 12, 3, ],
|
130
|
+
[ nil, nil, 13, ],
|
131
131
|
[ nil, nil, 14, ],
|
132
|
-
[ nil, nil, 15, ],
|
133
132
|
[ nil, nil, nil, ],
|
134
133
|
[ nil, nil, nil, ],
|
135
134
|
[ nil, nil, nil, ],
|
136
135
|
[ nil, nil, nil, ],
|
137
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 4
|
154
|
+
'(' shift, and goto to state 5
|
155
|
+
|
156
|
+
|
157
|
+
----------
|
158
|
+
|
159
|
+
<<'----------',
|
160
|
+
I001 =
|
161
|
+
( 0) $start : expr _
|
162
|
+
( 1) expr : expr _ '+' term
|
163
|
+
( 2) expr : expr _ '-' term
|
164
|
+
|
165
|
+
'+' shift, and goto to state 6
|
166
|
+
'-' shift, and goto to state 7
|
167
|
+
|
168
|
+
|
169
|
+
$end accept
|
170
|
+
|
171
|
+
----------
|
172
|
+
|
173
|
+
<<'----------',
|
174
|
+
I002 =
|
175
|
+
( 3) expr : term _
|
176
|
+
( 4) term : term _ '*' fact
|
177
|
+
( 5) term : term _ '/' fact
|
178
|
+
|
179
|
+
'*' shift, and goto to state 8
|
180
|
+
'/' shift, and goto to state 9
|
181
|
+
|
182
|
+
$default reduce using rule 3 (expr)
|
183
|
+
|
184
|
+
----------
|
185
|
+
|
186
|
+
<<'----------',
|
187
|
+
I003 =
|
188
|
+
( 6) term : fact _
|
189
|
+
|
190
|
+
|
191
|
+
$default reduce using rule 6 (term) [after shift]
|
192
|
+
|
193
|
+
----------
|
194
|
+
|
195
|
+
<<'----------',
|
196
|
+
I004 =
|
197
|
+
( 7) fact : NUM _
|
198
|
+
|
199
|
+
|
200
|
+
$default reduce using rule 7 (fact) [after shift]
|
201
|
+
|
202
|
+
----------
|
203
|
+
|
204
|
+
<<'----------',
|
205
|
+
I005 =
|
206
|
+
( 8) fact : '(' _ expr ')'
|
207
|
+
|
208
|
+
NUM shift, and goto to state 4
|
209
|
+
'(' shift, and goto to state 5
|
210
|
+
|
211
|
+
|
212
|
+
----------
|
213
|
+
|
214
|
+
<<'----------',
|
215
|
+
I006 =
|
216
|
+
( 1) expr : expr '+' _ term
|
217
|
+
|
218
|
+
NUM shift, and goto to state 4
|
219
|
+
'(' shift, and goto to state 5
|
220
|
+
|
221
|
+
|
222
|
+
----------
|
223
|
+
|
224
|
+
<<'----------',
|
225
|
+
I007 =
|
226
|
+
( 2) expr : expr '-' _ term
|
227
|
+
|
228
|
+
NUM shift, and goto to state 4
|
229
|
+
'(' shift, and goto to state 5
|
230
|
+
|
231
|
+
|
232
|
+
----------
|
233
|
+
|
234
|
+
<<'----------',
|
235
|
+
I008 =
|
236
|
+
( 4) term : term '*' _ fact
|
237
|
+
|
238
|
+
NUM shift, and goto to state 4
|
239
|
+
'(' shift, and goto to state 5
|
240
|
+
|
241
|
+
|
242
|
+
----------
|
243
|
+
|
244
|
+
<<'----------',
|
245
|
+
I009 =
|
246
|
+
( 5) term : term '/' _ fact
|
247
|
+
|
248
|
+
NUM shift, and goto to state 4
|
249
|
+
'(' shift, and goto to state 5
|
250
|
+
|
251
|
+
|
252
|
+
----------
|
253
|
+
|
254
|
+
<<'----------',
|
255
|
+
I010 =
|
256
|
+
( 8) fact : '(' expr _ ')'
|
257
|
+
( 1) expr : expr _ '+' term
|
258
|
+
( 2) expr : expr _ '-' term
|
259
|
+
|
260
|
+
'+' shift, and goto to state 6
|
261
|
+
'-' shift, and goto to state 7
|
262
|
+
')' shift, and goto to state 15
|
263
|
+
|
264
|
+
|
265
|
+
----------
|
266
|
+
|
267
|
+
<<'----------',
|
268
|
+
I011 =
|
269
|
+
( 1) expr : expr '+' term _
|
270
|
+
( 4) term : term _ '*' fact
|
271
|
+
( 5) term : term _ '/' fact
|
272
|
+
|
273
|
+
'*' shift, and goto to state 8
|
274
|
+
'/' shift, and goto to state 9
|
275
|
+
|
276
|
+
$default reduce using rule 1 (expr)
|
277
|
+
|
278
|
+
----------
|
279
|
+
|
280
|
+
<<'----------',
|
281
|
+
I012 =
|
282
|
+
( 2) expr : expr '-' term _
|
283
|
+
( 4) term : term _ '*' fact
|
284
|
+
( 5) term : term _ '/' fact
|
285
|
+
|
286
|
+
'*' shift, and goto to state 8
|
287
|
+
'/' shift, and goto to state 9
|
288
|
+
|
289
|
+
$default reduce using rule 2 (expr)
|
290
|
+
|
291
|
+
----------
|
292
|
+
|
293
|
+
<<'----------',
|
294
|
+
I013 =
|
295
|
+
( 4) term : term '*' fact _
|
296
|
+
|
297
|
+
|
298
|
+
$default reduce using rule 4 (term) [after shift]
|
299
|
+
|
300
|
+
----------
|
301
|
+
|
302
|
+
<<'----------',
|
303
|
+
I014 =
|
304
|
+
( 5) term : term '/' fact _
|
305
|
+
|
306
|
+
|
307
|
+
$default reduce using rule 5 (term) [after shift]
|
308
|
+
|
309
|
+
----------
|
310
|
+
|
311
|
+
<<'----------',
|
312
|
+
I015 =
|
313
|
+
( 8) fact : '(' expr ')' _
|
314
|
+
|
315
|
+
|
316
|
+
$default reduce using rule 8 (fact) [after shift]
|
317
|
+
|
318
|
+
----------
|
138
319
|
]
|
139
320
|
|
321
|
+
|
140
322
|
Tables = [ reduce_table, nparams, action_table,
|
141
323
|
defred_table, defred_after_shift_table, goto_table,
|
142
324
|
t2i, i2t, nt2i, i2nt ]
|
@@ -186,69 +368,61 @@ end
|
|
186
368
|
|
187
369
|
class Visitor
|
188
370
|
|
189
|
-
module_eval <<-'.,.,
|
190
|
-
|
371
|
+
module_eval <<-'.,.,120998293447553.,.,', 'sample_calc/calc.cst.dr', 23
|
372
|
+
def visit_Node_expr_0 node
|
191
373
|
node.value = node.expr.value + node.term.value
|
192
374
|
|
193
|
-
|
194
|
-
|
195
|
-
.,.,118754109035322.,.,
|
375
|
+
end
|
376
|
+
.,.,120998293447553.,.,
|
196
377
|
|
197
|
-
module_eval <<-'.,.,
|
198
|
-
|
378
|
+
module_eval <<-'.,.,1209982934266.,.,', 'sample_calc/calc.cst.dr', 24
|
379
|
+
def visit_Node_expr_1 node
|
199
380
|
node.value = node.expr.value + node.term.value
|
200
381
|
|
201
|
-
|
202
|
-
|
203
|
-
.,.,118754109055219.,.,
|
382
|
+
end
|
383
|
+
.,.,1209982934266.,.,
|
204
384
|
|
205
|
-
module_eval <<-'.,.,
|
206
|
-
|
385
|
+
module_eval <<-'.,.,120998293442645.,.,', 'sample_calc/calc.cst.dr', 25
|
386
|
+
def visit_Node_expr_2 node
|
207
387
|
node.value = node.term.value
|
208
388
|
|
209
|
-
|
210
|
-
|
211
|
-
.,.,118754109026591.,.,
|
389
|
+
end
|
390
|
+
.,.,120998293442645.,.,
|
212
391
|
|
213
|
-
module_eval <<-'.,.,
|
214
|
-
|
392
|
+
module_eval <<-'.,.,120998293449169.,.,', 'sample_calc/calc.cst.dr', 28
|
393
|
+
def visit_Node_term_0 node
|
215
394
|
node.value = node.term.value * node.fact.value
|
216
395
|
|
217
|
-
|
218
|
-
|
219
|
-
.,.,118754109017048.,.,
|
396
|
+
end
|
397
|
+
.,.,120998293449169.,.,
|
220
398
|
|
221
|
-
module_eval <<-'.,.,
|
222
|
-
|
399
|
+
module_eval <<-'.,.,12099829345606.,.,', 'sample_calc/calc.cst.dr', 29
|
400
|
+
def visit_Node_term_1 node
|
223
401
|
node.value = node.term.value / node.fact.value
|
224
402
|
|
225
|
-
|
226
|
-
|
227
|
-
.,.,118754109059012.,.,
|
403
|
+
end
|
404
|
+
.,.,12099829345606.,.,
|
228
405
|
|
229
|
-
module_eval <<-'.,.,
|
230
|
-
|
406
|
+
module_eval <<-'.,.,120998293417529.,.,', 'sample_calc/calc.cst.dr', 30
|
407
|
+
def visit_Node_term_2 node
|
231
408
|
node.value = node.fact.value
|
232
409
|
|
233
|
-
|
234
|
-
|
235
|
-
.,.,118754109013457.,.,
|
410
|
+
end
|
411
|
+
.,.,120998293417529.,.,
|
236
412
|
|
237
|
-
module_eval <<-'.,.,
|
238
|
-
|
413
|
+
module_eval <<-'.,.,12099829345810.,.,', 'sample_calc/calc.cst.dr', 33
|
414
|
+
def visit_Node_fact_0 node
|
239
415
|
node.value = node.num.value
|
240
416
|
|
241
|
-
|
242
|
-
|
243
|
-
.,.,118754109020434.,.,
|
417
|
+
end
|
418
|
+
.,.,12099829345810.,.,
|
244
419
|
|
245
|
-
module_eval <<-'.,.,
|
246
|
-
|
420
|
+
module_eval <<-'.,.,120998293441876.,.,', 'sample_calc/calc.cst.dr', 34
|
421
|
+
def visit_Node_fact_1 node
|
247
422
|
node.value = node.expr
|
248
423
|
|
249
|
-
|
250
|
-
|
251
|
-
.,.,118754109063699.,.,
|
424
|
+
end
|
425
|
+
.,.,120998293441876.,.,
|
252
426
|
|
253
427
|
end
|
254
428
|
|
@@ -380,7 +554,7 @@ v.visit_Node_fact_1(self)
|
|
380
554
|
|
381
555
|
class D4TinyCalc::CSTBuilder < Depager::LALR::Action #:nodoc:all
|
382
556
|
include Depager::DecoratorUtils
|
383
|
-
|
557
|
+
[]
|
384
558
|
on_reduce = [
|
385
559
|
nil,
|
386
560
|
:_cst_0,
|
@@ -401,61 +575,53 @@ class D4TinyCalc::CSTBuilder < Depager::LALR::Action #:nodoc:all
|
|
401
575
|
end
|
402
576
|
|
403
577
|
|
404
|
-
module_eval <<-'.,.,
|
405
|
-
|
578
|
+
module_eval <<-'.,.,120998293417689.,.,', 'sample_calc/calc.cst.dr', 23
|
579
|
+
def _cst_0 val
|
406
580
|
Node_expr_0.new(val[0], val[1], val[2])
|
407
|
-
|
408
|
-
|
409
|
-
.,.,118754109050531.,.,
|
581
|
+
end
|
582
|
+
.,.,120998293417689.,.,
|
410
583
|
|
411
|
-
module_eval <<-'.,.,
|
412
|
-
|
584
|
+
module_eval <<-'.,.,120998293460542.,.,', 'sample_calc/calc.cst.dr', 24
|
585
|
+
def _cst_1 val
|
413
586
|
Node_expr_1.new(val[0], val[1], val[2])
|
414
|
-
|
415
|
-
|
416
|
-
.,.,118754109039698.,.,
|
587
|
+
end
|
588
|
+
.,.,120998293460542.,.,
|
417
589
|
|
418
|
-
module_eval <<-'.,.,
|
419
|
-
|
590
|
+
module_eval <<-'.,.,12099829348426.,.,', 'sample_calc/calc.cst.dr', 25
|
591
|
+
def _cst_2 val
|
420
592
|
Node_expr_2.new(val[0])
|
421
|
-
|
422
|
-
|
423
|
-
.,.,1187541090475.,.,
|
593
|
+
end
|
594
|
+
.,.,12099829348426.,.,
|
424
595
|
|
425
|
-
module_eval <<-'.,.,
|
426
|
-
|
596
|
+
module_eval <<-'.,.,120998293430701.,.,', 'sample_calc/calc.cst.dr', 28
|
597
|
+
def _cst_3 val
|
427
598
|
Node_term_0.new(val[0], val[1], val[2])
|
428
|
-
|
429
|
-
|
430
|
-
.,.,118754109053937.,.,
|
599
|
+
end
|
600
|
+
.,.,120998293430701.,.,
|
431
601
|
|
432
|
-
module_eval <<-'.,.,
|
433
|
-
|
602
|
+
module_eval <<-'.,.,120998293449360.,.,', 'sample_calc/calc.cst.dr', 29
|
603
|
+
def _cst_4 val
|
434
604
|
Node_term_1.new(val[0], val[1], val[2])
|
435
|
-
|
436
|
-
|
437
|
-
.,.,118754109039336.,.,
|
605
|
+
end
|
606
|
+
.,.,120998293449360.,.,
|
438
607
|
|
439
|
-
module_eval <<-'.,.,
|
440
|
-
|
608
|
+
module_eval <<-'.,.,120998293440225.,.,', 'sample_calc/calc.cst.dr', 30
|
609
|
+
def _cst_5 val
|
441
610
|
Node_term_2.new(val[0])
|
442
|
-
|
443
|
-
|
444
|
-
.,.,118754109031052.,.,
|
611
|
+
end
|
612
|
+
.,.,120998293440225.,.,
|
445
613
|
|
446
|
-
module_eval <<-'.,.,
|
447
|
-
|
614
|
+
module_eval <<-'.,.,120998293456355.,.,', 'sample_calc/calc.cst.dr', 33
|
615
|
+
def _cst_6 val
|
448
616
|
Node_fact_0.new(val[0])
|
449
|
-
|
450
|
-
|
451
|
-
.,.,11875410903088.,.,
|
617
|
+
end
|
618
|
+
.,.,120998293456355.,.,
|
452
619
|
|
453
|
-
module_eval <<-'.,.,
|
454
|
-
|
620
|
+
module_eval <<-'.,.,120998293443146.,.,', 'sample_calc/calc.cst.dr', 34
|
621
|
+
def _cst_7 val
|
455
622
|
Node_fact_1.new(val[0], val[1], val[2])
|
456
|
-
|
457
|
-
|
458
|
-
.,.,11875410905263.,.,
|
623
|
+
end
|
624
|
+
.,.,120998293443146.,.,
|
459
625
|
|
460
626
|
end
|
461
627
|
|