depager 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
|
|
@@ -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 ]
|
@@ -181,7 +363,7 @@ end
|
|
181
363
|
|
182
364
|
class D4TinyCalc::Action < Depager::LALR::Action #:nodoc:all
|
183
365
|
include Depager::DecoratorUtils
|
184
|
-
|
366
|
+
[]
|
185
367
|
on_reduce = [
|
186
368
|
nil,
|
187
369
|
:_act_0,
|
@@ -202,69 +384,61 @@ class D4TinyCalc::Action < Depager::LALR::Action #:nodoc:all
|
|
202
384
|
end
|
203
385
|
|
204
386
|
|
205
|
-
module_eval <<-'.,.,
|
206
|
-
|
387
|
+
module_eval <<-'.,.,120998293115109.,.,', 'sample_calc/calc.action.dr', 15
|
388
|
+
def _act_0 val
|
207
389
|
val[0] + val[2]
|
208
390
|
|
209
|
-
|
210
|
-
|
211
|
-
.,.,118754108827289.,.,
|
391
|
+
end
|
392
|
+
.,.,120998293115109.,.,
|
212
393
|
|
213
|
-
module_eval <<-'.,.,
|
214
|
-
|
394
|
+
module_eval <<-'.,.,12099829312650.,.,', 'sample_calc/calc.action.dr', 16
|
395
|
+
def _act_1 val
|
215
396
|
val[0] - val[2]
|
216
397
|
|
217
|
-
|
218
|
-
|
219
|
-
.,.,118754108850101.,.,
|
398
|
+
end
|
399
|
+
.,.,12099829312650.,.,
|
220
400
|
|
221
|
-
module_eval <<-'.,.,
|
222
|
-
|
401
|
+
module_eval <<-'.,.,12099829313489.,.,', 'sample_calc/calc.action.dr', 17
|
402
|
+
def _act_2 val
|
223
403
|
val[0]
|
224
404
|
|
225
|
-
|
226
|
-
|
227
|
-
.,.,118754108859938.,.,
|
405
|
+
end
|
406
|
+
.,.,12099829313489.,.,
|
228
407
|
|
229
|
-
module_eval <<-'.,.,
|
230
|
-
|
408
|
+
module_eval <<-'.,.,120998293125343.,.,', 'sample_calc/calc.action.dr', 20
|
409
|
+
def _act_3 val
|
231
410
|
val[0] * val[2]
|
232
411
|
|
233
|
-
|
234
|
-
|
235
|
-
.,.,118754108817909.,.,
|
412
|
+
end
|
413
|
+
.,.,120998293125343.,.,
|
236
414
|
|
237
|
-
module_eval <<-'.,.,
|
238
|
-
|
415
|
+
module_eval <<-'.,.,120998293141013.,.,', 'sample_calc/calc.action.dr', 21
|
416
|
+
def _act_4 val
|
239
417
|
val[0] / val[2]
|
240
418
|
|
241
|
-
|
242
|
-
|
243
|
-
.,.,11875410886381.,.,
|
419
|
+
end
|
420
|
+
.,.,120998293141013.,.,
|
244
421
|
|
245
|
-
module_eval <<-'.,.,
|
246
|
-
|
422
|
+
module_eval <<-'.,.,120998293143307.,.,', 'sample_calc/calc.action.dr', 22
|
423
|
+
def _act_5 val
|
247
424
|
val[0]
|
248
425
|
|
249
|
-
|
250
|
-
|
251
|
-
.,.,118754108815401.,.,
|
426
|
+
end
|
427
|
+
.,.,120998293143307.,.,
|
252
428
|
|
253
|
-
module_eval <<-'.,.,
|
254
|
-
|
429
|
+
module_eval <<-'.,.,120998293124180.,.,', 'sample_calc/calc.action.dr', 25
|
430
|
+
def _act_6 val
|
255
431
|
val[0].value
|
256
432
|
|
257
|
-
|
258
|
-
|
259
|
-
.,.,118754108820197.,.,
|
433
|
+
end
|
434
|
+
.,.,120998293124180.,.,
|
260
435
|
|
261
|
-
module_eval <<-'.,.,
|
262
|
-
|
436
|
+
module_eval <<-'.,.,120998293127174.,.,', 'sample_calc/calc.action.dr', 26
|
437
|
+
def _act_7 val
|
263
438
|
val[1]
|
264
439
|
|
265
|
-
|
266
|
-
|
267
|
-
.,.,11875410882848.,.,
|
440
|
+
end
|
441
|
+
.,.,120998293127174.,.,
|
268
442
|
|
269
443
|
end
|
270
444
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
%class TinyCalc
|
2
2
|
%extend Lexer ('depager/lex.rb')
|
3
|
-
%extend
|
3
|
+
%extend ASTBuilder ('depager/ast.rb')
|
4
4
|
%extend Action ('depager/action.rb')
|
5
|
-
%decorate @
|
5
|
+
%decorate @ASTBuilder
|
6
6
|
%decorate @Action
|
7
7
|
#%decorate ShiftReducePrinter ('depager/srp.rb')
|
8
8
|
%mixin Depager
|
@@ -17,11 +17,11 @@
|
|
17
17
|
%AST{
|
18
18
|
Node [value] { @value = nil }
|
19
19
|
Visitor { }
|
20
|
-
add(left, right) {
|
21
|
-
sub(left, right) {
|
22
|
-
mul(left, right) {
|
23
|
-
div(left, right) {
|
24
|
-
literal(-n) {
|
20
|
+
add(left, right) { $.value = visit($.left).value + visit($.right).value }
|
21
|
+
sub(left, right) { $.value = visit($.left).value - visit($.right).value }
|
22
|
+
mul(left, right) { $.value = visit($.left).value * visit($.right).value }
|
23
|
+
div(left, right) { $.value = visit($.left).value / visit($.right).value }
|
24
|
+
literal(-n) { $.value = $.n.value }
|
25
25
|
%}
|
26
26
|
|
27
27
|
#begin-rule
|
@@ -0,0 +1,755 @@
|
|
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
|
+
'ASTBuilder' => 2,
|
28
|
+
'Action' => 3,
|
29
|
+
}
|
30
|
+
### Term to Int
|
31
|
+
t2i = {
|
32
|
+
nil => 0,
|
33
|
+
false => 1,
|
34
|
+
"+" => 2,
|
35
|
+
"-" => 3,
|
36
|
+
"*" => 4,
|
37
|
+
"/" => 5,
|
38
|
+
:NUM => 6,
|
39
|
+
"(" => 7,
|
40
|
+
")" => 8,
|
41
|
+
}
|
42
|
+
### Int to Term
|
43
|
+
i2t = [
|
44
|
+
nil,
|
45
|
+
false,
|
46
|
+
"+",
|
47
|
+
"-",
|
48
|
+
"*",
|
49
|
+
"/",
|
50
|
+
:NUM,
|
51
|
+
"(",
|
52
|
+
")",
|
53
|
+
]
|
54
|
+
### Action Table
|
55
|
+
action_table = [
|
56
|
+
[ nil, nil, nil, nil, nil, nil, 4, 5, nil, ],
|
57
|
+
[ ACC, nil, 6, 7, nil, nil, nil, nil, nil, ],
|
58
|
+
[ nil, nil, nil, nil, 8, 9, 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, 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, nil, nil, nil, nil, 4, 5, nil, ],
|
66
|
+
[ nil, nil, 6, 7, nil, nil, nil, nil, 15, ],
|
67
|
+
[ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
|
68
|
+
[ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
|
69
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
70
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
71
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
72
|
+
]
|
73
|
+
### Default Reduce Table
|
74
|
+
defred_table = [
|
75
|
+
nil,
|
76
|
+
nil,
|
77
|
+
-3,
|
78
|
+
-6,
|
79
|
+
-7,
|
80
|
+
nil,
|
81
|
+
nil,
|
82
|
+
nil,
|
83
|
+
nil,
|
84
|
+
nil,
|
85
|
+
nil,
|
86
|
+
-1,
|
87
|
+
-2,
|
88
|
+
-4,
|
89
|
+
-5,
|
90
|
+
-8,
|
91
|
+
]
|
92
|
+
defred_after_shift_table = [
|
93
|
+
nil,
|
94
|
+
nil,
|
95
|
+
nil,
|
96
|
+
-6,
|
97
|
+
-7,
|
98
|
+
nil,
|
99
|
+
nil,
|
100
|
+
nil,
|
101
|
+
nil,
|
102
|
+
nil,
|
103
|
+
nil,
|
104
|
+
nil,
|
105
|
+
nil,
|
106
|
+
-4,
|
107
|
+
-5,
|
108
|
+
-8,
|
109
|
+
]
|
110
|
+
### Nonterm to Int
|
111
|
+
nt2i = {
|
112
|
+
:expr => 0,
|
113
|
+
:term => 1,
|
114
|
+
:fact => 2,
|
115
|
+
}
|
116
|
+
### Int to Nonterm
|
117
|
+
i2nt = [
|
118
|
+
:expr,
|
119
|
+
:term,
|
120
|
+
:fact,
|
121
|
+
]
|
122
|
+
### Goto Table
|
123
|
+
goto_table = [
|
124
|
+
[ 1, 2, 3, ],
|
125
|
+
[ nil, nil, nil, ],
|
126
|
+
[ nil, nil, nil, ],
|
127
|
+
[ nil, nil, nil, ],
|
128
|
+
[ nil, nil, nil, ],
|
129
|
+
[ 10, 2, 3, ],
|
130
|
+
[ nil, 11, 3, ],
|
131
|
+
[ nil, 12, 3, ],
|
132
|
+
[ nil, nil, 13, ],
|
133
|
+
[ nil, nil, 14, ],
|
134
|
+
[ nil, nil, nil, ],
|
135
|
+
[ nil, nil, nil, ],
|
136
|
+
[ nil, nil, nil, ],
|
137
|
+
[ nil, nil, nil, ],
|
138
|
+
[ nil, nil, nil, ],
|
139
|
+
[ nil, nil, nil, ],
|
140
|
+
]
|
141
|
+
|
142
|
+
|
143
|
+
alias orig_error error
|
144
|
+
def error
|
145
|
+
orig_error
|
146
|
+
warn "current state: #{StateInfo[@stack.last]}"
|
147
|
+
end
|
148
|
+
|
149
|
+
### States
|
150
|
+
StateInfo = [
|
151
|
+
<<'----------',
|
152
|
+
I000 =
|
153
|
+
( 0) $start : _ expr
|
154
|
+
|
155
|
+
NUM shift, and goto to state 4
|
156
|
+
'(' shift, and goto to state 5
|
157
|
+
|
158
|
+
|
159
|
+
----------
|
160
|
+
|
161
|
+
<<'----------',
|
162
|
+
I001 =
|
163
|
+
( 0) $start : expr _
|
164
|
+
( 1) expr : expr _ '+' term
|
165
|
+
( 2) expr : expr _ '-' term
|
166
|
+
|
167
|
+
'+' shift, and goto to state 6
|
168
|
+
'-' shift, and goto to state 7
|
169
|
+
|
170
|
+
|
171
|
+
$end accept
|
172
|
+
|
173
|
+
----------
|
174
|
+
|
175
|
+
<<'----------',
|
176
|
+
I002 =
|
177
|
+
( 3) expr : term _
|
178
|
+
( 4) term : term _ '*' fact
|
179
|
+
( 5) term : term _ '/' fact
|
180
|
+
|
181
|
+
'*' shift, and goto to state 8
|
182
|
+
'/' shift, and goto to state 9
|
183
|
+
|
184
|
+
$default reduce using rule 3 (expr)
|
185
|
+
|
186
|
+
----------
|
187
|
+
|
188
|
+
<<'----------',
|
189
|
+
I003 =
|
190
|
+
( 6) term : fact _
|
191
|
+
|
192
|
+
|
193
|
+
$default reduce using rule 6 (term) [after shift]
|
194
|
+
|
195
|
+
----------
|
196
|
+
|
197
|
+
<<'----------',
|
198
|
+
I004 =
|
199
|
+
( 7) fact : NUM _
|
200
|
+
|
201
|
+
|
202
|
+
$default reduce using rule 7 (fact) [after shift]
|
203
|
+
|
204
|
+
----------
|
205
|
+
|
206
|
+
<<'----------',
|
207
|
+
I005 =
|
208
|
+
( 8) fact : '(' _ expr ')'
|
209
|
+
|
210
|
+
NUM shift, and goto to state 4
|
211
|
+
'(' shift, and goto to state 5
|
212
|
+
|
213
|
+
|
214
|
+
----------
|
215
|
+
|
216
|
+
<<'----------',
|
217
|
+
I006 =
|
218
|
+
( 1) expr : expr '+' _ term
|
219
|
+
|
220
|
+
NUM shift, and goto to state 4
|
221
|
+
'(' shift, and goto to state 5
|
222
|
+
|
223
|
+
|
224
|
+
----------
|
225
|
+
|
226
|
+
<<'----------',
|
227
|
+
I007 =
|
228
|
+
( 2) expr : expr '-' _ term
|
229
|
+
|
230
|
+
NUM shift, and goto to state 4
|
231
|
+
'(' shift, and goto to state 5
|
232
|
+
|
233
|
+
|
234
|
+
----------
|
235
|
+
|
236
|
+
<<'----------',
|
237
|
+
I008 =
|
238
|
+
( 4) term : term '*' _ fact
|
239
|
+
|
240
|
+
NUM shift, and goto to state 4
|
241
|
+
'(' shift, and goto to state 5
|
242
|
+
|
243
|
+
|
244
|
+
----------
|
245
|
+
|
246
|
+
<<'----------',
|
247
|
+
I009 =
|
248
|
+
( 5) term : term '/' _ fact
|
249
|
+
|
250
|
+
NUM shift, and goto to state 4
|
251
|
+
'(' shift, and goto to state 5
|
252
|
+
|
253
|
+
|
254
|
+
----------
|
255
|
+
|
256
|
+
<<'----------',
|
257
|
+
I010 =
|
258
|
+
( 8) fact : '(' expr _ ')'
|
259
|
+
( 1) expr : expr _ '+' term
|
260
|
+
( 2) expr : expr _ '-' term
|
261
|
+
|
262
|
+
'+' shift, and goto to state 6
|
263
|
+
'-' shift, and goto to state 7
|
264
|
+
')' shift, and goto to state 15
|
265
|
+
|
266
|
+
|
267
|
+
----------
|
268
|
+
|
269
|
+
<<'----------',
|
270
|
+
I011 =
|
271
|
+
( 1) expr : expr '+' term _
|
272
|
+
( 4) term : term _ '*' fact
|
273
|
+
( 5) term : term _ '/' fact
|
274
|
+
|
275
|
+
'*' shift, and goto to state 8
|
276
|
+
'/' shift, and goto to state 9
|
277
|
+
|
278
|
+
$default reduce using rule 1 (expr)
|
279
|
+
|
280
|
+
----------
|
281
|
+
|
282
|
+
<<'----------',
|
283
|
+
I012 =
|
284
|
+
( 2) expr : expr '-' term _
|
285
|
+
( 4) term : term _ '*' fact
|
286
|
+
( 5) term : term _ '/' fact
|
287
|
+
|
288
|
+
'*' shift, and goto to state 8
|
289
|
+
'/' shift, and goto to state 9
|
290
|
+
|
291
|
+
$default reduce using rule 2 (expr)
|
292
|
+
|
293
|
+
----------
|
294
|
+
|
295
|
+
<<'----------',
|
296
|
+
I013 =
|
297
|
+
( 4) term : term '*' fact _
|
298
|
+
|
299
|
+
|
300
|
+
$default reduce using rule 4 (term) [after shift]
|
301
|
+
|
302
|
+
----------
|
303
|
+
|
304
|
+
<<'----------',
|
305
|
+
I014 =
|
306
|
+
( 5) term : term '/' fact _
|
307
|
+
|
308
|
+
|
309
|
+
$default reduce using rule 5 (term) [after shift]
|
310
|
+
|
311
|
+
----------
|
312
|
+
|
313
|
+
<<'----------',
|
314
|
+
I015 =
|
315
|
+
( 8) fact : '(' expr ')' _
|
316
|
+
|
317
|
+
|
318
|
+
$default reduce using rule 8 (fact) [after shift]
|
319
|
+
|
320
|
+
----------
|
321
|
+
]
|
322
|
+
|
323
|
+
|
324
|
+
Tables = [ reduce_table, nparams, action_table,
|
325
|
+
defred_table, defred_after_shift_table, goto_table,
|
326
|
+
t2i, i2t, nt2i, i2nt ]
|
327
|
+
|
328
|
+
def self.createDecoratedParser
|
329
|
+
D4TinyCalc::Action.new(D4TinyCalc::ASTBuilder.new(TinyCalc.new()))
|
330
|
+
end
|
331
|
+
|
332
|
+
### Inner Code
|
333
|
+
|
334
|
+
def lex
|
335
|
+
begin
|
336
|
+
until @line.empty?
|
337
|
+
case @line
|
338
|
+
|
339
|
+
when /\A\s+/, /\A\#.*/, /\A\n/
|
340
|
+
@oldline = @line; @line = $'
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
when /\A[1-9][0-9]*/
|
345
|
+
@oldline = @line; @line = $'
|
346
|
+
yield _Token(:NUM, $&.to_i)
|
347
|
+
|
348
|
+
|
349
|
+
when /\A./
|
350
|
+
@oldline = @line; @line = $'
|
351
|
+
yield _Token($&, $&)
|
352
|
+
|
353
|
+
|
354
|
+
else
|
355
|
+
raise RuntimeError, "must not happen #{@line}"
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end while @line0 = @line = getline
|
359
|
+
yield nil, nil
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
### Outer Code
|
365
|
+
|
366
|
+
class Node
|
367
|
+
attr_accessor :lineno
|
368
|
+
attr_accessor :value
|
369
|
+
|
370
|
+
def initialize
|
371
|
+
@value = nil
|
372
|
+
|
373
|
+
end
|
374
|
+
|
375
|
+
def self.[] lineno, *args
|
376
|
+
self.new lineno, *args
|
377
|
+
end
|
378
|
+
def accept v
|
379
|
+
end
|
380
|
+
end
|
381
|
+
class NodeList < Node
|
382
|
+
attr_accessor :lineno
|
383
|
+
def initialize(lineno, lst=[])
|
384
|
+
@lineno = lineno
|
385
|
+
@lst = lst.to_a.select{|i| ! i.is_a?(NilNode)}
|
386
|
+
end
|
387
|
+
|
388
|
+
def all_value
|
389
|
+
@lst.map{|i| i.value}
|
390
|
+
end
|
391
|
+
|
392
|
+
def size
|
393
|
+
@lst.size
|
394
|
+
end
|
395
|
+
alias length size
|
396
|
+
def push(i)
|
397
|
+
@lst.push i unless i.is_a? NilNode
|
398
|
+
self
|
399
|
+
end
|
400
|
+
def concat(i)
|
401
|
+
@lst.concat i
|
402
|
+
self
|
403
|
+
end
|
404
|
+
def to_ary()
|
405
|
+
@lst
|
406
|
+
end
|
407
|
+
alias to_a to_ary
|
408
|
+
alias list to_ary
|
409
|
+
def accept(v)
|
410
|
+
@lst.each{|i| i.accept(v) }
|
411
|
+
end
|
412
|
+
end
|
413
|
+
class NilNode
|
414
|
+
attr_accessor :lineno
|
415
|
+
attr_accessor :value
|
416
|
+
def initialize(lineno, *args)
|
417
|
+
@lineno = lineno
|
418
|
+
end
|
419
|
+
def accept v
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
|
424
|
+
class Node_add < Node
|
425
|
+
attr_accessor :left, :right
|
426
|
+
attr_accessor
|
427
|
+
def initialize lineno, left, right
|
428
|
+
super()
|
429
|
+
@lineno = lineno
|
430
|
+
@lineno = lineno
|
431
|
+
@left = left
|
432
|
+
@right = right
|
433
|
+
|
434
|
+
end
|
435
|
+
def accept v
|
436
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
437
|
+
|
438
|
+
v.visit_Node_add(self)
|
439
|
+
self
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
class Node_sub < Node
|
444
|
+
attr_accessor :left, :right
|
445
|
+
attr_accessor
|
446
|
+
def initialize lineno, left, right
|
447
|
+
super()
|
448
|
+
@lineno = lineno
|
449
|
+
@lineno = lineno
|
450
|
+
@left = left
|
451
|
+
@right = right
|
452
|
+
|
453
|
+
end
|
454
|
+
def accept v
|
455
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
456
|
+
|
457
|
+
v.visit_Node_sub(self)
|
458
|
+
self
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
class Node_mul < Node
|
463
|
+
attr_accessor :left, :right
|
464
|
+
attr_accessor
|
465
|
+
def initialize lineno, left, right
|
466
|
+
super()
|
467
|
+
@lineno = lineno
|
468
|
+
@lineno = lineno
|
469
|
+
@left = left
|
470
|
+
@right = right
|
471
|
+
|
472
|
+
end
|
473
|
+
def accept v
|
474
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
475
|
+
|
476
|
+
v.visit_Node_mul(self)
|
477
|
+
self
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
class Node_div < Node
|
482
|
+
attr_accessor :left, :right
|
483
|
+
attr_accessor
|
484
|
+
def initialize lineno, left, right
|
485
|
+
super()
|
486
|
+
@lineno = lineno
|
487
|
+
@lineno = lineno
|
488
|
+
@left = left
|
489
|
+
@right = right
|
490
|
+
|
491
|
+
end
|
492
|
+
def accept v
|
493
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
494
|
+
|
495
|
+
v.visit_Node_div(self)
|
496
|
+
self
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
class Node_literal < Node
|
501
|
+
attr_accessor :n
|
502
|
+
attr_accessor :n
|
503
|
+
def initialize lineno, n
|
504
|
+
super()
|
505
|
+
@lineno = lineno
|
506
|
+
@lineno = lineno
|
507
|
+
@n = n
|
508
|
+
|
509
|
+
end
|
510
|
+
def accept v
|
511
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
512
|
+
|
513
|
+
v.visit_Node_literal(self)
|
514
|
+
self
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
class Visitor
|
519
|
+
def visit node
|
520
|
+
node.accept(self)
|
521
|
+
end
|
522
|
+
|
523
|
+
module_eval <<-'.,.,120998293133008.,.,', 'sample_calc/calc.ast.action.dr', 19
|
524
|
+
|
525
|
+
|
526
|
+
.,.,120998293133008.,.,
|
527
|
+
|
528
|
+
module_eval <<-'.,.,120998293117496.,.,', 'sample_calc/calc.ast.action.dr', 19
|
529
|
+
def visit_Node_add node
|
530
|
+
node.value = visit(node.left).value + visit(node.right).value
|
531
|
+
|
532
|
+
rescue
|
533
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
534
|
+
raise
|
535
|
+
|
536
|
+
end
|
537
|
+
.,.,120998293117496.,.,
|
538
|
+
|
539
|
+
module_eval <<-'.,.,120998293117798.,.,', 'sample_calc/calc.ast.action.dr', 20
|
540
|
+
def visit_Node_sub node
|
541
|
+
node.value = visit(node.left).value - visit(node.right).value
|
542
|
+
|
543
|
+
rescue
|
544
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
545
|
+
raise
|
546
|
+
|
547
|
+
end
|
548
|
+
.,.,120998293117798.,.,
|
549
|
+
|
550
|
+
module_eval <<-'.,.,120998293122558.,.,', 'sample_calc/calc.ast.action.dr', 21
|
551
|
+
def visit_Node_mul node
|
552
|
+
node.value = visit(node.left).value * visit(node.right).value
|
553
|
+
|
554
|
+
rescue
|
555
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
556
|
+
raise
|
557
|
+
|
558
|
+
end
|
559
|
+
.,.,120998293122558.,.,
|
560
|
+
|
561
|
+
module_eval <<-'.,.,120998293153267.,.,', 'sample_calc/calc.ast.action.dr', 22
|
562
|
+
def visit_Node_div node
|
563
|
+
node.value = visit(node.left).value / visit(node.right).value
|
564
|
+
|
565
|
+
rescue
|
566
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
567
|
+
raise
|
568
|
+
|
569
|
+
end
|
570
|
+
.,.,120998293153267.,.,
|
571
|
+
|
572
|
+
module_eval <<-'.,.,12099829314264.,.,', 'sample_calc/calc.ast.action.dr', 23
|
573
|
+
def visit_Node_literal node
|
574
|
+
node.value = node.n.value
|
575
|
+
|
576
|
+
rescue
|
577
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
578
|
+
raise
|
579
|
+
|
580
|
+
end
|
581
|
+
.,.,12099829314264.,.,
|
582
|
+
|
583
|
+
end
|
584
|
+
|
585
|
+
class D4TinyCalc::ASTBuilder < Depager::LALR::Action #:nodoc:all
|
586
|
+
include Depager::DecoratorUtils
|
587
|
+
[]
|
588
|
+
on_reduce = [
|
589
|
+
nil,
|
590
|
+
:_ast_0,
|
591
|
+
:_ast_1,
|
592
|
+
:_ast_2,
|
593
|
+
:_ast_3,
|
594
|
+
:_ast_4,
|
595
|
+
:_ast_5,
|
596
|
+
:_ast_6,
|
597
|
+
:_ast_7,
|
598
|
+
|
599
|
+
]
|
600
|
+
Tables = [on_reduce]
|
601
|
+
def initialize inside
|
602
|
+
super inside, 'ASTBuilder'
|
603
|
+
@on_reduce, = self.class::Tables
|
604
|
+
init_parser
|
605
|
+
end
|
606
|
+
|
607
|
+
|
608
|
+
module_eval <<-'.,.,120998293152228.,.,', 'sample_calc/calc.ast.action.dr', 29
|
609
|
+
def _ast_0 val
|
610
|
+
Node_add.new(val[0].lineno, val[0], val[2])
|
611
|
+
end
|
612
|
+
.,.,120998293152228.,.,
|
613
|
+
|
614
|
+
module_eval <<-'.,.,120998293150297.,.,', 'sample_calc/calc.ast.action.dr', 32
|
615
|
+
def _ast_1 val
|
616
|
+
Node_sub.new(val[0].lineno, val[0], val[2])
|
617
|
+
end
|
618
|
+
.,.,120998293150297.,.,
|
619
|
+
|
620
|
+
module_eval <<-'.,.,120998293136559.,.,', 'sample_calc/calc.ast.action.dr', 35
|
621
|
+
def _ast_2 val
|
622
|
+
val[0]
|
623
|
+
end
|
624
|
+
.,.,120998293136559.,.,
|
625
|
+
|
626
|
+
module_eval <<-'.,.,120998293148223.,.,', 'sample_calc/calc.ast.action.dr', 40
|
627
|
+
def _ast_3 val
|
628
|
+
Node_mul.new(val[0].lineno, val[0], val[2])
|
629
|
+
end
|
630
|
+
.,.,120998293148223.,.,
|
631
|
+
|
632
|
+
module_eval <<-'.,.,120998293116882.,.,', 'sample_calc/calc.ast.action.dr', 43
|
633
|
+
def _ast_4 val
|
634
|
+
Node_div.new(val[0].lineno, val[0], val[2])
|
635
|
+
end
|
636
|
+
.,.,120998293116882.,.,
|
637
|
+
|
638
|
+
module_eval <<-'.,.,120998293121576.,.,', 'sample_calc/calc.ast.action.dr', 46
|
639
|
+
def _ast_5 val
|
640
|
+
val[0]
|
641
|
+
end
|
642
|
+
.,.,120998293121576.,.,
|
643
|
+
|
644
|
+
module_eval <<-'.,.,120998293134763.,.,', 'sample_calc/calc.ast.action.dr', 51
|
645
|
+
def _ast_6 val
|
646
|
+
Node_literal.new(val[0].lineno, val[0])
|
647
|
+
end
|
648
|
+
.,.,120998293134763.,.,
|
649
|
+
|
650
|
+
module_eval <<-'.,.,120998293114095.,.,', 'sample_calc/calc.ast.action.dr', 54
|
651
|
+
def _ast_7 val
|
652
|
+
val[1]
|
653
|
+
end
|
654
|
+
.,.,120998293114095.,.,
|
655
|
+
|
656
|
+
end
|
657
|
+
|
658
|
+
class D4TinyCalc::Action < Depager::LALR::Action #:nodoc:all
|
659
|
+
include Depager::DecoratorUtils
|
660
|
+
[" include Depager\n"]
|
661
|
+
on_reduce = [
|
662
|
+
nil,
|
663
|
+
:_act_0,
|
664
|
+
:_act_1,
|
665
|
+
:_act_2,
|
666
|
+
:_act_3,
|
667
|
+
:_act_4,
|
668
|
+
:_act_5,
|
669
|
+
:_act_6,
|
670
|
+
:_act_7,
|
671
|
+
|
672
|
+
]
|
673
|
+
Tables = [on_reduce]
|
674
|
+
def initialize inside
|
675
|
+
super inside, 'Action'
|
676
|
+
@on_reduce, = self.class::Tables
|
677
|
+
init_parser
|
678
|
+
end
|
679
|
+
|
680
|
+
|
681
|
+
module_eval <<-'.,.,120998293112277.,.,', 'sample_calc/calc.ast.action.dr', 30
|
682
|
+
def _act_0 val
|
683
|
+
val[0] + val[2]
|
684
|
+
|
685
|
+
end
|
686
|
+
.,.,120998293112277.,.,
|
687
|
+
|
688
|
+
module_eval <<-'.,.,12099829311590.,.,', 'sample_calc/calc.ast.action.dr', 33
|
689
|
+
def _act_1 val
|
690
|
+
val[0] - val[2]
|
691
|
+
|
692
|
+
end
|
693
|
+
.,.,12099829311590.,.,
|
694
|
+
|
695
|
+
module_eval <<-'.,.,120998293160717.,.,', 'sample_calc/calc.ast.action.dr', 36
|
696
|
+
def _act_2 val
|
697
|
+
val[0]
|
698
|
+
|
699
|
+
end
|
700
|
+
.,.,120998293160717.,.,
|
701
|
+
|
702
|
+
module_eval <<-'.,.,120998293161791.,.,', 'sample_calc/calc.ast.action.dr', 41
|
703
|
+
def _act_3 val
|
704
|
+
val[0] * val[2]
|
705
|
+
|
706
|
+
end
|
707
|
+
.,.,120998293161791.,.,
|
708
|
+
|
709
|
+
module_eval <<-'.,.,120998293126570.,.,', 'sample_calc/calc.ast.action.dr', 44
|
710
|
+
def _act_4 val
|
711
|
+
val[0] / val[2]
|
712
|
+
|
713
|
+
end
|
714
|
+
.,.,120998293126570.,.,
|
715
|
+
|
716
|
+
module_eval <<-'.,.,120998293164676.,.,', 'sample_calc/calc.ast.action.dr', 47
|
717
|
+
def _act_5 val
|
718
|
+
val[0]
|
719
|
+
|
720
|
+
end
|
721
|
+
.,.,120998293164676.,.,
|
722
|
+
|
723
|
+
module_eval <<-'.,.,120998293119648.,.,', 'sample_calc/calc.ast.action.dr', 52
|
724
|
+
def _act_6 val
|
725
|
+
val[0].value
|
726
|
+
|
727
|
+
end
|
728
|
+
.,.,120998293119648.,.,
|
729
|
+
|
730
|
+
module_eval <<-'.,.,120998293146539.,.,', 'sample_calc/calc.ast.action.dr', 55
|
731
|
+
def _act_7 val
|
732
|
+
val[1].value
|
733
|
+
|
734
|
+
end
|
735
|
+
.,.,120998293146539.,.,
|
736
|
+
|
737
|
+
end
|
738
|
+
|
739
|
+
|
740
|
+
def createDecoratedTinyCalc
|
741
|
+
D4TinyCalc::Action.new(D4TinyCalc::ASTBuilder.new(TinyCalc.new()))
|
742
|
+
end
|
743
|
+
|
744
|
+
### main
|
745
|
+
if __FILE__ == $0
|
746
|
+
### Main Code
|
747
|
+
require 'pp'
|
748
|
+
parser = createDecoratedTinyCalc()
|
749
|
+
t, r = parser.yyparse(STDIN)
|
750
|
+
v = Visitor.new
|
751
|
+
pp r
|
752
|
+
pp t.accept(v).value
|
753
|
+
pp t
|
754
|
+
|
755
|
+
end
|