bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

parser: reprecate %nterm back


From: Akim Demaille
Subject: parser: reprecate %nterm back
Date: Fri, 14 Dec 2018 05:10:56 +0100

commit aadf6c0bf355359c7cee6e69d80a4b9c8ab91340
Author: Akim Demaille <address@hidden>
Date:   Thu Dec 13 08:19:54 2018 +0100

    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 7928c3e6fbdf47ff81184966cee937e6aa694b94.
    
    * 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
    20b07467938cf880a1d30eb30d6e191843a21fec.

diff --git a/NEWS b/NEWS
index 5f23fa79..b62141f1 100644
--- a/NEWS
+++ b/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.
 
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 865153b5..279b6166 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -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
diff --git a/src/scan-gram.l b/src/scan-gram.l
index 61256a0d..d3662690 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -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));
   }
diff --git a/src/symtab.c b/src/symtab.c
index 0caf063a..7bc604b7 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -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)
         {
diff --git a/tests/input.at b/tests/input.at
index 44803ce5..2b0b5573 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]