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
@@ -14,11 +14,11 @@
|
|
14
14
|
%AST{
|
15
15
|
Node [value] { @value = nil }
|
16
16
|
Visitor { }
|
17
|
-
add(left, right) {
|
18
|
-
sub(left, right) {
|
19
|
-
mul(left, right) {
|
20
|
-
div(left, right) {
|
21
|
-
literal(-n) {
|
17
|
+
add(left, right) { $.value = $.left.value + $.right.value }
|
18
|
+
sub(left, right) { $.value = $.left.value - $.right.value }
|
19
|
+
mul(left, right) { $.value = $.left.value * $.right.value }
|
20
|
+
div(left, right) { $.value = $.left.value / $.right.value }
|
21
|
+
literal(-n) { $.value = $.n.value }
|
22
22
|
%}
|
23
23
|
|
24
24
|
#begin-rule
|
@@ -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,17 +119,17 @@ class TinyCalc < Depager::LALR::Basis
|
|
119
119
|
]
|
120
120
|
### Goto Table
|
121
121
|
goto_table = [
|
122
|
-
[ 2, 3,
|
123
|
-
[ 6, 3, 4, ],
|
124
|
-
[ nil, nil, nil, ],
|
122
|
+
[ 1, 2, 3, ],
|
125
123
|
[ nil, nil, nil, ],
|
126
124
|
[ nil, nil, nil, ],
|
127
125
|
[ nil, nil, nil, ],
|
128
126
|
[ nil, nil, nil, ],
|
129
|
-
[
|
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,
|
132
|
+
[ nil, nil, nil, ],
|
133
133
|
[ nil, nil, nil, ],
|
134
134
|
[ nil, nil, nil, ],
|
135
135
|
[ nil, nil, nil, ],
|
@@ -137,6 +137,188 @@ class TinyCalc < Depager::LALR::Basis
|
|
137
137
|
[ nil, nil, nil, ],
|
138
138
|
]
|
139
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
|
+
----------
|
319
|
+
]
|
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 ]
|
@@ -179,207 +361,236 @@ end
|
|
179
361
|
|
180
362
|
### Outer Code
|
181
363
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
364
|
+
class Node
|
365
|
+
attr_accessor :lineno
|
366
|
+
attr_accessor :value
|
367
|
+
|
186
368
|
def initialize
|
187
369
|
@value = nil
|
188
370
|
|
189
371
|
end
|
190
372
|
|
191
|
-
|
192
|
-
|
193
|
-
end
|
194
|
-
def self.[] lineno, *args
|
195
|
-
self.new lineno, *args
|
196
|
-
end
|
197
|
-
def accept v
|
198
|
-
end
|
373
|
+
def self.[] lineno, *args
|
374
|
+
self.new lineno, *args
|
199
375
|
end
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
def value
|
214
|
-
@lst.map{|i| "i.value"}
|
215
|
-
end
|
216
|
-
|
217
|
-
def push(i) @lst.push i; self; end
|
218
|
-
def concat(i) @lst.concat i; self; end
|
219
|
-
def map(&b) @lst.map(&b); end
|
220
|
-
def to_ary() @lst; end
|
221
|
-
def accept(v)
|
222
|
-
@lst.each{|i| i.accept(v) }
|
223
|
-
end
|
376
|
+
def accept v
|
377
|
+
end
|
378
|
+
end
|
379
|
+
class NodeList < Node
|
380
|
+
attr_accessor :lineno
|
381
|
+
def initialize(lineno, lst=[])
|
382
|
+
@lineno = lineno
|
383
|
+
@lst = lst.to_a.select{|i| ! i.is_a?(NilNode)}
|
384
|
+
end
|
385
|
+
|
386
|
+
def all_value
|
387
|
+
@lst.map{|i| i.value}
|
224
388
|
end
|
389
|
+
|
390
|
+
def size
|
391
|
+
@lst.size
|
392
|
+
end
|
393
|
+
alias length size
|
394
|
+
def push(i)
|
395
|
+
@lst.push i unless i.is_a? NilNode
|
396
|
+
self
|
397
|
+
end
|
398
|
+
def concat(i)
|
399
|
+
@lst.concat i
|
400
|
+
self
|
401
|
+
end
|
402
|
+
def to_ary()
|
403
|
+
@lst
|
404
|
+
end
|
405
|
+
alias to_a to_ary
|
406
|
+
alias list to_ary
|
407
|
+
def accept(v)
|
408
|
+
@lst.each{|i| i.accept(v) }
|
409
|
+
end
|
410
|
+
end
|
411
|
+
class NilNode
|
412
|
+
attr_accessor :lineno
|
413
|
+
attr_accessor :value
|
414
|
+
def initialize(lineno, *args)
|
415
|
+
@lineno = lineno
|
416
|
+
end
|
417
|
+
def accept v
|
418
|
+
end
|
419
|
+
end
|
225
420
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
421
|
+
|
422
|
+
class Node_add < Node
|
423
|
+
attr_accessor :left, :right
|
424
|
+
attr_accessor
|
425
|
+
def initialize lineno, left, right
|
426
|
+
super()
|
427
|
+
@lineno = lineno
|
428
|
+
@lineno = lineno
|
233
429
|
@left = left
|
234
430
|
@right = right
|
235
431
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
432
|
+
end
|
433
|
+
def accept v
|
434
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
435
|
+
@left.accept(v)
|
240
436
|
@right.accept(v)
|
241
437
|
|
242
|
-
|
243
|
-
|
244
|
-
end
|
438
|
+
v.visit_Node_add(self)
|
439
|
+
self
|
245
440
|
end
|
441
|
+
end
|
246
442
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
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
|
254
450
|
@left = left
|
255
451
|
@right = right
|
256
452
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
453
|
+
end
|
454
|
+
def accept v
|
455
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
456
|
+
@left.accept(v)
|
261
457
|
@right.accept(v)
|
262
458
|
|
263
|
-
|
264
|
-
|
265
|
-
end
|
459
|
+
v.visit_Node_sub(self)
|
460
|
+
self
|
266
461
|
end
|
462
|
+
end
|
267
463
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
464
|
+
class Node_mul < Node
|
465
|
+
attr_accessor :left, :right
|
466
|
+
attr_accessor
|
467
|
+
def initialize lineno, left, right
|
468
|
+
super()
|
469
|
+
@lineno = lineno
|
470
|
+
@lineno = lineno
|
275
471
|
@left = left
|
276
472
|
@right = right
|
277
473
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
474
|
+
end
|
475
|
+
def accept v
|
476
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
477
|
+
@left.accept(v)
|
282
478
|
@right.accept(v)
|
283
479
|
|
284
|
-
|
285
|
-
|
286
|
-
end
|
480
|
+
v.visit_Node_mul(self)
|
481
|
+
self
|
287
482
|
end
|
483
|
+
end
|
288
484
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
485
|
+
class Node_div < Node
|
486
|
+
attr_accessor :left, :right
|
487
|
+
attr_accessor
|
488
|
+
def initialize lineno, left, right
|
489
|
+
super()
|
490
|
+
@lineno = lineno
|
491
|
+
@lineno = lineno
|
296
492
|
@left = left
|
297
493
|
@right = right
|
298
494
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
495
|
+
end
|
496
|
+
def accept v
|
497
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
498
|
+
@left.accept(v)
|
303
499
|
@right.accept(v)
|
304
500
|
|
305
|
-
|
306
|
-
|
307
|
-
end
|
501
|
+
v.visit_Node_div(self)
|
502
|
+
self
|
308
503
|
end
|
504
|
+
end
|
309
505
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
506
|
+
class Node_literal < Node
|
507
|
+
attr_accessor :n
|
508
|
+
attr_accessor :n
|
509
|
+
def initialize lineno, n
|
510
|
+
super()
|
511
|
+
@lineno = lineno
|
512
|
+
@lineno = lineno
|
317
513
|
@n = n
|
318
514
|
|
319
|
-
end
|
320
|
-
def accept v
|
321
|
-
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
322
|
-
|
323
|
-
v.visit_Node_literal(self)
|
324
|
-
self
|
325
|
-
end
|
326
515
|
end
|
516
|
+
def accept v
|
517
|
+
warn @lineno.to_s+':'+self.class.to_s if $DEBUG
|
518
|
+
|
519
|
+
v.visit_Node_literal(self)
|
520
|
+
self
|
521
|
+
end
|
522
|
+
end
|
327
523
|
|
328
524
|
class Visitor
|
329
525
|
def visit node
|
330
526
|
node.accept(self)
|
331
527
|
end
|
332
528
|
|
333
|
-
module_eval <<-'.,.,
|
529
|
+
module_eval <<-'.,.,120998293320397.,.,', 'sample_calc/calc.astdf.dr', 16
|
334
530
|
|
335
531
|
|
336
|
-
.,.,
|
532
|
+
.,.,120998293320397.,.,
|
337
533
|
|
338
|
-
module_eval <<-'.,.,
|
339
|
-
|
534
|
+
module_eval <<-'.,.,120998293317058.,.,', 'sample_calc/calc.astdf.dr', 16
|
535
|
+
def visit_Node_add node
|
340
536
|
node.value = node.left.value + node.right.value
|
341
537
|
|
342
|
-
|
343
|
-
|
344
|
-
|
538
|
+
rescue
|
539
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
540
|
+
raise
|
541
|
+
|
542
|
+
end
|
543
|
+
.,.,120998293317058.,.,
|
345
544
|
|
346
|
-
module_eval <<-'.,.,
|
347
|
-
|
545
|
+
module_eval <<-'.,.,12099829337992.,.,', 'sample_calc/calc.astdf.dr', 17
|
546
|
+
def visit_Node_sub node
|
348
547
|
node.value = node.left.value - node.right.value
|
349
548
|
|
350
|
-
|
351
|
-
|
352
|
-
|
549
|
+
rescue
|
550
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
551
|
+
raise
|
552
|
+
|
553
|
+
end
|
554
|
+
.,.,12099829337992.,.,
|
353
555
|
|
354
|
-
module_eval <<-'.,.,
|
355
|
-
|
556
|
+
module_eval <<-'.,.,12099829331479.,.,', 'sample_calc/calc.astdf.dr', 18
|
557
|
+
def visit_Node_mul node
|
356
558
|
node.value = node.left.value * node.right.value
|
357
559
|
|
358
|
-
|
359
|
-
|
360
|
-
|
560
|
+
rescue
|
561
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
562
|
+
raise
|
563
|
+
|
564
|
+
end
|
565
|
+
.,.,12099829331479.,.,
|
361
566
|
|
362
|
-
module_eval <<-'.,.,
|
363
|
-
|
567
|
+
module_eval <<-'.,.,120998293356650.,.,', 'sample_calc/calc.astdf.dr', 19
|
568
|
+
def visit_Node_div node
|
364
569
|
node.value = node.left.value / node.right.value
|
365
570
|
|
366
|
-
|
367
|
-
|
368
|
-
|
571
|
+
rescue
|
572
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
573
|
+
raise
|
574
|
+
|
575
|
+
end
|
576
|
+
.,.,120998293356650.,.,
|
369
577
|
|
370
|
-
module_eval <<-'.,.,
|
371
|
-
|
578
|
+
module_eval <<-'.,.,120998293349915.,.,', 'sample_calc/calc.astdf.dr', 20
|
579
|
+
def visit_Node_literal node
|
372
580
|
node.value = node.n.value
|
373
581
|
|
374
|
-
|
375
|
-
|
376
|
-
|
582
|
+
rescue
|
583
|
+
warn "raise at src:#{node.lineno}/#{node.class.name}"
|
584
|
+
raise
|
585
|
+
|
586
|
+
end
|
587
|
+
.,.,120998293349915.,.,
|
377
588
|
|
378
589
|
end
|
379
590
|
|
380
591
|
class D4TinyCalc::ASTBuilderDepthFirst < Depager::LALR::Action #:nodoc:all
|
381
592
|
include Depager::DecoratorUtils
|
382
|
-
|
593
|
+
[]
|
383
594
|
on_reduce = [
|
384
595
|
nil,
|
385
596
|
:_ast_0,
|
@@ -400,61 +611,53 @@ class D4TinyCalc::ASTBuilderDepthFirst < Depager::LALR::Action #:nodoc:all
|
|
400
611
|
end
|
401
612
|
|
402
613
|
|
403
|
-
module_eval <<-'.,.,
|
404
|
-
|
614
|
+
module_eval <<-'.,.,12099829331599.,.,', 'sample_calc/calc.astdf.dr', 26
|
615
|
+
def _ast_0 val
|
405
616
|
Node_add.new(val[0].lineno, val[0], val[2])
|
406
|
-
|
407
|
-
|
408
|
-
.,.,118754108836976.,.,
|
617
|
+
end
|
618
|
+
.,.,12099829331599.,.,
|
409
619
|
|
410
|
-
module_eval <<-'.,.,
|
411
|
-
|
620
|
+
module_eval <<-'.,.,12099829338068.,.,', 'sample_calc/calc.astdf.dr', 28
|
621
|
+
def _ast_1 val
|
412
622
|
Node_sub.new(val[0].lineno, val[0], val[2])
|
413
|
-
|
414
|
-
|
415
|
-
.,.,118754108859323.,.,
|
623
|
+
end
|
624
|
+
.,.,12099829338068.,.,
|
416
625
|
|
417
|
-
module_eval <<-'.,.,
|
418
|
-
|
626
|
+
module_eval <<-'.,.,12099829334432.,.,', 'sample_calc/calc.astdf.dr', 30
|
627
|
+
def _ast_2 val
|
419
628
|
val[0]
|
420
|
-
|
421
|
-
|
422
|
-
.,.,11875410886924.,.,
|
629
|
+
end
|
630
|
+
.,.,12099829334432.,.,
|
423
631
|
|
424
|
-
module_eval <<-'.,.,
|
425
|
-
|
632
|
+
module_eval <<-'.,.,120998293324156.,.,', 'sample_calc/calc.astdf.dr', 34
|
633
|
+
def _ast_3 val
|
426
634
|
Node_mul.new(val[0].lineno, val[0], val[2])
|
427
|
-
|
428
|
-
|
429
|
-
.,.,118754108848739.,.,
|
635
|
+
end
|
636
|
+
.,.,120998293324156.,.,
|
430
637
|
|
431
|
-
module_eval <<-'.,.,
|
432
|
-
|
638
|
+
module_eval <<-'.,.,120998293347721.,.,', 'sample_calc/calc.astdf.dr', 36
|
639
|
+
def _ast_4 val
|
433
640
|
Node_div.new(val[0].lineno, val[0], val[2])
|
434
|
-
|
435
|
-
|
436
|
-
.,.,118754108840033.,.,
|
641
|
+
end
|
642
|
+
.,.,120998293347721.,.,
|
437
643
|
|
438
|
-
module_eval <<-'.,.,
|
439
|
-
|
644
|
+
module_eval <<-'.,.,120998293340404.,.,', 'sample_calc/calc.astdf.dr', 38
|
645
|
+
def _ast_5 val
|
440
646
|
val[0]
|
441
|
-
|
442
|
-
|
443
|
-
.,.,118754108834371.,.,
|
647
|
+
end
|
648
|
+
.,.,120998293340404.,.,
|
444
649
|
|
445
|
-
module_eval <<-'.,.,
|
446
|
-
|
650
|
+
module_eval <<-'.,.,120998293339461.,.,', 'sample_calc/calc.astdf.dr', 42
|
651
|
+
def _ast_6 val
|
447
652
|
Node_literal.new(val[0].lineno, val[0])
|
448
|
-
|
449
|
-
|
450
|
-
.,.,118754108849607.,.,
|
653
|
+
end
|
654
|
+
.,.,120998293339461.,.,
|
451
655
|
|
452
|
-
module_eval <<-'.,.,
|
453
|
-
|
656
|
+
module_eval <<-'.,.,120998293325172.,.,', 'sample_calc/calc.astdf.dr', 44
|
657
|
+
def _ast_7 val
|
454
658
|
val[1]
|
455
|
-
|
456
|
-
|
457
|
-
.,.,118754108811811.,.,
|
659
|
+
end
|
660
|
+
.,.,120998293325172.,.,
|
458
661
|
|
459
662
|
end
|
460
663
|
|