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
@@ -50,25 +50,26 @@ class TinyCalc < Depager::LALR::Basis
|
|
50
50
|
]
|
51
51
|
### Action Table
|
52
52
|
action_table = [
|
53
|
-
[ nil, nil, nil, nil, nil, nil,
|
54
|
-
[
|
55
|
-
[
|
53
|
+
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
54
|
+
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
55
|
+
[ ACC, nil, 7, 8, nil, nil, nil, nil, nil, ],
|
56
|
+
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
56
57
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
57
58
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
58
|
-
[ nil, nil,
|
59
|
-
[ nil, nil, nil, nil, nil, nil,
|
60
|
-
[ nil, nil, nil, nil, nil, nil,
|
61
|
-
[ nil, nil, nil, nil, nil, nil,
|
62
|
-
[ nil, nil, nil, nil, nil, nil,
|
63
|
-
[ nil, nil, 6, 7, nil, nil, nil, nil, 15, ],
|
64
|
-
[ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
|
65
|
-
[ nil, nil, nil, nil, 8, 9, nil, nil, nil, ],
|
59
|
+
[ nil, nil, 7, 8, nil, nil, nil, nil, 11, ],
|
60
|
+
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
61
|
+
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
62
|
+
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
63
|
+
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
66
64
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
65
|
+
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
66
|
+
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
67
67
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
68
68
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
69
69
|
]
|
70
70
|
### Default Reduce Table
|
71
71
|
defred_table = [
|
72
|
+
nil,
|
72
73
|
nil,
|
73
74
|
nil,
|
74
75
|
-3,
|
@@ -79,17 +80,17 @@ class TinyCalc < Depager::LALR::Basis
|
|
79
80
|
nil,
|
80
81
|
nil,
|
81
82
|
nil,
|
82
|
-
|
83
|
+
-8,
|
83
84
|
-1,
|
84
85
|
-2,
|
85
86
|
-4,
|
86
87
|
-5,
|
87
|
-
-8,
|
88
88
|
]
|
89
89
|
defred_after_shift_table = [
|
90
90
|
nil,
|
91
91
|
nil,
|
92
92
|
nil,
|
93
|
+
nil,
|
93
94
|
-6,
|
94
95
|
-7,
|
95
96
|
nil,
|
@@ -97,12 +98,11 @@ class TinyCalc < Depager::LALR::Basis
|
|
97
98
|
nil,
|
98
99
|
nil,
|
99
100
|
nil,
|
100
|
-
|
101
|
+
-8,
|
101
102
|
nil,
|
102
103
|
nil,
|
103
104
|
-4,
|
104
105
|
-5,
|
105
|
-
-8,
|
106
106
|
]
|
107
107
|
### Nonterm to Int
|
108
108
|
nt2i = {
|
@@ -118,17 +118,17 @@ class TinyCalc < Depager::LALR::Basis
|
|
118
118
|
]
|
119
119
|
### Goto Table
|
120
120
|
goto_table = [
|
121
|
-
[
|
121
|
+
[ 2, 3, 4, ],
|
122
|
+
[ 6, 3, 4, ],
|
122
123
|
[ nil, nil, nil, ],
|
123
124
|
[ nil, nil, nil, ],
|
124
125
|
[ nil, nil, nil, ],
|
125
126
|
[ nil, nil, nil, ],
|
126
|
-
[ 10, 2, 3, ],
|
127
|
-
[ nil, 11, 3, ],
|
128
|
-
[ nil, 12, 3, ],
|
129
|
-
[ nil, nil, 13, ],
|
130
|
-
[ nil, nil, 14, ],
|
131
127
|
[ nil, nil, nil, ],
|
128
|
+
[ nil, 12, 4, ],
|
129
|
+
[ nil, 13, 4, ],
|
130
|
+
[ nil, nil, 14, ],
|
131
|
+
[ nil, nil, 15, ],
|
132
132
|
[ nil, nil, nil, ],
|
133
133
|
[ nil, nil, nil, ],
|
134
134
|
[ nil, nil, nil, ],
|
@@ -149,20 +149,30 @@ class TinyCalc < Depager::LALR::Basis
|
|
149
149
|
I000 =
|
150
150
|
( 0) $start : _ expr
|
151
151
|
|
152
|
-
NUM shift, and goto to state
|
153
|
-
'(' shift, and goto to state
|
152
|
+
NUM shift, and goto to state 5
|
153
|
+
'(' shift, and goto to state 1
|
154
154
|
|
155
155
|
|
156
156
|
----------
|
157
157
|
|
158
158
|
<<'----------',
|
159
159
|
I001 =
|
160
|
+
( 8) fact : '(' _ expr ')'
|
161
|
+
|
162
|
+
NUM shift, and goto to state 5
|
163
|
+
'(' shift, and goto to state 1
|
164
|
+
|
165
|
+
|
166
|
+
----------
|
167
|
+
|
168
|
+
<<'----------',
|
169
|
+
I002 =
|
160
170
|
( 0) $start : expr _
|
161
171
|
( 1) expr : expr _ '+' term
|
162
172
|
( 2) expr : expr _ '-' term
|
163
173
|
|
164
|
-
'+' shift, and goto to state
|
165
|
-
'-' shift, and goto to state
|
174
|
+
'+' shift, and goto to state 7
|
175
|
+
'-' shift, and goto to state 8
|
166
176
|
|
167
177
|
|
168
178
|
$end accept
|
@@ -170,20 +180,20 @@ I001 =
|
|
170
180
|
----------
|
171
181
|
|
172
182
|
<<'----------',
|
173
|
-
|
183
|
+
I003 =
|
174
184
|
( 3) expr : term _
|
175
185
|
( 4) term : term _ '*' fact
|
176
186
|
( 5) term : term _ '/' fact
|
177
187
|
|
178
|
-
'*' shift, and goto to state
|
179
|
-
'/' shift, and goto to state
|
188
|
+
'*' shift, and goto to state 9
|
189
|
+
'/' shift, and goto to state 10
|
180
190
|
|
181
191
|
$default reduce using rule 3 (expr)
|
182
192
|
|
183
193
|
----------
|
184
194
|
|
185
195
|
<<'----------',
|
186
|
-
|
196
|
+
I004 =
|
187
197
|
( 6) term : fact _
|
188
198
|
|
189
199
|
|
@@ -192,7 +202,7 @@ I003 =
|
|
192
202
|
----------
|
193
203
|
|
194
204
|
<<'----------',
|
195
|
-
|
205
|
+
I005 =
|
196
206
|
( 7) fact : NUM _
|
197
207
|
|
198
208
|
|
@@ -201,96 +211,95 @@ I004 =
|
|
201
211
|
----------
|
202
212
|
|
203
213
|
<<'----------',
|
204
|
-
|
205
|
-
( 8) fact : '(' _
|
214
|
+
I006 =
|
215
|
+
( 8) fact : '(' expr _ ')'
|
216
|
+
( 1) expr : expr _ '+' term
|
217
|
+
( 2) expr : expr _ '-' term
|
206
218
|
|
207
|
-
|
208
|
-
'
|
219
|
+
'+' shift, and goto to state 7
|
220
|
+
'-' shift, and goto to state 8
|
221
|
+
')' shift, and goto to state 11
|
209
222
|
|
210
223
|
|
211
224
|
----------
|
212
225
|
|
213
226
|
<<'----------',
|
214
|
-
|
227
|
+
I007 =
|
215
228
|
( 1) expr : expr '+' _ term
|
216
229
|
|
217
|
-
NUM shift, and goto to state
|
218
|
-
'(' shift, and goto to state
|
230
|
+
NUM shift, and goto to state 5
|
231
|
+
'(' shift, and goto to state 1
|
219
232
|
|
220
233
|
|
221
234
|
----------
|
222
235
|
|
223
236
|
<<'----------',
|
224
|
-
|
237
|
+
I008 =
|
225
238
|
( 2) expr : expr '-' _ term
|
226
239
|
|
227
|
-
NUM shift, and goto to state
|
228
|
-
'(' shift, and goto to state
|
240
|
+
NUM shift, and goto to state 5
|
241
|
+
'(' shift, and goto to state 1
|
229
242
|
|
230
243
|
|
231
244
|
----------
|
232
245
|
|
233
246
|
<<'----------',
|
234
|
-
|
247
|
+
I009 =
|
235
248
|
( 4) term : term '*' _ fact
|
236
249
|
|
237
|
-
NUM shift, and goto to state
|
238
|
-
'(' shift, and goto to state
|
250
|
+
NUM shift, and goto to state 5
|
251
|
+
'(' shift, and goto to state 1
|
239
252
|
|
240
253
|
|
241
254
|
----------
|
242
255
|
|
243
256
|
<<'----------',
|
244
|
-
|
257
|
+
I010 =
|
245
258
|
( 5) term : term '/' _ fact
|
246
259
|
|
247
|
-
NUM shift, and goto to state
|
248
|
-
'(' shift, and goto to state
|
260
|
+
NUM shift, and goto to state 5
|
261
|
+
'(' shift, and goto to state 1
|
249
262
|
|
250
263
|
|
251
264
|
----------
|
252
265
|
|
253
266
|
<<'----------',
|
254
|
-
|
255
|
-
( 8) fact : '(' expr
|
256
|
-
( 1) expr : expr _ '+' term
|
257
|
-
( 2) expr : expr _ '-' term
|
267
|
+
I011 =
|
268
|
+
( 8) fact : '(' expr ')' _
|
258
269
|
|
259
|
-
'+' shift, and goto to state 6
|
260
|
-
'-' shift, and goto to state 7
|
261
|
-
')' shift, and goto to state 15
|
262
270
|
|
271
|
+
$default reduce using rule 8 (fact) [after shift]
|
263
272
|
|
264
273
|
----------
|
265
274
|
|
266
275
|
<<'----------',
|
267
|
-
|
276
|
+
I012 =
|
268
277
|
( 1) expr : expr '+' term _
|
269
278
|
( 4) term : term _ '*' fact
|
270
279
|
( 5) term : term _ '/' fact
|
271
280
|
|
272
|
-
'*' shift, and goto to state
|
273
|
-
'/' shift, and goto to state
|
281
|
+
'*' shift, and goto to state 9
|
282
|
+
'/' shift, and goto to state 10
|
274
283
|
|
275
284
|
$default reduce using rule 1 (expr)
|
276
285
|
|
277
286
|
----------
|
278
287
|
|
279
288
|
<<'----------',
|
280
|
-
|
289
|
+
I013 =
|
281
290
|
( 2) expr : expr '-' term _
|
282
291
|
( 4) term : term _ '*' fact
|
283
292
|
( 5) term : term _ '/' fact
|
284
293
|
|
285
|
-
'*' shift, and goto to state
|
286
|
-
'/' shift, and goto to state
|
294
|
+
'*' shift, and goto to state 9
|
295
|
+
'/' shift, and goto to state 10
|
287
296
|
|
288
297
|
$default reduce using rule 2 (expr)
|
289
298
|
|
290
299
|
----------
|
291
300
|
|
292
301
|
<<'----------',
|
293
|
-
|
302
|
+
I014 =
|
294
303
|
( 4) term : term '*' fact _
|
295
304
|
|
296
305
|
|
@@ -299,21 +308,12 @@ I013 =
|
|
299
308
|
----------
|
300
309
|
|
301
310
|
<<'----------',
|
302
|
-
|
311
|
+
I015 =
|
303
312
|
( 5) term : term '/' fact _
|
304
313
|
|
305
314
|
|
306
315
|
$default reduce using rule 5 (term) [after shift]
|
307
316
|
|
308
|
-
----------
|
309
|
-
|
310
|
-
<<'----------',
|
311
|
-
I015 =
|
312
|
-
( 8) fact : '(' expr ')' _
|
313
|
-
|
314
|
-
|
315
|
-
$default reduce using rule 8 (fact) [after shift]
|
316
|
-
|
317
317
|
----------
|
318
318
|
]
|
319
319
|
|
@@ -360,6 +360,6 @@ end
|
|
360
360
|
if __FILE__ == $0
|
361
361
|
### Main Code
|
362
362
|
parser = TinyCalc.new()
|
363
|
-
parser.
|
363
|
+
parser.parse(STDIN)
|
364
364
|
|
365
365
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
%class TinyCalc
|
2
|
-
%extend Lexer ('
|
3
|
-
%extend NVAction ('
|
2
|
+
%extend Lexer ('plugins/lex.rb')
|
3
|
+
%extend NVAction ('plugins/nvaction.rb')
|
4
4
|
%decorate @NVAction
|
5
|
-
#%decorate ShiftReducePrinter ('
|
5
|
+
#%decorate ShiftReducePrinter ('plugins/srp.rb')
|
6
6
|
%prec{
|
7
7
|
left '*' '/'
|
8
8
|
left '+' '-'
|
@@ -11,8 +11,8 @@
|
|
11
11
|
|
12
12
|
%LEX{
|
13
13
|
/\s+/, /\#.*/ { }
|
14
|
-
/[1-9][0-9]*/ { yield
|
15
|
-
/./ { yield
|
14
|
+
/[1-9][0-9]*/ { yield token(:NUM, $&.to_i) }
|
15
|
+
/./ { yield token($&, $&) }
|
16
16
|
%}
|
17
17
|
|
18
18
|
#begin-rule
|
@@ -27,5 +27,5 @@
|
|
27
27
|
#end-rule
|
28
28
|
%%
|
29
29
|
parser = createDecoratedTinyCalc
|
30
|
-
r, = parser.
|
30
|
+
r, = parser.parse(STDIN)
|
31
31
|
puts r
|
@@ -50,18 +50,18 @@ class TinyCalc < Depager::LALR::Basis
|
|
50
50
|
### Action Table
|
51
51
|
action_table = [
|
52
52
|
[ nil, nil, nil, nil, nil, nil, 2, nil, 3, ],
|
53
|
-
[ ACC, nil, 4, 5, 6,
|
53
|
+
[ ACC, nil, 7, 4, 5, 6, nil, nil, nil, ],
|
54
54
|
[ nil, nil, nil, nil, nil, nil, 2, nil, 3, ],
|
55
55
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
56
56
|
[ nil, nil, nil, nil, nil, nil, 2, nil, 3, ],
|
57
57
|
[ nil, nil, nil, nil, nil, nil, 2, nil, 3, ],
|
58
58
|
[ nil, nil, nil, nil, nil, nil, 2, nil, 3, ],
|
59
59
|
[ nil, nil, nil, nil, nil, nil, 2, nil, 3, ],
|
60
|
-
[ nil, nil, 4, 5, 6,
|
61
|
-
[ nil, nil, nil, nil,
|
62
|
-
[ nil, nil, nil, nil, 6, 7, nil, nil, nil, ],
|
60
|
+
[ nil, nil, 7, 4, 5, 6, nil, 13, nil, ],
|
61
|
+
[ nil, nil, nil, nil, 5, 6, nil, nil, nil, ],
|
63
62
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
64
63
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
64
|
+
[ nil, nil, nil, nil, 5, 6, nil, nil, nil, ],
|
65
65
|
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
66
66
|
]
|
67
67
|
### Default Reduce Table
|
@@ -75,10 +75,10 @@ class TinyCalc < Depager::LALR::Basis
|
|
75
75
|
nil,
|
76
76
|
nil,
|
77
77
|
nil,
|
78
|
-
-1,
|
79
78
|
-2,
|
80
79
|
-3,
|
81
80
|
-4,
|
81
|
+
-1,
|
82
82
|
-5,
|
83
83
|
]
|
84
84
|
defred_after_shift_table = [
|
@@ -92,9 +92,9 @@ class TinyCalc < Depager::LALR::Basis
|
|
92
92
|
nil,
|
93
93
|
nil,
|
94
94
|
nil,
|
95
|
-
nil,
|
96
95
|
-3,
|
97
96
|
-4,
|
97
|
+
nil,
|
98
98
|
-5,
|
99
99
|
]
|
100
100
|
### Nonterm to Int
|
@@ -150,10 +150,10 @@ I001 =
|
|
150
150
|
( 3) expr : expr _ '*' expr
|
151
151
|
( 4) expr : expr _ '/' expr
|
152
152
|
|
153
|
-
'+' shift, and goto to state
|
154
|
-
'-' shift, and goto to state
|
155
|
-
'*' shift, and goto to state
|
156
|
-
'/' shift, and goto to state
|
153
|
+
'+' shift, and goto to state 7
|
154
|
+
'-' shift, and goto to state 4
|
155
|
+
'*' shift, and goto to state 5
|
156
|
+
'/' shift, and goto to state 6
|
157
157
|
|
158
158
|
|
159
159
|
$end accept
|
@@ -181,7 +181,7 @@ I003 =
|
|
181
181
|
|
182
182
|
<<'----------',
|
183
183
|
I004 =
|
184
|
-
(
|
184
|
+
( 2) expr : expr '-' _ expr
|
185
185
|
|
186
186
|
'(' shift, and goto to state 2
|
187
187
|
NUM shift, and goto to state 3
|
@@ -191,7 +191,7 @@ I004 =
|
|
191
191
|
|
192
192
|
<<'----------',
|
193
193
|
I005 =
|
194
|
-
(
|
194
|
+
( 3) expr : expr '*' _ expr
|
195
195
|
|
196
196
|
'(' shift, and goto to state 2
|
197
197
|
NUM shift, and goto to state 3
|
@@ -201,7 +201,7 @@ I005 =
|
|
201
201
|
|
202
202
|
<<'----------',
|
203
203
|
I006 =
|
204
|
-
(
|
204
|
+
( 4) expr : expr '/' _ expr
|
205
205
|
|
206
206
|
'(' shift, and goto to state 2
|
207
207
|
NUM shift, and goto to state 3
|
@@ -211,7 +211,7 @@ I006 =
|
|
211
211
|
|
212
212
|
<<'----------',
|
213
213
|
I007 =
|
214
|
-
(
|
214
|
+
( 1) expr : expr '+' _ expr
|
215
215
|
|
216
216
|
'(' shift, and goto to state 2
|
217
217
|
NUM shift, and goto to state 3
|
@@ -227,10 +227,10 @@ I008 =
|
|
227
227
|
( 3) expr : expr _ '*' expr
|
228
228
|
( 4) expr : expr _ '/' expr
|
229
229
|
|
230
|
-
'+' shift, and goto to state
|
231
|
-
'-' shift, and goto to state
|
232
|
-
'*' shift, and goto to state
|
233
|
-
'/' shift, and goto to state
|
230
|
+
'+' shift, and goto to state 7
|
231
|
+
'-' shift, and goto to state 4
|
232
|
+
'*' shift, and goto to state 5
|
233
|
+
'/' shift, and goto to state 6
|
234
234
|
')' shift, and goto to state 13
|
235
235
|
|
236
236
|
|
@@ -238,57 +238,57 @@ I008 =
|
|
238
238
|
|
239
239
|
<<'----------',
|
240
240
|
I009 =
|
241
|
-
(
|
241
|
+
( 2) expr : expr '-' expr _
|
242
242
|
( 1) expr : expr _ '+' expr
|
243
243
|
( 2) expr : expr _ '-' expr
|
244
244
|
( 3) expr : expr _ '*' expr
|
245
245
|
( 4) expr : expr _ '/' expr
|
246
246
|
|
247
|
-
'*' shift, and goto to state
|
248
|
-
'/' shift, and goto to state
|
247
|
+
'*' shift, and goto to state 5
|
248
|
+
'/' shift, and goto to state 6
|
249
249
|
|
250
|
-
$default reduce using rule
|
250
|
+
$default reduce using rule 2 (expr)
|
251
251
|
|
252
252
|
----------
|
253
253
|
|
254
254
|
<<'----------',
|
255
255
|
I010 =
|
256
|
-
(
|
256
|
+
( 3) expr : expr '*' expr _
|
257
257
|
( 1) expr : expr _ '+' expr
|
258
258
|
( 2) expr : expr _ '-' expr
|
259
259
|
( 3) expr : expr _ '*' expr
|
260
260
|
( 4) expr : expr _ '/' expr
|
261
261
|
|
262
|
-
'*' shift, and goto to state 6
|
263
|
-
'/' shift, and goto to state 7
|
264
262
|
|
265
|
-
$default reduce using rule
|
263
|
+
$default reduce using rule 3 (expr) [after shift]
|
266
264
|
|
267
265
|
----------
|
268
266
|
|
269
267
|
<<'----------',
|
270
268
|
I011 =
|
271
|
-
(
|
269
|
+
( 4) expr : expr '/' expr _
|
272
270
|
( 1) expr : expr _ '+' expr
|
273
271
|
( 2) expr : expr _ '-' expr
|
274
272
|
( 3) expr : expr _ '*' expr
|
275
273
|
( 4) expr : expr _ '/' expr
|
276
274
|
|
277
275
|
|
278
|
-
$default reduce using rule
|
276
|
+
$default reduce using rule 4 (expr) [after shift]
|
279
277
|
|
280
278
|
----------
|
281
279
|
|
282
280
|
<<'----------',
|
283
281
|
I012 =
|
284
|
-
(
|
282
|
+
( 1) expr : expr '+' expr _
|
285
283
|
( 1) expr : expr _ '+' expr
|
286
284
|
( 2) expr : expr _ '-' expr
|
287
285
|
( 3) expr : expr _ '*' expr
|
288
286
|
( 4) expr : expr _ '/' expr
|
289
287
|
|
288
|
+
'*' shift, and goto to state 5
|
289
|
+
'/' shift, and goto to state 6
|
290
290
|
|
291
|
-
$default reduce using rule
|
291
|
+
$default reduce using rule 1 (expr)
|
292
292
|
|
293
293
|
----------
|
294
294
|
|
@@ -325,12 +325,12 @@ I013 =
|
|
325
325
|
|
326
326
|
when /\A[1-9][0-9]*/
|
327
327
|
@oldline = @line; @line = $'
|
328
|
-
yield
|
328
|
+
yield token(:NUM, $&.to_i)
|
329
329
|
|
330
330
|
|
331
331
|
when /\A./
|
332
332
|
@oldline = @line; @line = $'
|
333
|
-
yield
|
333
|
+
yield token($&, $&)
|
334
334
|
|
335
335
|
|
336
336
|
else
|
@@ -347,7 +347,7 @@ end
|
|
347
347
|
|
348
348
|
class D4TinyCalc::NVAction < Depager::LALR::Action #:nodoc:all
|
349
349
|
include Depager::DecoratorUtils
|
350
|
-
|
350
|
+
|
351
351
|
on_reduce = [
|
352
352
|
nil,
|
353
353
|
:_act_0,
|
@@ -366,53 +366,53 @@ class D4TinyCalc::NVAction < Depager::LALR::Action #:nodoc:all
|
|
366
366
|
end
|
367
367
|
|
368
368
|
|
369
|
-
module_eval <<-'.,.,
|
369
|
+
module_eval <<-'.,.,122745803936127.,.,', 'sample_calc/calc_prec.nvaction.dr', 18
|
370
370
|
def _act_0 val
|
371
371
|
_left, _, _right, = *val
|
372
372
|
_left + _right
|
373
373
|
|
374
374
|
end
|
375
|
-
.,.,
|
375
|
+
.,.,122745803936127.,.,
|
376
376
|
|
377
|
-
module_eval <<-'.,.,
|
377
|
+
module_eval <<-'.,.,122745803916018.,.,', 'sample_calc/calc_prec.nvaction.dr', 19
|
378
378
|
def _act_1 val
|
379
379
|
_left, _, _right, = *val
|
380
380
|
_left - _right
|
381
381
|
|
382
382
|
end
|
383
|
-
.,.,
|
383
|
+
.,.,122745803916018.,.,
|
384
384
|
|
385
|
-
module_eval <<-'.,.,
|
385
|
+
module_eval <<-'.,.,122745803947193.,.,', 'sample_calc/calc_prec.nvaction.dr', 20
|
386
386
|
def _act_2 val
|
387
387
|
_left, _, _right, = *val
|
388
388
|
_left * _right
|
389
389
|
|
390
390
|
end
|
391
|
-
.,.,
|
391
|
+
.,.,122745803947193.,.,
|
392
392
|
|
393
|
-
module_eval <<-'.,.,
|
393
|
+
module_eval <<-'.,.,122745803925953.,.,', 'sample_calc/calc_prec.nvaction.dr', 21
|
394
394
|
def _act_3 val
|
395
395
|
_left, _, _right, = *val
|
396
396
|
_left / _right
|
397
397
|
|
398
398
|
end
|
399
|
-
.,.,
|
399
|
+
.,.,122745803925953.,.,
|
400
400
|
|
401
|
-
module_eval <<-'.,.,
|
401
|
+
module_eval <<-'.,.,122745803965385.,.,', 'sample_calc/calc_prec.nvaction.dr', 22
|
402
402
|
def _act_4 val
|
403
403
|
_, _expr, _, = *val
|
404
404
|
_expr
|
405
405
|
|
406
406
|
end
|
407
|
-
.,.,
|
407
|
+
.,.,122745803965385.,.,
|
408
408
|
|
409
|
-
module_eval <<-'.,.,
|
409
|
+
module_eval <<-'.,.,12274580397259.,.,', 'sample_calc/calc_prec.nvaction.dr', 23
|
410
410
|
def _act_5 val
|
411
411
|
_NUM, = *val
|
412
412
|
_NUM.value
|
413
413
|
|
414
414
|
end
|
415
|
-
.,.,
|
415
|
+
.,.,12274580397259.,.,
|
416
416
|
|
417
417
|
end
|
418
418
|
|
@@ -425,7 +425,7 @@ end
|
|
425
425
|
if __FILE__ == $0
|
426
426
|
### Main Code
|
427
427
|
parser = createDecoratedTinyCalc
|
428
|
-
r, = parser.
|
428
|
+
r, = parser.parse(STDIN)
|
429
429
|
puts r
|
430
430
|
|
431
431
|
end
|