Skip to content

Commit

Permalink
Showing 1 changed file with 36 additions and 48 deletions.
84 changes: 36 additions & 48 deletions lib/ruby/stdlib/racc/parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# $Id: 2bd697d1146b280d8d3878e21e556ef769484a37 $
# frozen_string_literal: false
#--
# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
#
# Copyright (c) 1999-2006 Minero Aoki
#
@@ -9,13 +10,7 @@
# As a special exception, when this code is copied by Racc
# into a Racc output file, you may use that output file
# without restriction.
#

require 'racc/info'

unless defined?(NotImplementedError)
NotImplementedError = NotImplementError # :nodoc:
end
#++

module Racc
class ParseError < StandardError; end
@@ -43,7 +38,7 @@ class ParseError < StandardError; end
# [--version] [--copyright] [--help] <var>grammarfile</var>
#
# [+filename+]
# Racc grammar file. Any extention is permitted.
# Racc grammar file. Any extension is permitted.
# [-o+outfile+, --output-file=+outfile+]
# A filename for output. default is <+filename+>.tab.rb
# [-O+filename+, --log-file=+filename+]
@@ -54,12 +49,12 @@ class ParseError < StandardError; end
# [-v, --verbose]
# verbose mode. create +filename+.output file, like yacc's y.output file.
# [-g, --debug]
# add debug code to parser class. To display debuggin information,
# add debug code to parser class. To display debugging information,
# use this '-g' option and set @yydebug true in parser class.
# [-E, --embedded]
# Output parser which doesn't need runtime files (racc/parser.rb).
# [-C, --check-only]
# Check syntax of racc grammer file and quit.
# Check syntax of racc grammar file and quit.
# [-S, --output-status]
# Print messages time to time while compiling.
# [-l, --no-line-convert]
@@ -180,30 +175,25 @@ class ParseError < StandardError; end
# Your own parser is completely yours.
module Racc

unless defined?(Racc_No_Extentions)
Racc_No_Extentions = false # :nodoc:
unless defined?(Racc_No_Extensions)
Racc_No_Extensions = false # :nodoc:
end

class Parser

Racc_Runtime_Version = ::Racc::VERSION
Racc_Runtime_Revision = '$Id: 2bd697d1146b280d8d3878e21e556ef769484a37 $'
Racc_Runtime_Version = '1.4.6'
Racc_Runtime_Revision = %w$originalRevision: 1.8 $[1]

Racc_Runtime_Core_Version_R = ::Racc::VERSION
Racc_Runtime_Core_Revision_R = '$Id: 2bd697d1146b280d8d3878e21e556ef769484a37 $'.split[1]
Racc_Runtime_Core_Version_R = '1.4.6'
Racc_Runtime_Core_Revision_R = %w$originalRevision: 1.8 $[1]
begin
if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby'
require 'racc/cparse-jruby.jar'
com.headius.racc.Cparse.new.load(JRuby.runtime, false)
else
require 'racc/cparse'
end
# Racc_Runtime_Core_Version_C = (defined in extention)
require 'racc/cparse'
# Racc_Runtime_Core_Version_C = (defined in extension)
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'
end
if Racc_No_Extentions
if Racc_No_Extensions
raise LoadError, 'selecting ruby version of racc runtime core'
end

@@ -213,8 +203,6 @@ class Parser
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C # :nodoc:
Racc_Runtime_Type = 'c' # :nodoc:
rescue LoadError
puts $!
puts $!.backtrace
Racc_Main_Parsing_Routine = :_racc_do_parse_rb
Racc_YY_Parse_Method = :_racc_yyparse_rb
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R
@@ -286,7 +274,8 @@ def next_token
def _racc_do_parse_rb(arg, in_debug)
action_table, action_check, action_default, action_pointer,
_, _, _, _,
_, _, token_table, * = arg
_, _, token_table, _,
_, _, * = arg

_racc_init_sysvars
tok = act = i = nil
@@ -328,15 +317,18 @@ def _racc_do_parse_rb(arg, in_debug)
# RECEIVER#METHOD_ID is a method to get next token.
# It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE].
def yyparse(recv, mid)
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), false)
__send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true)
end

def _racc_yyparse_rb(recv, mid, arg, c_debug)
action_table, action_check, action_default, action_pointer,
_, _, _, _,
_, _, token_table, * = arg
_, _, _, _,
_, _, token_table, _,
_, _, * = arg

_racc_init_sysvars
act = nil
i = nil

catch(:racc_end_parse) {
until i = action_pointer[@racc_state[-1]]
@@ -363,9 +355,9 @@ def _racc_yyparse_rb(recv, mid, arg, c_debug)
;
end

while !(i = action_pointer[@racc_state[-1]]) ||
! @racc_read_next ||
@racc_t == 0 # $
while not(i = action_pointer[@racc_state[-1]]) or
not @racc_read_next or
@racc_t == 0 # $
unless i and i += @racc_t and
i >= 0 and
act = action_table[i] and
@@ -386,17 +378,16 @@ def _racc_yyparse_rb(recv, mid, arg, c_debug)

def _racc_evalact(act, arg)
action_table, action_check, _, action_pointer,
_, _, _, _,
_, _, _, shift_n,
reduce_n, * = arg
nerr = 0 # tmp
_, _, _, _,
_, _, _, shift_n, reduce_n,
_, _, * = arg

if act > 0 and act < shift_n
#
# shift
#
if @racc_error_status > 0
@racc_error_status -= 1 unless @racc_t <= 1 # error token or EOF
@racc_error_status -= 1 unless @racc_t == 1 # error token
end
@racc_vstack.push @racc_val
@racc_state.push act
@@ -440,13 +431,10 @@ def _racc_evalact(act, arg)
case @racc_error_status
when 0
unless arg[21] # user_yyerror
nerr += 1
on_error @racc_t, @racc_val, @racc_vstack
end
when 3
if @racc_t == 0 # is $
# We're at EOF, and another error occurred immediately after
# attempting auto-recovery
throw :racc_end_parse, nil
end
@racc_read_next = true
@@ -482,11 +470,10 @@ def _racc_evalact(act, arg)
end

def _racc_do_reduce(arg, act)
_, _, _, _,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, _, _,
_, use_result, * = arg

_, _, _, _,
goto_table, goto_check, goto_default, goto_pointer,
nt_base, reduce_table, _, _,
_, use_result, * = arg
state = @racc_state
vstack = @racc_vstack
tstack = @racc_tstack
@@ -582,6 +569,7 @@ def racc_reduce(toks, sim, tstack, vstack)
toks.each {|t| out.print ' ', racc_token2str(t) }
end
out.puts " --> #{racc_token2str(sim)}"

racc_print_stacks tstack, vstack
@racc_debug_out.puts
end

0 comments on commit 3fe1cc2

Please sign in to comment.