1
1
#
2
- # parser.rb
2
+ # $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
3
3
#
4
- # Copyright (c) 1999-2003 Minero Aoki <aamine@loveruby.net>
4
+ # Copyright (c) 1999-2006 Minero Aoki
5
5
#
6
6
# This program is free software.
7
7
# You can distribute/modify this program under the same terms of ruby.
10
10
# into a Racc output file, you may use that output file
11
11
# without restriction.
12
12
#
13
- # $raccId: parser.rb,v 1.4 2003/11/03 13:41:47 aamine Exp $
14
- #
15
13
16
14
unless defined? ( NotImplementedError )
17
15
NotImplementedError = NotImplementError
@@ -24,7 +22,6 @@ class ParseError < StandardError; end
24
22
ParseError = Racc ::ParseError
25
23
end
26
24
27
-
28
25
module Racc
29
26
30
27
unless defined? ( Racc_No_Extentions )
@@ -33,14 +30,14 @@ module Racc
33
30
34
31
class Parser
35
32
36
- Racc_Runtime_Version = '1.4.4 '
37
- Racc_Runtime_Revision = '$raccRevision : 1.4 $' . split [ 1 ]
33
+ Racc_Runtime_Version = '1.4.5 '
34
+ Racc_Runtime_Revision = '$originalRevision : 1.8 $' . split [ 1 ]
38
35
39
- Racc_Runtime_Core_Version_R = '1.4.4 '
40
- Racc_Runtime_Core_Revision_R = '$raccRevision : 1.4 $' . split [ 1 ]
36
+ Racc_Runtime_Core_Version_R = '1.4.5 '
37
+ Racc_Runtime_Core_Revision_R = '$originalRevision : 1.8 $' . split [ 1 ]
41
38
begin
42
39
require 'racc/cparse'
43
- # Racc_Runtime_Core_Version_C = (defined in extension )
40
+ # Racc_Runtime_Core_Version_C = (defined in extention )
44
41
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C . split [ 2 ]
45
42
unless new . respond_to? ( :_racc_do_parse_c , true )
46
43
raise LoadError , 'old cparse.so'
@@ -106,7 +103,7 @@ def next_token
106
103
raise NotImplementedError , "#{ self . class } \# next_token is not defined"
107
104
end
108
105
109
- def _racc_do_parse_rb ( arg , in_debug )
106
+ def _racc_do_parse_rb ( arg , in_debug )
110
107
action_table , action_check , action_default , action_pointer ,
111
108
goto_table , goto_check , goto_default , goto_pointer ,
112
109
nt_base , reduce_table , token_table , shift_n ,
@@ -151,11 +148,11 @@ def _racc_do_parse_rb( arg, in_debug )
151
148
### yyparse
152
149
###
153
150
154
- def yyparse ( recv , mid )
151
+ def yyparse ( recv , mid )
155
152
__send__ ( Racc_YY_Parse_Method , recv , mid , _racc_setup ( ) , true )
156
153
end
157
154
158
- def _racc_yyparse_rb ( recv , mid , arg , c_debug )
155
+ def _racc_yyparse_rb ( recv , mid , arg , c_debug )
159
156
action_table , action_check , action_default , action_pointer ,
160
157
goto_table , goto_check , goto_default , goto_pointer ,
161
158
nt_base , reduce_table , token_table , shift_n ,
@@ -174,7 +171,6 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
174
171
end
175
172
end
176
173
recv . __send__ ( mid ) do |tok , val |
177
- # $stderr.puts "rd: tok=#{tok}, val=#{val}"
178
174
unless tok
179
175
@racc_t = 0
180
176
else
@@ -188,12 +184,7 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
188
184
act = action_table [ i ] and
189
185
action_check [ i ] == @racc_state [ -1 ]
190
186
act = action_default [ @racc_state [ -1 ] ]
191
- # $stderr.puts "02: act=#{act}"
192
- # $stderr.puts "curstate=#{@racc_state[-1]}"
193
- else
194
- # $stderr.puts "01: act=#{act}"
195
187
end
196
-
197
188
while act = _racc_evalact ( act , arg )
198
189
;
199
190
end
@@ -206,9 +197,6 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
206
197
act = action_table [ i ] and
207
198
action_check [ i ] == @racc_state [ -1 ]
208
199
act = action_default [ @racc_state [ -1 ] ]
209
- # $stderr.puts "04: act=#{act}"
210
- else
211
- # $stderr.puts "03: act=#{act}"
212
200
end
213
201
while act = _racc_evalact ( act , arg )
214
202
;
@@ -222,13 +210,12 @@ def _racc_yyparse_rb( recv, mid, arg, c_debug )
222
210
### common
223
211
###
224
212
225
- def _racc_evalact ( act , arg )
226
- # $stderr.puts "ea: act=#{act}"
213
+ def _racc_evalact ( act , arg )
227
214
action_table , action_check , action_default , action_pointer ,
228
215
goto_table , goto_check , goto_default , goto_pointer ,
229
216
nt_base , reduce_table , token_table , shift_n ,
230
217
reduce_n , use_result , * = arg
231
- nerr = 0 # tmp
218
+ nerr = 0 # tmp
232
219
233
220
if act > 0 and act < shift_n
234
221
#
@@ -261,7 +248,7 @@ def _racc_evalact( act, arg )
261
248
when 2 # yyaccept
262
249
return shift_n
263
250
else
264
- raise RuntimeError , '[Racc Bug] unknown jump code'
251
+ raise '[Racc Bug] unknown jump code'
265
252
end
266
253
end
267
254
@@ -299,7 +286,6 @@ def _racc_evalact( act, arg )
299
286
break
300
287
end
301
288
end
302
-
303
289
throw :racc_end_parse , nil if @racc_state . size <= 1
304
290
@racc_state . pop
305
291
@racc_vstack . pop
@@ -311,15 +297,15 @@ def _racc_evalact( act, arg )
311
297
return act
312
298
313
299
else
314
- raise RuntimeError , "[Racc Bug] unknown action #{ act . inspect } "
300
+ raise "[Racc Bug] unknown action #{ act . inspect } "
315
301
end
316
302
317
303
racc_next_state ( @racc_state [ -1 ] , @racc_state ) if @yydebug
318
304
319
305
nil
320
306
end
321
307
322
- def _racc_do_reduce ( arg , act )
308
+ def _racc_do_reduce ( arg , act )
323
309
action_table , action_check , action_default , action_pointer ,
324
310
goto_table , goto_check , goto_default , goto_pointer ,
325
311
nt_base , reduce_table , token_table , shift_n ,
@@ -360,7 +346,7 @@ def _racc_do_reduce( arg, act )
360
346
goto_default [ k1 ]
361
347
end
362
348
363
- def on_error ( t , val , vstack )
349
+ def on_error ( t , val , vstack )
364
350
raise ParseError , sprintf ( "\n parse error on value %s (%s)" ,
365
351
val . inspect , token_to_str ( t ) || '?' )
366
352
end
@@ -381,20 +367,20 @@ def yyerrok
381
367
# for debugging output
382
368
#
383
369
384
- def racc_read_token ( t , tok , val )
370
+ def racc_read_token ( t , tok , val )
385
371
@racc_debug_out . print 'read '
386
372
@racc_debug_out . print tok . inspect , '(' , racc_token2str ( t ) , ') '
387
373
@racc_debug_out . puts val . inspect
388
374
@racc_debug_out . puts
389
375
end
390
376
391
- def racc_shift ( tok , tstack , vstack )
377
+ def racc_shift ( tok , tstack , vstack )
392
378
@racc_debug_out . puts "shift #{ racc_token2str tok } "
393
379
racc_print_stacks tstack , vstack
394
380
@racc_debug_out . puts
395
381
end
396
382
397
- def racc_reduce ( toks , sim , tstack , vstack )
383
+ def racc_reduce ( toks , sim , tstack , vstack )
398
384
out = @racc_debug_out
399
385
out . print 'reduce '
400
386
if toks . empty?
@@ -413,20 +399,20 @@ def racc_accept
413
399
@racc_debug_out . puts
414
400
end
415
401
416
- def racc_e_pop ( state , tstack , vstack )
402
+ def racc_e_pop ( state , tstack , vstack )
417
403
@racc_debug_out . puts 'error recovering mode: pop token'
418
404
racc_print_states state
419
405
racc_print_stacks tstack , vstack
420
406
@racc_debug_out . puts
421
407
end
422
408
423
- def racc_next_state ( curstate , state )
409
+ def racc_next_state ( curstate , state )
424
410
@racc_debug_out . puts "goto #{ curstate } "
425
411
racc_print_states state
426
412
@racc_debug_out . puts
427
413
end
428
414
429
- def racc_print_stacks ( t , v )
415
+ def racc_print_stacks ( t , v )
430
416
out = @racc_debug_out
431
417
out . print ' ['
432
418
t . each_index do |i |
@@ -435,19 +421,19 @@ def racc_print_stacks( t, v )
435
421
out . puts ' ]'
436
422
end
437
423
438
- def racc_print_states ( s )
424
+ def racc_print_states ( s )
439
425
out = @racc_debug_out
440
426
out . print ' ['
441
427
s . each { |st | out . print ' ' , st }
442
428
out . puts ' ]'
443
429
end
444
430
445
- def racc_token2str ( tok )
431
+ def racc_token2str ( tok )
446
432
self . class ::Racc_token_to_s_table [ tok ] or
447
- raise RuntimeError , "[Racc Bug] can't convert token #{ tok } to string"
433
+ raise "[Racc Bug] can't convert token #{ tok } to string"
448
434
end
449
435
450
- def token_to_str ( t )
436
+ def token_to_str ( t )
451
437
self . class ::Racc_token_to_s_table [ t ]
452
438
end
453
439
0 commit comments