mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-14 06:43:03 +00:00
symbol: use the first occurrence as an LHS as defining location
Currently on the following grammar:
%type <foo> foo
%%
start: foo | bar | "baz"
foo: foo
bar: bar
bison reports:
warning: 2 nonterminals useless in grammar [-Wother]
warning: 4 rules useless in grammar [-Wother]
1.13-15: warning: nonterminal useless in grammar: foo [-Wother]
%type <foo> foo
^^^
3.14-16: warning: nonterminal useless in grammar: bar [-Wother]
start: foo | bar | "baz"
^^^
[...]
i.e., the location of the first occurrence of a symbol is taken as its
definition point. In the case of nonterminals, the first occurrence
as a left-hand side of a rule makes more sense:
warning: 2 nonterminals useless in grammar [-Wother]
warning: 4 rules useless in grammar [-Wother]
4.1-3: warning: nonterminal useless in grammar: foo [-Wother]
foo: foo
^^^
5.1-3: warning: nonterminal useless in grammar: bar [-Wother]
bar: bar
^^^
[...]
* src/symtab.h, src/symtab.c (symbol::location_of_lhs): New.
(symbol_location_as_lhs_set): New.
* src/parse-gram.y (current_lhs): Use it.
* tests/reduce.at: Update locations.
This commit is contained in:
9
NEWS
9
NEWS
@@ -33,13 +33,14 @@ GNU Bison NEWS
|
||||
^^^^^^^^^^^
|
||||
|
||||
Now, rules whose left-hand side symbol is useless are no longer reported
|
||||
as useless.
|
||||
as useless. The locations of the errors have also been adjusted to point
|
||||
to the first use of the nonterminal as a left-hand side of a rule:
|
||||
|
||||
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
|
||||
^^^
|
||||
3.1-3: warning: nonterminal useless in grammar: exp [-Wother]
|
||||
exp: exp '+' exp | exp '-' exp | '(' exp ')'
|
||||
^^^
|
||||
2.14-16: warning: rule useless in grammar [-Wother]
|
||||
input: '0' | exp
|
||||
^^^
|
||||
|
||||
Reference in New Issue
Block a user