depager 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/Manifest.txt +52 -0
- data/README.en +64 -0
- data/README.ja +128 -0
- data/bin/depager +47 -0
- data/data/depager/misc/depager-mode.el +209 -0
- data/data/depager/sample/extension/paction.dr +15 -0
- data/data/depager/sample/extension/pactiontest.dr +14 -0
- data/data/depager/sample/pl0d/pl0ds.dr +334 -0
- data/data/depager/sample/pl0d/pl0test.pl0 +34 -0
- data/data/depager/sample/sample_calc/calc.action.dr +33 -0
- data/data/depager/sample/sample_calc/calc.astdf.dr +54 -0
- data/data/depager/sample/sample_calc/calc.astl.action.dr +66 -0
- data/data/depager/sample/sample_calc/calc.astl.dr +55 -0
- data/data/depager/sample/sample_calc/calc.atree.dr +43 -0
- data/data/depager/sample/sample_calc/calc.cst.dr +45 -0
- data/data/depager/sample/sample_calc/calc.dr +43 -0
- data/data/depager/sample/sample_calc/calc.lex.dr +29 -0
- data/data/depager/sample/sample_calc/calc.nvaction.dr +33 -0
- data/data/depager/sample/sample_calc/calc_prec.nvaction.dr +31 -0
- data/data/depager/sample/slex_test/slextest1.dr +37 -0
- data/data/depager/sample/slex_test/slextest2.dr +33 -0
- data/lib/depager.rb +608 -0
- data/lib/depager/Rakefile +30 -0
- data/lib/depager/action.rb +47 -0
- data/lib/depager/ast_base.dr +232 -0
- data/lib/depager/ast_base.rb +1249 -0
- data/lib/depager/astdf.rb +10 -0
- data/lib/depager/astl.rb +14 -0
- data/lib/depager/atree.dr +55 -0
- data/lib/depager/atree.rb +336 -0
- data/lib/depager/cst.dr +182 -0
- data/lib/depager/cst.rb +625 -0
- data/lib/depager/lex.dr +76 -0
- data/lib/depager/lex.rb +306 -0
- data/lib/depager/lr.rb +604 -0
- data/lib/depager/nvaction.rb +21 -0
- data/lib/depager/parse_action.rb +24 -0
- data/lib/depager/parser.rb +248 -0
- data/lib/depager/psrtmpl.rb +33 -0
- data/lib/depager/slex.dr +161 -0
- data/lib/depager/slex.rb +646 -0
- data/lib/depager/srp.rb +50 -0
- data/lib/depager/template/astdf.erbs +57 -0
- data/lib/depager/template/astl.erbs +57 -0
- data/lib/depager/template/extension_lalr_master.erb +51 -0
- data/lib/depager/template/extension_lalr_slave.erb +107 -0
- data/lib/depager/template/simple.erb +21 -0
- data/lib/depager/template/single_lalr_parser.erb +97 -0
- data/lib/depager/utils.rb +355 -0
- data/lib/depager/version.rb +9 -0
- data/setup.rb +1585 -0
- metadata +103 -0
data/lib/depager/slex.rb
ADDED
@@ -0,0 +1,646 @@
|
|
1
|
+
|
2
|
+
###
|
3
|
+
### StatefulLexerExtension - Depager Extension (master)
|
4
|
+
###
|
5
|
+
require 'pp.rb'
|
6
|
+
require 'depager/parser.rb'
|
7
|
+
require 'depager/parse_action'
|
8
|
+
|
9
|
+
|
10
|
+
module D4StatefulLexerExtension #:nodoc:all
|
11
|
+
end
|
12
|
+
|
13
|
+
class StatefulLexerExtension #:nodoc:all
|
14
|
+
include Depager::ExtensionUtils
|
15
|
+
|
16
|
+
attr_accessor :h2p
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@master = self
|
20
|
+
@hook = []
|
21
|
+
@h2p = {}
|
22
|
+
init_parser
|
23
|
+
end
|
24
|
+
|
25
|
+
def __regext__ p
|
26
|
+
super p, :default, nil
|
27
|
+
|
28
|
+
@hook[0] = StatefulLexerExtension_prerulelist.new(p, @nparam, self)
|
29
|
+
@h2p['prerulelist'] = @hook[0]
|
30
|
+
p.prerulelist.push [@hook[0], :do_parse]
|
31
|
+
|
32
|
+
@hook[1] = StatefulLexerExtension_prerhs_postsymbol.new(p, @nparam, self)
|
33
|
+
@h2p['prerhs_postsymbol'] = @hook[1]
|
34
|
+
p.postsymbol.push [@hook[1], :do_parse]
|
35
|
+
|
36
|
+
# use @hook[1](StatefulLexerExtension_prerhs_postsymbol)
|
37
|
+
p.prerhs.push [@hook[1], :do_parse]
|
38
|
+
|
39
|
+
regext p
|
40
|
+
end
|
41
|
+
|
42
|
+
### Inner Code
|
43
|
+
attr_accessor :ins, :code, :optval
|
44
|
+
def init_parser
|
45
|
+
super
|
46
|
+
@ins = []
|
47
|
+
@optouter = []
|
48
|
+
@on_reduce = []
|
49
|
+
@addition = []
|
50
|
+
end
|
51
|
+
def postRuleList
|
52
|
+
@optouter << %{
|
53
|
+
def afterError
|
54
|
+
warn "StatefulLex: lex_state==\#{@basis.lex_state}" if $MP_DEBUG
|
55
|
+
end
|
56
|
+
}
|
57
|
+
g_parser.optouter <<
|
58
|
+
gen_action_decorator_code(target_name, paramkey,
|
59
|
+
@on_reduce, @optouter)
|
60
|
+
end
|
61
|
+
def postRhs
|
62
|
+
j = 0
|
63
|
+
rhs = g_parser.rhs
|
64
|
+
@ins.each do |i, m|
|
65
|
+
state_name = "#{lhs_name}_#{nrhs}_#{i}"
|
66
|
+
if i != rhs.size
|
67
|
+
isym = g_parser.add_nonterm("__#{state_name}__".intern)
|
68
|
+
new_rule = Rule[isym, []]
|
69
|
+
val = ( ":_lex_#{state_name}" )
|
70
|
+
@addition << [ new_rule, rhs, val, i+j, isym ]
|
71
|
+
j += 1
|
72
|
+
else
|
73
|
+
@on_reduce[nrules] = ( ":_lex_#{state_name}" )
|
74
|
+
end
|
75
|
+
@optouter.push << %{
|
76
|
+
def _lex_#{lhs_name}_#{nrhs}_#{i} val
|
77
|
+
@basis.lex_state = #{m}
|
78
|
+
end
|
79
|
+
}
|
80
|
+
end
|
81
|
+
@ins.clear
|
82
|
+
end
|
83
|
+
def postRhsList
|
84
|
+
@addition.each do |new_rule, rhs, val, pos, isym|
|
85
|
+
g_parser.g << new_rule
|
86
|
+
rhs.insert(pos, isym)
|
87
|
+
@on_reduce[nrules] = val
|
88
|
+
end
|
89
|
+
@addition.clear
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
### Outer Code
|
95
|
+
|
96
|
+
###
|
97
|
+
### StatefulLexerExtension_prerulelist - Part of Depager Extension (slave)
|
98
|
+
###
|
99
|
+
module D4StatefulLexerExtension_prerulelist #:nodoc:all
|
100
|
+
end
|
101
|
+
|
102
|
+
class StatefulLexerExtension_prerulelist < Basis #:nodoc:all
|
103
|
+
include Depager::ExtensionUtils
|
104
|
+
|
105
|
+
include ActionParser
|
106
|
+
|
107
|
+
### Reduce Table
|
108
|
+
reduce_table = [
|
109
|
+
[ -1, 1 ],
|
110
|
+
[ 0, 1 ],
|
111
|
+
[ 1, 0 ],
|
112
|
+
[ 1, 3 ],
|
113
|
+
[ 2, 4 ],
|
114
|
+
[ 4, 0 ],
|
115
|
+
[ 4, 2 ],
|
116
|
+
[ 3, 1 ],
|
117
|
+
[ 3, 2 ],
|
118
|
+
[ 5, 2 ],
|
119
|
+
[ 6, 1 ],
|
120
|
+
[ 6, 3 ],
|
121
|
+
]
|
122
|
+
### Extension Params
|
123
|
+
nparams = {
|
124
|
+
'NVAction' => 2,
|
125
|
+
}
|
126
|
+
### Term to Int
|
127
|
+
t2i = {
|
128
|
+
nil => 0,
|
129
|
+
false => 1,
|
130
|
+
"<" => 2,
|
131
|
+
:ID => 3,
|
132
|
+
">" => 4,
|
133
|
+
":" => 5,
|
134
|
+
:ACTION => 6,
|
135
|
+
:LEX => 7,
|
136
|
+
"," => 8,
|
137
|
+
}
|
138
|
+
### Int to Term
|
139
|
+
i2t = [
|
140
|
+
nil,
|
141
|
+
false,
|
142
|
+
"<",
|
143
|
+
:ID,
|
144
|
+
">",
|
145
|
+
":",
|
146
|
+
:ACTION,
|
147
|
+
:LEX,
|
148
|
+
",",
|
149
|
+
]
|
150
|
+
### Action Table
|
151
|
+
action_table = [
|
152
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
153
|
+
[ ACC, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
154
|
+
[ nil, nil, 4, nil, nil, nil, nil, nil, nil, ],
|
155
|
+
[ nil, nil, nil, nil, nil, nil, nil, 7, nil, ],
|
156
|
+
[ nil, nil, nil, 9, nil, nil, nil, nil, nil, ],
|
157
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
158
|
+
[ nil, nil, nil, nil, nil, nil, 11, nil, 10, ],
|
159
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
160
|
+
[ nil, nil, nil, nil, nil, nil, nil, 7, nil, ],
|
161
|
+
[ nil, nil, nil, nil, nil, 14, nil, nil, nil, ],
|
162
|
+
[ nil, nil, nil, nil, nil, nil, nil, 15, nil, ],
|
163
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
164
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
165
|
+
[ nil, nil, nil, nil, 16, nil, nil, nil, nil, ],
|
166
|
+
[ nil, nil, nil, 17, nil, nil, nil, nil, nil, ],
|
167
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
168
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
169
|
+
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
170
|
+
]
|
171
|
+
### Default Reduce Table
|
172
|
+
defred_table = [
|
173
|
+
-2,
|
174
|
+
nil,
|
175
|
+
-1,
|
176
|
+
nil,
|
177
|
+
nil,
|
178
|
+
-7,
|
179
|
+
nil,
|
180
|
+
-10,
|
181
|
+
-3,
|
182
|
+
-5,
|
183
|
+
nil,
|
184
|
+
-9,
|
185
|
+
-8,
|
186
|
+
nil,
|
187
|
+
nil,
|
188
|
+
-11,
|
189
|
+
-4,
|
190
|
+
-6,
|
191
|
+
]
|
192
|
+
defred_after_shift_table = [
|
193
|
+
-2,
|
194
|
+
nil,
|
195
|
+
nil,
|
196
|
+
nil,
|
197
|
+
nil,
|
198
|
+
-7,
|
199
|
+
nil,
|
200
|
+
-10,
|
201
|
+
nil,
|
202
|
+
nil,
|
203
|
+
nil,
|
204
|
+
-9,
|
205
|
+
-8,
|
206
|
+
nil,
|
207
|
+
nil,
|
208
|
+
-11,
|
209
|
+
-4,
|
210
|
+
-6,
|
211
|
+
]
|
212
|
+
### Nonterm to Int
|
213
|
+
nt2i = {
|
214
|
+
:start => 0,
|
215
|
+
:mode_list => 1,
|
216
|
+
:mode => 2,
|
217
|
+
:lexactlist => 3,
|
218
|
+
:opt_super => 4,
|
219
|
+
:lexact => 5,
|
220
|
+
:lexlist => 6,
|
221
|
+
}
|
222
|
+
### Int to Nonterm
|
223
|
+
i2nt = [
|
224
|
+
:start,
|
225
|
+
:mode_list,
|
226
|
+
:mode,
|
227
|
+
:lexactlist,
|
228
|
+
:opt_super,
|
229
|
+
:lexact,
|
230
|
+
:lexlist,
|
231
|
+
]
|
232
|
+
### Goto Table
|
233
|
+
goto_table = [
|
234
|
+
[ 1, 2, nil, nil, nil, nil, nil, ],
|
235
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
236
|
+
[ nil, nil, 3, nil, nil, nil, nil, ],
|
237
|
+
[ nil, nil, nil, 8, nil, 5, 6, ],
|
238
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
239
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
240
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
241
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
242
|
+
[ nil, nil, nil, nil, nil, 12, 6, ],
|
243
|
+
[ nil, nil, nil, nil, 13, nil, nil, ],
|
244
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
245
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
246
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
247
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
248
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
249
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
250
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
251
|
+
[ nil, nil, nil, nil, nil, nil, nil, ],
|
252
|
+
]
|
253
|
+
|
254
|
+
Tables = [ reduce_table, nparams, action_table,
|
255
|
+
defred_table, defred_after_shift_table, goto_table,
|
256
|
+
t2i, i2t, nt2i, i2nt ]
|
257
|
+
|
258
|
+
attr_accessor :p, :m
|
259
|
+
def initialize p, nparam, master = nil
|
260
|
+
super()
|
261
|
+
@g_parser = @p = p
|
262
|
+
@master = @m = master
|
263
|
+
@nparam = nparam
|
264
|
+
@dect = D4StatefulLexerExtension_prerulelist::NVAction.new(self)
|
265
|
+
init_parser
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
def do_parse?
|
270
|
+
if @line =~ /^\s*%LEX\{\s*\Z/
|
271
|
+
@line = $'
|
272
|
+
true
|
273
|
+
else
|
274
|
+
false
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
|
279
|
+
def banner
|
280
|
+
"%LEX{ ... } / #{@master.class.name}"
|
281
|
+
end
|
282
|
+
|
283
|
+
### Inner Code
|
284
|
+
|
285
|
+
def lex
|
286
|
+
begin
|
287
|
+
until @line.empty? do
|
288
|
+
case @line
|
289
|
+
when /\A\s+/, /\A#.*\Z/
|
290
|
+
|
291
|
+
when /\A[A-Z]+/
|
292
|
+
yield _Token(:ID, $&)
|
293
|
+
when /\A\%\}\s*\Z/
|
294
|
+
@line = $'; yield nil,nil
|
295
|
+
when /\A\/(([^\/\\]+|\\.)*)\//, /\A'([^'\\]+|\\.)*\'/
|
296
|
+
yield _Token(:LEX, "/\\A#{$1}/")
|
297
|
+
when /\A\{/
|
298
|
+
ln = lineno; yield :ACTION, Token[parse_action, ln]; //=~''
|
299
|
+
when /\A./
|
300
|
+
yield _Token($&, $&)
|
301
|
+
|
302
|
+
else
|
303
|
+
raise RuntimeError, "must not happen #{@line}"
|
304
|
+
end
|
305
|
+
@oldline = @line
|
306
|
+
@line = $'
|
307
|
+
end
|
308
|
+
end while @line = getline
|
309
|
+
yield nil, nil
|
310
|
+
end
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
### Outer Code
|
315
|
+
|
316
|
+
class D4StatefulLexerExtension_prerulelist::NVAction < Depager::Action #:nodoc:all
|
317
|
+
include Depager::DecoratorUtils
|
318
|
+
include ActionParser
|
319
|
+
|
320
|
+
on_reduce = [
|
321
|
+
nil,
|
322
|
+
:_act_0,
|
323
|
+
:_act_1,
|
324
|
+
:_act_2,
|
325
|
+
:_act_3,
|
326
|
+
:_act_4,
|
327
|
+
:_act_5,
|
328
|
+
:_act_6,
|
329
|
+
:_act_7,
|
330
|
+
:_act_8,
|
331
|
+
:_act_9,
|
332
|
+
:_act_10,
|
333
|
+
|
334
|
+
]
|
335
|
+
Tables = [on_reduce]
|
336
|
+
def initialize inside
|
337
|
+
super inside, 'NVAction'
|
338
|
+
@on_reduce, = self.class::Tables
|
339
|
+
init_parser
|
340
|
+
end
|
341
|
+
|
342
|
+
|
343
|
+
module_eval <<-'.,.,118028145945879.,.,', 'slex.dr', 73
|
344
|
+
def _act_0 val
|
345
|
+
_mode_list = *val
|
346
|
+
|
347
|
+
ll = ''
|
348
|
+
_mode_list.each do |m, s, l|
|
349
|
+
elsec = if s
|
350
|
+
"_rest = lex_#{s}(&block)"
|
351
|
+
else
|
352
|
+
%!raise RuntimeError, "must not happen \#{@line}"!
|
353
|
+
end
|
354
|
+
ll << %{
|
355
|
+
def lex_#{m}(&block)
|
356
|
+
_rest = ''
|
357
|
+
case @line
|
358
|
+
#{l.map{|i| ' '*4+i}}
|
359
|
+
else
|
360
|
+
#{elsec}
|
361
|
+
end
|
362
|
+
return _rest
|
363
|
+
end
|
364
|
+
}; #code
|
365
|
+
end
|
366
|
+
g_parser.optinner << ll << %{
|
367
|
+
attr_accessor :lex_state
|
368
|
+
def lex(&block)
|
369
|
+
@lex_state ||= :START
|
370
|
+
begin
|
371
|
+
until @line.empty?
|
372
|
+
@line = self.send "lex_\#{@lex_state}", &block
|
373
|
+
end
|
374
|
+
end while @line = getline
|
375
|
+
yield nil, nil
|
376
|
+
end
|
377
|
+
}; #code
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
.,.,118028145945879.,.,
|
382
|
+
|
383
|
+
module_eval <<-'.,.,118028145964322.,.,', 'slex.dr', 108
|
384
|
+
def _act_1 val
|
385
|
+
[ ]
|
386
|
+
|
387
|
+
end
|
388
|
+
|
389
|
+
.,.,118028145964322.,.,
|
390
|
+
|
391
|
+
module_eval <<-'.,.,118028145964390.,.,', 'slex.dr', 109
|
392
|
+
def _act_2 val
|
393
|
+
_mode_list, _mode, _lexactlist = *val
|
394
|
+
_mode_list << [_mode[0], _mode[1], _lexactlist]
|
395
|
+
|
396
|
+
end
|
397
|
+
|
398
|
+
.,.,118028145964390.,.,
|
399
|
+
|
400
|
+
module_eval <<-'.,.,118028145932066.,.,', 'slex.dr', 112
|
401
|
+
def _act_3 val
|
402
|
+
_, _ID, _opt_super, _ = *val
|
403
|
+
[ _ID.value, _opt_super ]
|
404
|
+
|
405
|
+
end
|
406
|
+
|
407
|
+
.,.,118028145932066.,.,
|
408
|
+
|
409
|
+
module_eval <<-'.,.,118028145910814.,.,', 'slex.dr', 115
|
410
|
+
def _act_4 val
|
411
|
+
nil
|
412
|
+
|
413
|
+
end
|
414
|
+
|
415
|
+
.,.,118028145910814.,.,
|
416
|
+
|
417
|
+
module_eval <<-'.,.,118028145954649.,.,', 'slex.dr', 116
|
418
|
+
def _act_5 val
|
419
|
+
_, _ID = *val
|
420
|
+
_ID.value
|
421
|
+
|
422
|
+
end
|
423
|
+
|
424
|
+
.,.,118028145954649.,.,
|
425
|
+
|
426
|
+
module_eval <<-'.,.,118028145953818.,.,', 'slex.dr', 119
|
427
|
+
def _act_6 val
|
428
|
+
_lexact = *val
|
429
|
+
[ _lexact ]
|
430
|
+
|
431
|
+
end
|
432
|
+
|
433
|
+
.,.,118028145953818.,.,
|
434
|
+
|
435
|
+
module_eval <<-'.,.,118028145941830.,.,', 'slex.dr', 120
|
436
|
+
def _act_7 val
|
437
|
+
_lexactlist, _lexact = *val
|
438
|
+
_lexactlist << _lexact
|
439
|
+
|
440
|
+
end
|
441
|
+
|
442
|
+
.,.,118028145941830.,.,
|
443
|
+
|
444
|
+
module_eval <<-'.,.,11802814599495.,.,', 'slex.dr', 124
|
445
|
+
def _act_8 val
|
446
|
+
_lexlist, _ACTION = *val
|
447
|
+
|
448
|
+
%{
|
449
|
+
when #{_lexlist.join(', ')}
|
450
|
+
_rest = $'
|
451
|
+
#{ _ACTION.value }
|
452
|
+
}; #code
|
453
|
+
|
454
|
+
end
|
455
|
+
|
456
|
+
.,.,11802814599495.,.,
|
457
|
+
|
458
|
+
module_eval <<-'.,.,118028145922938.,.,', 'slex.dr', 133
|
459
|
+
def _act_9 val
|
460
|
+
_LEX = *val
|
461
|
+
[ _LEX.value ]
|
462
|
+
|
463
|
+
end
|
464
|
+
|
465
|
+
.,.,118028145922938.,.,
|
466
|
+
|
467
|
+
module_eval <<-'.,.,11802814594078.,.,', 'slex.dr', 134
|
468
|
+
def _act_10 val
|
469
|
+
_lexlist, _, _LEX = *val
|
470
|
+
_lexlist.push _LEX
|
471
|
+
|
472
|
+
end
|
473
|
+
|
474
|
+
.,.,11802814594078.,.,
|
475
|
+
|
476
|
+
end
|
477
|
+
|
478
|
+
|
479
|
+
###
|
480
|
+
### StatefulLexerExtension_prerhs_postsymbol - Part of Depager Extension (slave)
|
481
|
+
###
|
482
|
+
module D4StatefulLexerExtension_prerhs_postsymbol #:nodoc:all
|
483
|
+
end
|
484
|
+
|
485
|
+
class StatefulLexerExtension_prerhs_postsymbol < Basis #:nodoc:all
|
486
|
+
include Depager::ExtensionUtils
|
487
|
+
|
488
|
+
|
489
|
+
### Reduce Table
|
490
|
+
reduce_table = [
|
491
|
+
[ -1, 1 ],
|
492
|
+
[ 0, 4 ],
|
493
|
+
]
|
494
|
+
### Extension Params
|
495
|
+
nparams = {
|
496
|
+
'NVAction' => 2,
|
497
|
+
}
|
498
|
+
### Term to Int
|
499
|
+
t2i = {
|
500
|
+
nil => 0,
|
501
|
+
false => 1,
|
502
|
+
"[" => 2,
|
503
|
+
">" => 3,
|
504
|
+
:SYMBOL => 4,
|
505
|
+
"]" => 5,
|
506
|
+
}
|
507
|
+
### Int to Term
|
508
|
+
i2t = [
|
509
|
+
nil,
|
510
|
+
false,
|
511
|
+
"[",
|
512
|
+
">",
|
513
|
+
:SYMBOL,
|
514
|
+
"]",
|
515
|
+
]
|
516
|
+
### Action Table
|
517
|
+
action_table = [
|
518
|
+
[ nil, nil, 2, nil, nil, nil, ],
|
519
|
+
[ ACC, nil, nil, nil, nil, nil, ],
|
520
|
+
[ nil, nil, nil, 3, nil, nil, ],
|
521
|
+
[ nil, nil, nil, nil, 4, nil, ],
|
522
|
+
[ nil, nil, nil, nil, nil, 5, ],
|
523
|
+
[ nil, nil, nil, nil, nil, nil, ],
|
524
|
+
]
|
525
|
+
### Default Reduce Table
|
526
|
+
defred_table = [
|
527
|
+
nil,
|
528
|
+
nil,
|
529
|
+
nil,
|
530
|
+
nil,
|
531
|
+
nil,
|
532
|
+
-1,
|
533
|
+
]
|
534
|
+
defred_after_shift_table = [
|
535
|
+
nil,
|
536
|
+
nil,
|
537
|
+
nil,
|
538
|
+
nil,
|
539
|
+
nil,
|
540
|
+
-1,
|
541
|
+
]
|
542
|
+
### Nonterm to Int
|
543
|
+
nt2i = {
|
544
|
+
:start => 0,
|
545
|
+
}
|
546
|
+
### Int to Nonterm
|
547
|
+
i2nt = [
|
548
|
+
:start,
|
549
|
+
]
|
550
|
+
### Goto Table
|
551
|
+
goto_table = [
|
552
|
+
[ 1, ],
|
553
|
+
[ nil, ],
|
554
|
+
[ nil, ],
|
555
|
+
[ nil, ],
|
556
|
+
[ nil, ],
|
557
|
+
[ nil, ],
|
558
|
+
]
|
559
|
+
|
560
|
+
Tables = [ reduce_table, nparams, action_table,
|
561
|
+
defred_table, defred_after_shift_table, goto_table,
|
562
|
+
t2i, i2t, nt2i, i2nt ]
|
563
|
+
|
564
|
+
attr_accessor :p, :m
|
565
|
+
def initialize p, nparam, master = nil
|
566
|
+
super()
|
567
|
+
@g_parser = @p = p
|
568
|
+
@master = @m = master
|
569
|
+
@nparam = nparam
|
570
|
+
@dect = D4StatefulLexerExtension_prerhs_postsymbol::NVAction.new(self)
|
571
|
+
init_parser
|
572
|
+
end
|
573
|
+
|
574
|
+
|
575
|
+
def do_parse?
|
576
|
+
if @line =~ /^\s*\[/
|
577
|
+
|
578
|
+
true
|
579
|
+
else
|
580
|
+
false
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
|
585
|
+
def banner
|
586
|
+
"[> ...] / #{@master.class.name}"
|
587
|
+
end
|
588
|
+
|
589
|
+
### Inner Code
|
590
|
+
|
591
|
+
def lex
|
592
|
+
begin
|
593
|
+
until @line.empty? do
|
594
|
+
case @line
|
595
|
+
when /\A\s+/
|
596
|
+
|
597
|
+
when /\A:[a-zA-Z_]+/
|
598
|
+
yield _Token(:SYMBOL, $&)
|
599
|
+
when /\A\]/
|
600
|
+
yield _Token($&, $&); @line = $'; yield nil, nil
|
601
|
+
when /\A./
|
602
|
+
yield _Token($&, $&)
|
603
|
+
|
604
|
+
else
|
605
|
+
raise RuntimeError, "must not happen #{@line}"
|
606
|
+
end
|
607
|
+
@oldline = @line
|
608
|
+
@line = $'
|
609
|
+
end
|
610
|
+
end while @line = getline
|
611
|
+
yield nil, nil
|
612
|
+
end
|
613
|
+
|
614
|
+
end
|
615
|
+
|
616
|
+
### Outer Code
|
617
|
+
|
618
|
+
class D4StatefulLexerExtension_prerhs_postsymbol::NVAction < Depager::Action #:nodoc:all
|
619
|
+
include Depager::DecoratorUtils
|
620
|
+
|
621
|
+
on_reduce = [
|
622
|
+
nil,
|
623
|
+
:_act_0,
|
624
|
+
|
625
|
+
]
|
626
|
+
Tables = [on_reduce]
|
627
|
+
def initialize inside
|
628
|
+
super inside, 'NVAction'
|
629
|
+
@on_reduce, = self.class::Tables
|
630
|
+
init_parser
|
631
|
+
end
|
632
|
+
|
633
|
+
|
634
|
+
module_eval <<-'.,.,118028146037199.,.,', 'slex.dr', 154
|
635
|
+
def _act_0 val
|
636
|
+
_, _, _SYMBOL, _ = *val
|
637
|
+
|
638
|
+
master.ins.push [g_parser.rhs.size, _SYMBOL.value]
|
639
|
+
|
640
|
+
end
|
641
|
+
|
642
|
+
.,.,118028146037199.,.,
|
643
|
+
|
644
|
+
end
|
645
|
+
|
646
|
+
|