parser: deprecate %nterm

It has several weaknesses.
Reported by Rici Lake.
http://lists.gnu.org/archive/html/bug-bison/2018-10/msg00000.html

* src/scan-gram.l: here.
This commit is contained in:
Akim Demaille
2018-11-11 19:16:56 +01:00
parent 8d454b843c
commit 7928c3e6fb
5 changed files with 30 additions and 32 deletions

7
NEWS
View File

@@ -10,12 +10,19 @@ GNU Bison NEWS
- relative paths (allowing to relocate an installation of bison)
- use gettext-h in gnulib instead of gettext
- constexpr/noexcept in C++
- resolving %type/%nterm/%type inconsistencies
** Backward incompatible changes
Support for DJGPP, which has been unmaintained and untested for years, is
removed.
** 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.
* Noteworthy changes in release 3.2.1 (2018-11-09) [stable]
** Bug fixes

View File

@@ -240,7 +240,6 @@ eqopt ([[:space:]]*=)?
"%no-lines" return PERCENT_NO_LINES;
"%nonassoc" return PERCENT_NONASSOC;
"%nondeterministic-parser" return PERCENT_NONDETERMINISTIC_PARSER;
"%nterm" return PERCENT_NTERM;
"%output" return PERCENT_OUTPUT;
"%param" RETURN_PERCENT_PARAM(both);
"%parse-param" RETURN_PERCENT_PARAM(parse);
@@ -260,7 +259,7 @@ eqopt ([[:space:]]*=)?
"%verbose" return PERCENT_VERBOSE;
"%yacc" return PERCENT_YACC;
/* deprecated */
/* Deprecated since Bison 2.7.90, 2012. */
"%default"[-_]"prec" DEPRECATED("%default-prec");
"%error"[-_]"verbose" DEPRECATED("%define parse.error verbose");
"%expect"[-_]"rr" DEPRECATED("%expect-rr");
@@ -273,6 +272,12 @@ 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

@@ -210,7 +210,7 @@ AT_DATA_GRAMMAR([input.yy],
[[%skeleton "lalr1.cc"
%define api.value.automove
%token <int> NUMBER "number"
%nterm <int> exp
%type <int> exp
%%
exp:
"number" { $$ = $1; $$; }
@@ -576,7 +576,7 @@ AT_DATA_GRAMMAR([[input.y]],
}
%token <int> NUMBER;
%nterm <int> expr;
%type <int> expr;
%token EOI 0;
%printer { yyo << $$; } <int>;
%destructor { std::cerr << "destroy: " << $$ << '\n'; } <int>

View File

@@ -73,32 +73,20 @@ AT_DATA([[input.y]],
[[%verbose
%output "input.c"
%nterm useless1
%nterm useless2
%nterm useless3
%nterm useless4
%nterm useless5
%nterm useless6
%nterm useless7
%nterm useless8
%nterm useless9
%token useful
%%
exp: useful;
useless1:
useless2:
useless3:
]])
AT_BISON_CHECK([[input.y]], 0, [],
[[input.y: warning: 9 nonterminals useless in grammar [-Wother]
input.y:4.8-15: warning: nonterminal useless in grammar: useless1 [-Wother]
input.y:5.8-15: warning: nonterminal useless in grammar: useless2 [-Wother]
input.y:6.8-15: warning: nonterminal useless in grammar: useless3 [-Wother]
input.y:7.8-15: warning: nonterminal useless in grammar: useless4 [-Wother]
input.y:8.8-15: warning: nonterminal useless in grammar: useless5 [-Wother]
input.y:9.8-15: warning: nonterminal useless in grammar: useless6 [-Wother]
input.y:10.8-15: warning: nonterminal useless in grammar: useless7 [-Wother]
input.y:11.8-15: warning: nonterminal useless in grammar: useless8 [-Wother]
input.y:12.8-15: warning: nonterminal useless in grammar: useless9 [-Wother]
[[input.y: warning: 3 nonterminals useless in grammar [-Wother]
input.y: warning: 3 rules useless in grammar [-Wother]
input.y:7.1-8: warning: nonterminal useless in grammar: useless1 [-Wother]
input.y:8.1-8: warning: nonterminal useless in grammar: useless2 [-Wother]
input.y:9.1-8: warning: nonterminal useless in grammar: useless3 [-Wother]
]])
AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
@@ -106,12 +94,10 @@ AT_CHECK([[sed -n '/^Grammar/q;/^$/!p' input.output]], 0,
useless1
useless2
useless3
useless4
useless5
useless6
useless7
useless8
useless9
Rules useless in grammar
2 useless1: %empty
3 useless2: %empty
4 useless3: %empty
]])
AT_CLEANUP

View File

@@ -344,7 +344,7 @@ AT_TEST([%destructor syncline],
%union {
int ival;
}
%nterm <ival> exp
%type <ival> exp
%%
exp: '0' { $$ = 0; };
%%
@@ -369,7 +369,7 @@ AT_TEST([%printer syncline],
%union {
int ival;
}
%nterm <ival> exp
%type <ival> exp
%%
exp: '0' { $$ = 0; };
%%