depager 0.2.3 → 0.3.0.b20160729
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.en +4 -19
- data/README.ja +42 -79
- data/bin/depager +42 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +49 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +10 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/extension/calc.simple_action.dr +33 -0
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +44 -0
- data/examples/pl0d/pl0ds.dr +337 -334
- data/examples/pl0d/test.pl0ds +33 -33
- data/examples/rie_calc/calc.rie.dr +57 -0
- data/examples/rie_calc/test.calc +4 -0
- data/examples/rie_dcuse/dcuse.rie.dr +71 -0
- data/examples/rie_dcuse/test.dcuse +1 -0
- data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
- data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
- data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
- data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
- data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
- data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
- data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
- data/examples/rie_pl0/pl0.rie.dr +450 -0
- data/examples/rie_pl0/test.pl0 +10 -0
- data/examples/sample_calc/calc.action.dr +33 -33
- data/examples/sample_calc/calc.ast.action.dr +65 -66
- data/examples/sample_calc/calc.ast.dr +55 -55
- data/examples/sample_calc/calc.cst.dr +45 -45
- data/examples/sample_calc/calc.dr +43 -43
- data/examples/sample_calc/calc.lex.dr +29 -29
- data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
- data/examples/slex_test/divreg.slex.dr +29 -29
- data/examples/slex_test/ljoin.slex.dr +36 -36
- data/examples/slex_test/test.divreg +1 -1
- data/examples/slex_test/test.ljoin +3 -3
- data/lib/depager.rb +582 -670
- data/lib/depager/grammar.rb +256 -291
- data/lib/depager/lr.rb +574 -579
- data/lib/depager/parser.rb +282 -277
- data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
- data/lib/depager/ruby/plugins/action.rb +53 -43
- data/lib/depager/ruby/plugins/ast.dr +364 -269
- data/lib/depager/ruby/plugins/ast.rb +1367 -1308
- data/lib/depager/ruby/plugins/cst.dr +172 -180
- data/lib/depager/ruby/plugins/cst.rb +587 -626
- data/lib/depager/ruby/plugins/lex.dr +85 -89
- data/lib/depager/ruby/plugins/lex.rb +310 -336
- data/lib/depager/ruby/plugins/rie.dr +723 -0
- data/lib/depager/ruby/plugins/rie.rb +1653 -0
- data/lib/depager/ruby/plugins/slex.dr +202 -200
- data/lib/depager/ruby/plugins/slex.rb +780 -817
- data/lib/depager/ruby/plugins/srp.rb +56 -51
- data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
- data/lib/depager/utils.rb +148 -318
- data/lib/depager/version.rb +4 -3
- metadata +52 -60
- data/ChangeLog +0 -16
- data/data/depager/pre-setup.rb +0 -3
- data/examples/c89/c89.tab.rb +0 -7127
- data/examples/pl0d/pl0ds.tab.rb +0 -2698
- data/examples/sample_calc/calc.action.tab.rb +0 -457
- data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
- data/examples/sample_calc/calc.ast.tab.rb +0 -665
- data/examples/sample_calc/calc.astdf.dr +0 -54
- data/examples/sample_calc/calc.astdf.tab.rb +0 -672
- data/examples/sample_calc/calc.atree.tab.rb +0 -451
- data/examples/sample_calc/calc.cst.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.dr +0 -33
- data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
- data/examples/sample_calc/calc.tab.rb +0 -365
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
- data/examples/slex_test/divreg.slex.tab.rb +0 -303
- data/examples/slex_test/ljoin.slex.tab.rb +0 -370
- data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
- data/lib/depager/ruby/plugins/astdf.rb +0 -6
- data/lib/depager/ruby/plugins/atree.dr +0 -55
- data/lib/depager/ruby/plugins/atree.rb +0 -347
- data/lib/depager/ruby/plugins/nvaction.rb +0 -19
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
@@ -1,303 +0,0 @@
|
|
1
|
-
|
2
|
-
begin; require 'rubygems'; rescue Exception; end
|
3
|
-
require 'depager/parser.rb'
|
4
|
-
|
5
|
-
|
6
|
-
module Depager::DecoratorUtils; end
|
7
|
-
module D4StatefulLexerTest1; end
|
8
|
-
|
9
|
-
class StatefulLexerTest1 < Depager::LALR::Basis
|
10
|
-
|
11
|
-
|
12
|
-
### Reduce Table
|
13
|
-
reduce_table = [
|
14
|
-
[ -1, 1 ], # ( 0) $start : expr
|
15
|
-
[ 0, 4 ], # ( 1) expr : expr '/' __expr_0_2__ fact
|
16
|
-
[ 0, 1 ], # ( 2) expr : fact
|
17
|
-
[ 2, 0 ], # ( 3) __expr_0_2__ :
|
18
|
-
[ 1, 1 ], # ( 4) fact : REGEXP
|
19
|
-
]
|
20
|
-
### Extension Params
|
21
|
-
nparams = {
|
22
|
-
'NVAction' => 3,
|
23
|
-
'StatefulLexer' => 2,
|
24
|
-
}
|
25
|
-
### Term to Int
|
26
|
-
t2i = {
|
27
|
-
nil => 0,
|
28
|
-
false => 1,
|
29
|
-
"/" => 2,
|
30
|
-
:REGEXP => 3,
|
31
|
-
}
|
32
|
-
### Int to Term
|
33
|
-
i2t = [
|
34
|
-
nil,
|
35
|
-
false,
|
36
|
-
"/",
|
37
|
-
:REGEXP,
|
38
|
-
]
|
39
|
-
### Action Table
|
40
|
-
action_table = [
|
41
|
-
[ nil, nil, nil, 2, ],
|
42
|
-
[ ACC, nil, 4, nil, ],
|
43
|
-
[ nil, nil, nil, nil, ],
|
44
|
-
[ nil, nil, nil, nil, ],
|
45
|
-
[ nil, nil, nil, nil, ],
|
46
|
-
[ nil, nil, nil, 2, ],
|
47
|
-
[ nil, nil, nil, nil, ],
|
48
|
-
]
|
49
|
-
### Default Reduce Table
|
50
|
-
defred_table = [
|
51
|
-
nil,
|
52
|
-
nil,
|
53
|
-
-4,
|
54
|
-
-2,
|
55
|
-
-3,
|
56
|
-
nil,
|
57
|
-
-1,
|
58
|
-
]
|
59
|
-
defred_after_shift_table = [
|
60
|
-
nil,
|
61
|
-
nil,
|
62
|
-
-4,
|
63
|
-
-2,
|
64
|
-
-3,
|
65
|
-
nil,
|
66
|
-
-1,
|
67
|
-
]
|
68
|
-
### Nonterm to Int
|
69
|
-
nt2i = {
|
70
|
-
:expr => 0,
|
71
|
-
:fact => 1,
|
72
|
-
:__expr_0_2__ => 2,
|
73
|
-
}
|
74
|
-
### Int to Nonterm
|
75
|
-
i2nt = [
|
76
|
-
:expr,
|
77
|
-
:fact,
|
78
|
-
:__expr_0_2__,
|
79
|
-
]
|
80
|
-
### Goto Table
|
81
|
-
goto_table = [
|
82
|
-
[ 1, 3, nil, ],
|
83
|
-
[ nil, nil, nil, ],
|
84
|
-
[ nil, nil, nil, ],
|
85
|
-
[ nil, nil, nil, ],
|
86
|
-
[ nil, nil, 5, ],
|
87
|
-
[ nil, 6, nil, ],
|
88
|
-
[ nil, nil, nil, ],
|
89
|
-
]
|
90
|
-
|
91
|
-
|
92
|
-
alias orig_error error
|
93
|
-
def error
|
94
|
-
orig_error
|
95
|
-
warn "current state: #{StateInfo[@stack.last]}"
|
96
|
-
end
|
97
|
-
|
98
|
-
### States
|
99
|
-
StateInfo = [
|
100
|
-
<<'----------',
|
101
|
-
I000 =
|
102
|
-
( 0) $start : _ expr
|
103
|
-
|
104
|
-
REGEXP shift, and goto to state 2
|
105
|
-
|
106
|
-
|
107
|
-
----------
|
108
|
-
|
109
|
-
<<'----------',
|
110
|
-
I001 =
|
111
|
-
( 0) $start : expr _
|
112
|
-
( 1) expr : expr _ '/' __expr_0_2__ fact
|
113
|
-
|
114
|
-
'/' shift, and goto to state 4
|
115
|
-
|
116
|
-
|
117
|
-
$end accept
|
118
|
-
|
119
|
-
----------
|
120
|
-
|
121
|
-
<<'----------',
|
122
|
-
I002 =
|
123
|
-
( 4) fact : REGEXP _
|
124
|
-
|
125
|
-
|
126
|
-
$default reduce using rule 4 (fact) [after shift]
|
127
|
-
|
128
|
-
----------
|
129
|
-
|
130
|
-
<<'----------',
|
131
|
-
I003 =
|
132
|
-
( 2) expr : fact _
|
133
|
-
|
134
|
-
|
135
|
-
$default reduce using rule 2 (expr) [after shift]
|
136
|
-
|
137
|
-
----------
|
138
|
-
|
139
|
-
<<'----------',
|
140
|
-
I004 =
|
141
|
-
( 1) expr : expr '/' _ __expr_0_2__ fact
|
142
|
-
|
143
|
-
|
144
|
-
$default reduce using rule 3 (__expr_0_2__) [after shift]
|
145
|
-
|
146
|
-
----------
|
147
|
-
|
148
|
-
<<'----------',
|
149
|
-
I005 =
|
150
|
-
( 1) expr : expr '/' __expr_0_2__ _ fact
|
151
|
-
|
152
|
-
REGEXP shift, and goto to state 2
|
153
|
-
|
154
|
-
|
155
|
-
----------
|
156
|
-
|
157
|
-
<<'----------',
|
158
|
-
I006 =
|
159
|
-
( 1) expr : expr '/' __expr_0_2__ fact _
|
160
|
-
|
161
|
-
|
162
|
-
$default reduce using rule 1 (expr) [after shift]
|
163
|
-
|
164
|
-
----------
|
165
|
-
]
|
166
|
-
|
167
|
-
|
168
|
-
Tables = [ reduce_table, nparams, action_table,
|
169
|
-
defred_table, defred_after_shift_table, goto_table,
|
170
|
-
t2i, i2t, nt2i, i2nt ]
|
171
|
-
|
172
|
-
def self.createDecoratedParser
|
173
|
-
D4StatefulLexerTest1::StatefulLexer.new(D4StatefulLexerTest1::NVAction.new(StatefulLexerTest1.new()))
|
174
|
-
end
|
175
|
-
|
176
|
-
### Inner Code
|
177
|
-
|
178
|
-
def lex_START(&block)
|
179
|
-
case @line
|
180
|
-
|
181
|
-
when /\A\s+/
|
182
|
-
@oldline = @line; @line = $'
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
when /\A\/(([^\/\\]+|\\.)*)\//
|
187
|
-
@oldline = @line; @line = $'
|
188
|
-
yield token(:REGEXP, $&)
|
189
|
-
|
190
|
-
|
191
|
-
when /\A./
|
192
|
-
@oldline = @line; @line = $'
|
193
|
-
yield token($&, $&)
|
194
|
-
|
195
|
-
|
196
|
-
else
|
197
|
-
raise RuntimeError, "must not happen #{@line}"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
def lex_OPMODE(&block)
|
202
|
-
case @line
|
203
|
-
|
204
|
-
when /\A\//
|
205
|
-
@oldline = @line; @line = $'
|
206
|
-
yield token($&, $&)
|
207
|
-
|
208
|
-
|
209
|
-
else
|
210
|
-
lex_START(&block)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
attr_accessor :lex_state, :lex_context
|
215
|
-
def lex(&block)
|
216
|
-
@lex_state ||= :START
|
217
|
-
@lex_context ||= {}
|
218
|
-
begin
|
219
|
-
until @line.empty?
|
220
|
-
self.send "lex_#{@lex_state}", &block
|
221
|
-
end
|
222
|
-
end while @line0 = @line = getline
|
223
|
-
yield nil, nil
|
224
|
-
end
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
### Outer Code
|
229
|
-
|
230
|
-
class D4StatefulLexerTest1::StatefulLexer < Depager::LALR::Action #:nodoc:all
|
231
|
-
include Depager::DecoratorUtils
|
232
|
-
|
233
|
-
on_reduce = [
|
234
|
-
nil,
|
235
|
-
nil,
|
236
|
-
nil,
|
237
|
-
:_lex_expr_0_2,
|
238
|
-
:_lex_fact_0_1,
|
239
|
-
|
240
|
-
]
|
241
|
-
Tables = [on_reduce]
|
242
|
-
def initialize inside
|
243
|
-
super inside, 'StatefulLexer'
|
244
|
-
@on_reduce, = self.class::Tables
|
245
|
-
init_parser
|
246
|
-
end
|
247
|
-
|
248
|
-
|
249
|
-
def _lex_expr_0_2 val
|
250
|
-
@basis.lex_state = :START;warn 'MODE:->:START'
|
251
|
-
end
|
252
|
-
|
253
|
-
def _lex_fact_0_1 val
|
254
|
-
@basis.lex_state = :OPMODE;warn 'MODE:->:OPMODE'
|
255
|
-
end
|
256
|
-
|
257
|
-
def afterError
|
258
|
-
warn "StatefulLex: lex_state==#{@basis.lex_state}" if $MP_DEBUG
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
|
263
|
-
class D4StatefulLexerTest1::NVAction < Depager::LALR::Action #:nodoc:all
|
264
|
-
include Depager::DecoratorUtils
|
265
|
-
|
266
|
-
on_reduce = [
|
267
|
-
nil,
|
268
|
-
nil,
|
269
|
-
nil,
|
270
|
-
nil,
|
271
|
-
:_act_3,
|
272
|
-
|
273
|
-
]
|
274
|
-
Tables = [on_reduce]
|
275
|
-
def initialize inside
|
276
|
-
super inside, 'NVAction'
|
277
|
-
@on_reduce, = self.class::Tables
|
278
|
-
init_parser
|
279
|
-
end
|
280
|
-
|
281
|
-
|
282
|
-
module_eval <<-'.,.,122745804061258.,.,', 'slex_test/divreg.slex.dr', 22
|
283
|
-
def _act_3 val
|
284
|
-
_REGEXP, = *val
|
285
|
-
warn "REGEXP: #{_REGEXP.value}"
|
286
|
-
|
287
|
-
end
|
288
|
-
.,.,122745804061258.,.,
|
289
|
-
|
290
|
-
end
|
291
|
-
|
292
|
-
|
293
|
-
def createDecoratedStatefulLexerTest1
|
294
|
-
D4StatefulLexerTest1::StatefulLexer.new(D4StatefulLexerTest1::NVAction.new(StatefulLexerTest1.new()))
|
295
|
-
end
|
296
|
-
|
297
|
-
### main
|
298
|
-
if __FILE__ == $0
|
299
|
-
### Main Code
|
300
|
-
p = createDecoratedStatefulLexerTest1
|
301
|
-
p.parse(STDIN)
|
302
|
-
|
303
|
-
end
|
@@ -1,370 +0,0 @@
|
|
1
|
-
|
2
|
-
begin; require 'rubygems'; rescue Exception; end
|
3
|
-
require 'depager/parser.rb'
|
4
|
-
|
5
|
-
|
6
|
-
module Depager::DecoratorUtils; end
|
7
|
-
module D4StatefulLexerTest2; end
|
8
|
-
|
9
|
-
class StatefulLexerTest2 < Depager::LALR::Basis
|
10
|
-
|
11
|
-
|
12
|
-
### Reduce Table
|
13
|
-
reduce_table = [
|
14
|
-
[ -1, 1 ], # ( 0) $start : stmts
|
15
|
-
[ 0, 0 ], # ( 1) stmts :
|
16
|
-
[ 0, 3 ], # ( 2) stmts : stmts expr EOL
|
17
|
-
[ 1, 4 ], # ( 3) expr : expr '+' __expr_0_2__ fact
|
18
|
-
[ 1, 1 ], # ( 4) expr : fact
|
19
|
-
[ 3, 0 ], # ( 5) __expr_0_2__ :
|
20
|
-
[ 2, 1 ], # ( 6) fact : ID
|
21
|
-
]
|
22
|
-
### Extension Params
|
23
|
-
nparams = {
|
24
|
-
'NVAction' => 3,
|
25
|
-
'StatefulLexer' => 2,
|
26
|
-
}
|
27
|
-
### Term to Int
|
28
|
-
t2i = {
|
29
|
-
nil => 0,
|
30
|
-
false => 1,
|
31
|
-
:EOL => 2,
|
32
|
-
"+" => 3,
|
33
|
-
:ID => 4,
|
34
|
-
}
|
35
|
-
### Int to Term
|
36
|
-
i2t = [
|
37
|
-
nil,
|
38
|
-
false,
|
39
|
-
:EOL,
|
40
|
-
"+",
|
41
|
-
:ID,
|
42
|
-
]
|
43
|
-
### Action Table
|
44
|
-
action_table = [
|
45
|
-
[ nil, nil, nil, nil, nil, ],
|
46
|
-
[ ACC, nil, nil, nil, 4, ],
|
47
|
-
[ nil, nil, 5, 6, nil, ],
|
48
|
-
[ nil, nil, nil, nil, nil, ],
|
49
|
-
[ nil, nil, nil, nil, nil, ],
|
50
|
-
[ nil, nil, nil, nil, nil, ],
|
51
|
-
[ nil, nil, nil, nil, nil, ],
|
52
|
-
[ nil, nil, nil, nil, 4, ],
|
53
|
-
[ nil, nil, nil, nil, nil, ],
|
54
|
-
]
|
55
|
-
### Default Reduce Table
|
56
|
-
defred_table = [
|
57
|
-
-1,
|
58
|
-
nil,
|
59
|
-
nil,
|
60
|
-
-4,
|
61
|
-
-6,
|
62
|
-
-2,
|
63
|
-
-5,
|
64
|
-
nil,
|
65
|
-
-3,
|
66
|
-
]
|
67
|
-
defred_after_shift_table = [
|
68
|
-
-1,
|
69
|
-
nil,
|
70
|
-
nil,
|
71
|
-
-4,
|
72
|
-
-6,
|
73
|
-
-2,
|
74
|
-
-5,
|
75
|
-
nil,
|
76
|
-
-3,
|
77
|
-
]
|
78
|
-
### Nonterm to Int
|
79
|
-
nt2i = {
|
80
|
-
:stmts => 0,
|
81
|
-
:expr => 1,
|
82
|
-
:fact => 2,
|
83
|
-
:__expr_0_2__ => 3,
|
84
|
-
}
|
85
|
-
### Int to Nonterm
|
86
|
-
i2nt = [
|
87
|
-
:stmts,
|
88
|
-
:expr,
|
89
|
-
:fact,
|
90
|
-
:__expr_0_2__,
|
91
|
-
]
|
92
|
-
### Goto Table
|
93
|
-
goto_table = [
|
94
|
-
[ 1, nil, nil, nil, ],
|
95
|
-
[ nil, 2, 3, nil, ],
|
96
|
-
[ nil, nil, nil, nil, ],
|
97
|
-
[ nil, nil, nil, nil, ],
|
98
|
-
[ nil, nil, nil, nil, ],
|
99
|
-
[ nil, nil, nil, nil, ],
|
100
|
-
[ nil, nil, nil, 7, ],
|
101
|
-
[ nil, nil, 8, nil, ],
|
102
|
-
[ nil, nil, nil, nil, ],
|
103
|
-
]
|
104
|
-
|
105
|
-
|
106
|
-
alias orig_error error
|
107
|
-
def error
|
108
|
-
orig_error
|
109
|
-
warn "current state: #{StateInfo[@stack.last]}"
|
110
|
-
end
|
111
|
-
|
112
|
-
### States
|
113
|
-
StateInfo = [
|
114
|
-
<<'----------',
|
115
|
-
I000 =
|
116
|
-
( 0) $start : _ stmts
|
117
|
-
|
118
|
-
|
119
|
-
$default reduce using rule 1 (stmts) [after shift]
|
120
|
-
|
121
|
-
----------
|
122
|
-
|
123
|
-
<<'----------',
|
124
|
-
I001 =
|
125
|
-
( 0) $start : stmts _
|
126
|
-
( 2) stmts : stmts _ expr EOL
|
127
|
-
|
128
|
-
ID shift, and goto to state 4
|
129
|
-
|
130
|
-
|
131
|
-
$end accept
|
132
|
-
|
133
|
-
----------
|
134
|
-
|
135
|
-
<<'----------',
|
136
|
-
I002 =
|
137
|
-
( 2) stmts : stmts expr _ EOL
|
138
|
-
( 3) expr : expr _ '+' __expr_0_2__ fact
|
139
|
-
|
140
|
-
EOL shift, and goto to state 5
|
141
|
-
'+' shift, and goto to state 6
|
142
|
-
|
143
|
-
|
144
|
-
----------
|
145
|
-
|
146
|
-
<<'----------',
|
147
|
-
I003 =
|
148
|
-
( 4) expr : fact _
|
149
|
-
|
150
|
-
|
151
|
-
$default reduce using rule 4 (expr) [after shift]
|
152
|
-
|
153
|
-
----------
|
154
|
-
|
155
|
-
<<'----------',
|
156
|
-
I004 =
|
157
|
-
( 6) fact : ID _
|
158
|
-
|
159
|
-
|
160
|
-
$default reduce using rule 6 (fact) [after shift]
|
161
|
-
|
162
|
-
----------
|
163
|
-
|
164
|
-
<<'----------',
|
165
|
-
I005 =
|
166
|
-
( 2) stmts : stmts expr EOL _
|
167
|
-
|
168
|
-
|
169
|
-
$default reduce using rule 2 (stmts) [after shift]
|
170
|
-
|
171
|
-
----------
|
172
|
-
|
173
|
-
<<'----------',
|
174
|
-
I006 =
|
175
|
-
( 3) expr : expr '+' _ __expr_0_2__ fact
|
176
|
-
|
177
|
-
|
178
|
-
$default reduce using rule 5 (__expr_0_2__) [after shift]
|
179
|
-
|
180
|
-
----------
|
181
|
-
|
182
|
-
<<'----------',
|
183
|
-
I007 =
|
184
|
-
( 3) expr : expr '+' __expr_0_2__ _ fact
|
185
|
-
|
186
|
-
ID shift, and goto to state 4
|
187
|
-
|
188
|
-
|
189
|
-
----------
|
190
|
-
|
191
|
-
<<'----------',
|
192
|
-
I008 =
|
193
|
-
( 3) expr : expr '+' __expr_0_2__ fact _
|
194
|
-
|
195
|
-
|
196
|
-
$default reduce using rule 3 (expr) [after shift]
|
197
|
-
|
198
|
-
----------
|
199
|
-
]
|
200
|
-
|
201
|
-
|
202
|
-
Tables = [ reduce_table, nparams, action_table,
|
203
|
-
defred_table, defred_after_shift_table, goto_table,
|
204
|
-
t2i, i2t, nt2i, i2nt ]
|
205
|
-
|
206
|
-
def self.createDecoratedParser
|
207
|
-
D4StatefulLexerTest2::StatefulLexer.new(D4StatefulLexerTest2::NVAction.new(StatefulLexerTest2.new()))
|
208
|
-
end
|
209
|
-
|
210
|
-
### Inner Code
|
211
|
-
|
212
|
-
def lex_START(&block)
|
213
|
-
case @line
|
214
|
-
|
215
|
-
when /\A[ \t]+/
|
216
|
-
@oldline = @line; @line = $'
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
when /\A\n/
|
221
|
-
@oldline = @line; @line = $'
|
222
|
-
yield token(:EOL, $&)
|
223
|
-
|
224
|
-
|
225
|
-
when /\A\w+/
|
226
|
-
@oldline = @line; @line = $'
|
227
|
-
yield token(:ID, $&)
|
228
|
-
|
229
|
-
|
230
|
-
when /\A./
|
231
|
-
@oldline = @line; @line = $'
|
232
|
-
yield token($&, $&)
|
233
|
-
|
234
|
-
|
235
|
-
else
|
236
|
-
raise RuntimeError, "must not happen #{@line}"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def lex_LCONT(&block)
|
241
|
-
case @line
|
242
|
-
|
243
|
-
when /\A\r?\n/
|
244
|
-
@oldline = @line; @line = $'
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
else
|
249
|
-
lex_START(&block)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
attr_accessor :lex_state, :lex_context
|
254
|
-
def lex(&block)
|
255
|
-
@lex_state ||= :START
|
256
|
-
@lex_context ||= {}
|
257
|
-
begin
|
258
|
-
until @line.empty?
|
259
|
-
self.send "lex_#{@lex_state}", &block
|
260
|
-
end
|
261
|
-
end while @line0 = @line = getline
|
262
|
-
yield nil, nil
|
263
|
-
end
|
264
|
-
|
265
|
-
end
|
266
|
-
|
267
|
-
### Outer Code
|
268
|
-
|
269
|
-
class D4StatefulLexerTest2::StatefulLexer < Depager::LALR::Action #:nodoc:all
|
270
|
-
include Depager::DecoratorUtils
|
271
|
-
|
272
|
-
on_reduce = [
|
273
|
-
nil,
|
274
|
-
nil,
|
275
|
-
nil,
|
276
|
-
nil,
|
277
|
-
nil,
|
278
|
-
:_lex_expr_0_2,
|
279
|
-
:_lex_fact_0_1,
|
280
|
-
|
281
|
-
]
|
282
|
-
Tables = [on_reduce]
|
283
|
-
def initialize inside
|
284
|
-
super inside, 'StatefulLexer'
|
285
|
-
@on_reduce, = self.class::Tables
|
286
|
-
init_parser
|
287
|
-
end
|
288
|
-
|
289
|
-
|
290
|
-
def _lex_expr_0_2 val
|
291
|
-
@basis.lex_state = :LCONT
|
292
|
-
end
|
293
|
-
|
294
|
-
def _lex_fact_0_1 val
|
295
|
-
@basis.lex_state = :START
|
296
|
-
end
|
297
|
-
|
298
|
-
def afterError
|
299
|
-
warn "StatefulLex: lex_state==#{@basis.lex_state}" if $MP_DEBUG
|
300
|
-
end
|
301
|
-
|
302
|
-
end
|
303
|
-
|
304
|
-
class D4StatefulLexerTest2::NVAction < Depager::LALR::Action #:nodoc:all
|
305
|
-
include Depager::DecoratorUtils
|
306
|
-
|
307
|
-
on_reduce = [
|
308
|
-
nil,
|
309
|
-
nil,
|
310
|
-
:_act_1,
|
311
|
-
:_act_2,
|
312
|
-
:_act_3,
|
313
|
-
nil,
|
314
|
-
:_act_5,
|
315
|
-
|
316
|
-
]
|
317
|
-
Tables = [on_reduce]
|
318
|
-
def initialize inside
|
319
|
-
super inside, 'NVAction'
|
320
|
-
@on_reduce, = self.class::Tables
|
321
|
-
init_parser
|
322
|
-
end
|
323
|
-
|
324
|
-
|
325
|
-
module_eval <<-'.,.,12274580401395.,.,', 'slex_test/ljoin.slex.dr', 19
|
326
|
-
def _act_1 val
|
327
|
-
_stmts, _expr, _EOL, = *val
|
328
|
-
warn "#{_expr} <EOL>:#{@lexstate}"
|
329
|
-
|
330
|
-
end
|
331
|
-
.,.,12274580401395.,.,
|
332
|
-
|
333
|
-
module_eval <<-'.,.,1227458040182.,.,', 'slex_test/ljoin.slex.dr', 23
|
334
|
-
def _act_2 val
|
335
|
-
_expr, _, ___expr_0_2__, _fact, = *val
|
336
|
-
"#{_expr} + #{_fact}"
|
337
|
-
|
338
|
-
end
|
339
|
-
.,.,1227458040182.,.,
|
340
|
-
|
341
|
-
module_eval <<-'.,.,122745804061311.,.,', 'slex_test/ljoin.slex.dr', 25
|
342
|
-
def _act_3 val
|
343
|
-
_fact, = *val
|
344
|
-
_fact
|
345
|
-
|
346
|
-
end
|
347
|
-
.,.,122745804061311.,.,
|
348
|
-
|
349
|
-
module_eval <<-'.,.,122745804033944.,.,', 'slex_test/ljoin.slex.dr', 29
|
350
|
-
def _act_5 val
|
351
|
-
_ID, = *val
|
352
|
-
_ID.value
|
353
|
-
|
354
|
-
end
|
355
|
-
.,.,122745804033944.,.,
|
356
|
-
|
357
|
-
end
|
358
|
-
|
359
|
-
|
360
|
-
def createDecoratedStatefulLexerTest2
|
361
|
-
D4StatefulLexerTest2::StatefulLexer.new(D4StatefulLexerTest2::NVAction.new(StatefulLexerTest2.new()))
|
362
|
-
end
|
363
|
-
|
364
|
-
### main
|
365
|
-
if __FILE__ == $0
|
366
|
-
### Main Code
|
367
|
-
p = createDecoratedStatefulLexerTest2
|
368
|
-
p.parse(STDIN)
|
369
|
-
|
370
|
-
end
|