mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
parser: reprecate %nterm back
After having spent quite some time on cleaning the handling of symbol
declarations in the grammar files, I believe we should keep it.
It looks like it's a duplicate of %type, but it is not. While POSIX
Yacc requires %type to apply only to nonterminal symbols, it appears
that both byacc and bison accept it for tokens too. And some
experienced users do actually expect this feature to group
symbols (terminal or not) by type ("On the other hand, it is generally
more useful IMHO to group terminals and non-terminals with the same
type tag together",
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html).
Even Bison's own parser does this today (see CHAR).
Basically reverts 7928c3e6fb.
* src/scan-gram.l (%nterm): Dedeprecate, but issue a Wyacc warning.
* tests/input.at: Adjust expectations.
(Yacc warnings on symbols): New.
* src/symtab.c (symbol_class_set): Fix error introduced in
20b0746793.
This commit is contained in:
4
NEWS
4
NEWS
@@ -19,10 +19,6 @@ GNU Bison NEWS
|
||||
|
||||
** Deprecated features
|
||||
|
||||
The directive %nterm, an historical heritage from an ancestor of Bison,
|
||||
was never officially documented. Its use now triggers warnings.
|
||||
Eventually, support will be removed. Use %type instead.
|
||||
|
||||
The use of the %error-verbose directive is deprecated in favor of "%define
|
||||
parse.error verbose" since Bison 3.0, but no warning was issued.
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
%printer { fprintf (yyo, "%d", $$); } <int>
|
||||
|
||||
%type <symbol*> id id_colon string_as_id symbol symbol.prec
|
||||
%printer { fprintf (yyo, "%s", $$->tag); } <symbol*>
|
||||
%printer { fprintf (yyo, "%s", $$ ? $$->tag : "<NULL>"); } <symbol*>
|
||||
%printer { fprintf (yyo, "%s:", $$->tag); } id_colon
|
||||
|
||||
%type <assoc> precedence_declarator
|
||||
|
||||
@@ -243,6 +243,7 @@ eqopt ([[:space:]]*=)?
|
||||
"%no-lines" return BISON_DIRECTIVE(NO_LINES);
|
||||
"%nonassoc" return PERCENT_NONASSOC;
|
||||
"%nondeterministic-parser" return BISON_DIRECTIVE(NONDETERMINISTIC_PARSER);
|
||||
"%nterm" return BISON_DIRECTIVE(NTERM);
|
||||
"%output" return BISON_DIRECTIVE(OUTPUT);
|
||||
"%param" RETURN_PERCENT_PARAM(both);
|
||||
"%parse-param" RETURN_PERCENT_PARAM(parse);
|
||||
@@ -279,12 +280,6 @@ eqopt ([[:space:]]*=)?
|
||||
"%pure"[-_]"parser" DEPRECATED("%pure-parser");
|
||||
"%token"[-_]"table" DEPRECATED("%token-table");
|
||||
|
||||
"%nterm" {
|
||||
/* Deprecated since Bison 3.3, but was a rather stealth feature. */
|
||||
deprecated_directive (loc, yytext, "%type");
|
||||
return PERCENT_NTERM;
|
||||
}
|
||||
|
||||
"%"{id} {
|
||||
complain (loc, complaint, _("invalid directive: %s"), quote (yytext));
|
||||
}
|
||||
|
||||
@@ -450,12 +450,11 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
||||
complain_class_redeclared (sym, class, loc);
|
||||
else
|
||||
{
|
||||
s->class = class;
|
||||
|
||||
if (class == nterm_sym && s->class != nterm_sym)
|
||||
s->number = nvars++;
|
||||
else if (class == token_sym && s->number == NUMBER_UNDEFINED)
|
||||
s->number = ntokens++;
|
||||
s->class = class;
|
||||
|
||||
if (declaring)
|
||||
{
|
||||
|
||||
@@ -130,6 +130,28 @@ AT_BISON_CHECK([input.y], [1], [],
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## -------------------------- ##
|
||||
## Yacc warnings on symbols. ##
|
||||
## -------------------------- ##
|
||||
|
||||
AT_SETUP([Yacc warnings on symbols])
|
||||
|
||||
AT_DATA([input.y],
|
||||
[[%nterm exp
|
||||
%token NUM 0x40 "number"
|
||||
%%
|
||||
exp: "number";
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
|
||||
[[input.y:1.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
|
||||
%nterm exp
|
||||
^^^^^^
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## --------------------- ##
|
||||
## Invalid %nterm uses. ##
|
||||
## --------------------- ##
|
||||
@@ -149,36 +171,21 @@ fact: "number";
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
||||
[[input.y:1.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
|
||||
%nterm expr "expression";
|
||||
^^^^^^
|
||||
input.y:1.13-24: error: nonterminals cannot be given a string alias
|
||||
[[input.y:1.13-24: error: nonterminals cannot be given a string alias
|
||||
%nterm expr "expression";
|
||||
^^^^^^^^^^^^
|
||||
input.y:2.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
|
||||
%nterm term 123;
|
||||
^^^^^^
|
||||
input.y:2.13-15: error: nonterminals cannot be given an explicit number
|
||||
%nterm term 123;
|
||||
^^^
|
||||
input.y:3.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
|
||||
%nterm fact 124 "factor";
|
||||
^^^^^^
|
||||
input.y:3.13-15: error: nonterminals cannot be given an explicit number
|
||||
%nterm fact 124 "factor";
|
||||
^^^
|
||||
input.y:3.17-24: error: nonterminals cannot be given a string alias
|
||||
%nterm fact 124 "factor";
|
||||
^^^^^^^^
|
||||
input.y:4.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
|
||||
%nterm '+' '*';
|
||||
^^^^^^
|
||||
input.y:4.8-10: error: character literals cannot be nonterminals
|
||||
%nterm '+' '*';
|
||||
^^^
|
||||
input.y:5.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
|
||||
%nterm "number";
|
||||
^^^^^^
|
||||
input.y:5.8-15: error: syntax error, unexpected string, expecting char or identifier or <tag>
|
||||
%nterm "number";
|
||||
^^^^^^^^
|
||||
@@ -499,10 +506,7 @@ BAR:
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret input.y], [1], [],
|
||||
[[input.y:2.1-6: warning: deprecated directive, use '%type' [-Wdeprecated]
|
||||
%nterm FOO BAR
|
||||
^^^^^^
|
||||
input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
|
||||
[[input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
|
||||
%nterm FOO BAR
|
||||
^^^
|
||||
input.y:1.8-10: previous definition
|
||||
|
||||
Reference in New Issue
Block a user