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:
Akim Demaille
2018-12-13 08:19:54 +01:00
parent dbb855895f
commit aadf6c0bf3
5 changed files with 27 additions and 33 deletions

View File

@@ -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

View File

@@ -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));
}

View File

@@ -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)
{