mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
reduce: don't complain about rules whose lhs is useless
In the following grammar, the 'exp' nonterminal is trivially useless.
So, of course, its rules are useless too.
%%
input: '0' | exp
exp: exp '+' exp | exp '-' exp | '(' exp ')'
Previously all the useless rules were reported, including those whose
left-hand side is the 'exp' nonterminal:
warning: 1 nonterminal useless in grammar [-Wother]
warning: 4 rules useless in grammar [-Wother]
2.14-16: warning: nonterminal useless in grammar: exp [-Wother]
input: '0' | exp
^^^
2.14-16: warning: rule useless in grammar [-Wother]
input: '0' | exp
^^^
! 3.6-16: warning: rule useless in grammar [-Wother]
! exp: exp '+' exp | exp '-' exp | '(' exp ')'
! ^^^^^^^^^^^
! 3.20-30: warning: rule useless in grammar [-Wother]
! exp: exp '+' exp | exp '-' exp | '(' exp ')'
! ^^^^^^^^^^^
! 3.34-44: warning: rule useless in grammar [-Wother]
! exp: exp '+' exp | exp '-' exp | '(' exp ')'
! ^^^^^^^^^^^
The interest of being so verbose is dubious. I suspect most of the
time nonterminals are not expected to be useless, so the user wants to
fix the nonterminal, not remove its rules. And even if the user
wanted to get rid of its rules, the position of these rules probably
does not help more that just having the name of the nonterminal.
This commit discard these messages, marked with '!', and keep the
others. In particular, we still report:
2.14-16: warning: rule useless in grammar [-Wother]
input: '0' | exp
^^^
All the useless rules (including the '!' ones) are still reported in
the reports (xml, text, etc.); only the diagnostics on stderr change.
* src/gram.c (grammar_rules_useless_report): Don't complain about
useless rules whose lhs is useless.
* src/reduce.h, src/reduce.c (reduce_nonterminal_useless_in_grammar):
Take a sym_content as argument.
Adjust callers.
* tests/reduce.at (Useless Rules, Underivable Rules, Reduced Automaton):
Adjust.
This commit is contained in:
44
NEWS
44
NEWS
@@ -2,6 +2,50 @@ GNU Bison NEWS
|
||||
|
||||
* Noteworthy changes in release ?.? (????-??-??) [?]
|
||||
|
||||
** Diagnostics about useless rules
|
||||
|
||||
In the following grammar, the 'exp' nonterminal is trivially useless. So,
|
||||
of course, its rules are useless too.
|
||||
|
||||
%%
|
||||
input: '0' | exp
|
||||
exp: exp '+' exp | exp '-' exp | '(' exp ')'
|
||||
|
||||
Previously all the useless rules were reported, including those whose
|
||||
left-hand side is the 'exp' nonterminal:
|
||||
|
||||
warning: 1 nonterminal useless in grammar [-Wother]
|
||||
warning: 4 rules useless in grammar [-Wother]
|
||||
2.14-16: warning: nonterminal useless in grammar: exp [-Wother]
|
||||
input: '0' | exp
|
||||
^^^
|
||||
2.14-16: warning: rule useless in grammar [-Wother]
|
||||
input: '0' | exp
|
||||
^^^
|
||||
3.6-16: warning: rule useless in grammar [-Wother]
|
||||
exp: exp '+' exp | exp '-' exp | '(' exp ')'
|
||||
^^^^^^^^^^^
|
||||
3.20-30: warning: rule useless in grammar [-Wother]
|
||||
exp: exp '+' exp | exp '-' exp | '(' exp ')'
|
||||
^^^^^^^^^^^
|
||||
3.34-44: warning: rule useless in grammar [-Wother]
|
||||
exp: exp '+' exp | exp '-' exp | '(' exp ')'
|
||||
^^^^^^^^^^^
|
||||
|
||||
Now, rules whose left-hand side symbol is useless are no longer reported
|
||||
as useless.
|
||||
|
||||
warning: 1 nonterminal useless in grammar [-Wother]
|
||||
warning: 4 rules useless in grammar [-Wother]
|
||||
2.14-16: warning: nonterminal useless in grammar: exp [-Wother]
|
||||
input: '0' | exp
|
||||
^^^
|
||||
2.14-16: warning: rule useless in grammar [-Wother]
|
||||
input: '0' | exp
|
||||
^^^
|
||||
|
||||
* Noteworthy changes in release ?.? (????-??-??) [?]
|
||||
|
||||
** Bug fixes
|
||||
|
||||
*** C++ with Variants (lalr1.cc)
|
||||
|
||||
Reference in New Issue
Block a user