Skip to content

unused variable warning is reported when grammer definition includes * qualifier #309

@taichi-ishitani

Description

@taichi-ishitani

Ruby reports unused variable warning for source file generated from the grammar definition includes * qualifier.

How to reproduce:

Give the source file geneated from the grammer definition below to Ruby with -W option.

class TestParser
options no_result_var

rule
  root
    : 'a' 'b'*
$ racc --version
racc version 1.8.1
$ racc test.y
$ ruby -W test.tab.rb
test.y:8: warning: assigned but unused variable - result
test.y:8: warning: assigned but unused variable - result

Ruby code below is geneated from the the above grammer definition.

#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.8.1
# from Racc grammar file "test.y".
#

require 'racc/parser.rb'
class TestParser < Racc::Parser
##### State transition tables begin ###

racc_action_table = [
     2,     3,     4,     6,     4 ]

racc_action_check = [
     0,     1,     2,     3,     4 ]

racc_action_pointer = [
    -2,     1,    -1,     3,     1,   nil,   nil,   nil ]

racc_action_default = [
    -4,    -4,    -1,    -4,    -1,    -3,     8,    -2 ]

racc_goto_table = [
     5,     1,     7 ]

racc_goto_check = [
     2,     1,     2 ]

racc_goto_pointer = [
   nil,     1,    -2 ]

racc_goto_default = [
   nil,   nil,   nil ]

racc_reduce_table = [
  0, 0, :racc_error,
  0, 6, :_reduce_1,
  2, 6, :_reduce_2,
  2, 5, :_reduce_none ]

racc_reduce_n = 4

racc_shift_n = 8

racc_token_table = {
  false => 0,
  :error => 1,
  "a" => 2,
  "b" => 3 }

racc_nt_base = 4

racc_use_result_var = false

Racc_arg = [
  racc_action_table,
  racc_action_check,
  racc_action_default,
  racc_action_pointer,
  racc_goto_table,
  racc_goto_check,
  racc_goto_default,
  racc_goto_pointer,
  racc_nt_base,
  racc_reduce_table,
  racc_token_table,
  racc_shift_n,
  racc_reduce_n,
  racc_use_result_var ]
Ractor.make_shareable(Racc_arg) if defined?(Ractor)

Racc_token_to_s_table = [
  "$end",
  "error",
  "\"a\"",
  "\"b\"",
  "$start",
  "root",
  "\"-many@b\"" ]
Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor)

Racc_debug_parser = false

##### State transition tables end #####

# reduce 0 omitted

module_eval(<<'.,.,', 'test.y', 7)
  def _reduce_1(val, _values)
    result = val[1] ? val[1].unshift(val[0]) : val
  end
.,.,

module_eval(<<'.,.,', 'test.y', 7)
  def _reduce_2(val, _values)
    result = val[1] ? val[1].unshift(val[0]) : val
  end
.,.,

# reduce 3 omitted

def _reduce_none(val, _values)
  val[0]
end

end   # class TestParser

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions