1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/racc/cparse/cparse.c: sync with original code, rev 1.8.

* ext/racc/cparse/cparse.c: should mark CparseParams objects.
* lib/racc/parser.rb: sync with original code, rev 1.8.
* lib/racc/parser.rb: update coding style.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2006-07-06 12:50:51 +00:00
parent c3e411ee8a
commit 69aeed5065
3 changed files with 98 additions and 61 deletions

View file

@ -1,7 +1,7 @@
#
# parser.rb
# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
#
# Copyright (c) 1999-2004 Minero Aoki
# Copyright (c) 1999-2006 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the same terms of ruby.
@ -10,13 +10,6 @@
# into a Racc output file, you may use that output file
# without restriction.
#
# $raccId: parser.rb,v 1.4 2003/11/03 13:41:47 aamine Exp $
#
# NOTE:
# This file is part of the runtime library of Racc parser generator.
# If you want to generate your own parser, you must get Racc full package.
# Get it from: http://raa.ruby-lang.org/list.rhtml?name=racc
#
unless defined?(NotImplementedError)
NotImplementedError = NotImplementError
@ -29,7 +22,6 @@ unless defined?(::ParseError)
ParseError = Racc::ParseError
end
module Racc
unless defined?(Racc_No_Extentions)
@ -38,14 +30,14 @@ module Racc
class Parser
Racc_Runtime_Version = '1.4.4'
Racc_Runtime_Revision = '$raccRevision: 1.4 $'.split[1]
Racc_Runtime_Version = '1.4.5'
Racc_Runtime_Revision = '$originalRevision: 1.8 $'.split[1]
Racc_Runtime_Core_Version_R = '1.4.4'
Racc_Runtime_Core_Revision_R = '$raccRevision: 1.4 $'.split[1]
Racc_Runtime_Core_Version_R = '1.4.5'
Racc_Runtime_Core_Revision_R = '$originalRevision: 1.8 $'.split[1]
begin
require 'racc/cparse'
# Racc_Runtime_Core_Version_C = (defined in extension)
# Racc_Runtime_Core_Version_C = (defined in extention)
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
unless new.respond_to?(:_racc_do_parse_c, true)
raise LoadError, 'old cparse.so'
@ -111,7 +103,7 @@ module Racc
raise NotImplementedError, "#{self.class}\#next_token is not defined"
end
def _racc_do_parse_rb( arg, in_debug )
def _racc_do_parse_rb(arg, in_debug)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
@ -156,11 +148,11 @@ module Racc
### yyparse
###
def yyparse( recv, mid )
def yyparse(recv, mid)
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
end
def _racc_yyparse_rb( recv, mid, arg, c_debug )
def _racc_yyparse_rb(recv, mid, arg, c_debug)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
@ -179,7 +171,6 @@ module Racc
end
end
recv.__send__(mid) do |tok, val|
# $stderr.puts "rd: tok=#{tok}, val=#{val}"
unless tok
@racc_t = 0
else
@ -193,12 +184,7 @@ module Racc
act = action_table[i] and
action_check[i] == @racc_state[-1]
act = action_default[@racc_state[-1]]
# $stderr.puts "02: act=#{act}"
# $stderr.puts "curstate=#{@racc_state[-1]}"
else
# $stderr.puts "01: act=#{act}"
end
while act = _racc_evalact(act, arg)
;
end
@ -211,9 +197,6 @@ module Racc
act = action_table[i] and
action_check[i] == @racc_state[-1]
act = action_default[@racc_state[-1]]
# $stderr.puts "04: act=#{act}"
else
# $stderr.puts "03: act=#{act}"
end
while act = _racc_evalact(act, arg)
;
@ -227,13 +210,12 @@ module Racc
### common
###
def _racc_evalact( act, arg )
# $stderr.puts "ea: act=#{act}"
def _racc_evalact(act, arg)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
reduce_n, use_result, * = arg
nerr = 0 # tmp
nerr = 0 # tmp
if act > 0 and act < shift_n
#
@ -266,7 +248,7 @@ nerr = 0 # tmp
when 2 # yyaccept
return shift_n
else
raise RuntimeError, '[Racc Bug] unknown jump code'
raise '[Racc Bug] unknown jump code'
end
end
@ -304,7 +286,6 @@ nerr = 0 # tmp
break
end
end
throw :racc_end_parse, nil if @racc_state.size <= 1
@racc_state.pop
@racc_vstack.pop
@ -316,7 +297,7 @@ nerr = 0 # tmp
return act
else
raise RuntimeError, "[Racc Bug] unknown action #{act.inspect}"
raise "[Racc Bug] unknown action #{act.inspect}"
end
racc_next_state(@racc_state[-1], @racc_state) if @yydebug
@ -324,7 +305,7 @@ nerr = 0 # tmp
nil
end
def _racc_do_reduce( arg, act )
def _racc_do_reduce(arg, act)
action_table, action_check, action_default, action_pointer,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, token_table, shift_n,
@ -365,7 +346,7 @@ nerr = 0 # tmp
goto_default[k1]
end
def on_error( t, val, vstack )
def on_error(t, val, vstack)
raise ParseError, sprintf("\nparse error on value %s (%s)",
val.inspect, token_to_str(t) || '?')
end
@ -386,20 +367,20 @@ nerr = 0 # tmp
# for debugging output
#
def racc_read_token( t, tok, val )
def racc_read_token(t, tok, val)
@racc_debug_out.print 'read '
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
@racc_debug_out.puts val.inspect
@racc_debug_out.puts
end
def racc_shift( tok, tstack, vstack )
def racc_shift(tok, tstack, vstack)
@racc_debug_out.puts "shift #{racc_token2str tok}"
racc_print_stacks tstack, vstack
@racc_debug_out.puts
end
def racc_reduce( toks, sim, tstack, vstack )
def racc_reduce(toks, sim, tstack, vstack)
out = @racc_debug_out
out.print 'reduce '
if toks.empty?
@ -418,20 +399,20 @@ nerr = 0 # tmp
@racc_debug_out.puts
end
def racc_e_pop( state, tstack, vstack )
def racc_e_pop(state, tstack, vstack)
@racc_debug_out.puts 'error recovering mode: pop token'
racc_print_states state
racc_print_stacks tstack, vstack
@racc_debug_out.puts
end
def racc_next_state( curstate, state )
def racc_next_state(curstate, state)
@racc_debug_out.puts "goto #{curstate}"
racc_print_states state
@racc_debug_out.puts
end
def racc_print_stacks( t, v )
def racc_print_stacks(t, v)
out = @racc_debug_out
out.print ' ['
t.each_index do |i|
@ -440,19 +421,19 @@ nerr = 0 # tmp
out.puts ' ]'
end
def racc_print_states( s )
def racc_print_states(s)
out = @racc_debug_out
out.print ' ['
s.each {|st| out.print ' ', st }
out.puts ' ]'
end
def racc_token2str( tok )
def racc_token2str(tok)
self.class::Racc_token_to_s_table[tok] or
raise RuntimeError, "[Racc Bug] can't convert token #{tok} to string"
raise "[Racc Bug] can't convert token #{tok} to string"
end
def token_to_str( t )
def token_to_str(t)
self.class::Racc_token_to_s_table[t]
end