ruby / ruby/racc

`unused variable` warning is reported when grammer definition includes `*` qualifier

Open
#309 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Yacc
Stars
569
Forks
93
Avg merge
4d 19h
Merged PRs (30d)
4

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the grammar using the * qualifier and the generated test.tab.rb, especially the _reduce_1 and _reduce_2 methods shown in the report. Reproduce the warning with racc test.y followed by ruby -W test.tab.rb, then compare generated reductions with and without the qualifier. Done means the reproduced grammar no longer reports the unused result warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.