[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: %nterm directive incorrectly accepts character literals and quoted s
From: |
Akim Demaille |
Subject: |
Re: %nterm directive incorrectly accepts character literals and quoted strings |
Date: |
Mon, 12 Nov 2018 07:36:44 +0100 |
> Le 15 oct. 2018 à 20:26, Akim Demaille <address@hidden> a écrit :
>
> The first thing is to stop promoting it.
The second one would be to deprecate it clearly.
commit 7928c3e6fbdf47ff81184966cee937e6aa694b94
Author: Akim Demaille <address@hidden>
Date: Sun Nov 11 19:16:56 2018 +0100
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.
diff --git a/NEWS b/NEWS
index a9549a63..1ed54441 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/src/scan-gram.l b/src/scan-gram.l
index da6398be..22d56cbd 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -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));
}
diff --git a/tests/c++.at b/tests/c++.at
index b23f761b..9de1eb86 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -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>
diff --git a/tests/reduce.at b/tests/reduce.at
index 138f32dd..9c088a02 100644
--- a/tests/reduce.at
+++ b/tests/reduce.at
@@ -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
diff --git a/tests/synclines.at b/tests/synclines.at
index c0b16c7e..62f2a76b 100644
--- a/tests/synclines.at
+++ b/tests/synclines.at
@@ -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; };
%%
- Re: %nterm directive incorrectly accepts character literals and quoted strings,
Akim Demaille <=