bison-patches
[Top][All Lists]
Advanced

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

style: avoid explicit symbol numbers


From: Akim Demaille
Subject: style: avoid explicit symbol numbers
Date: Sat, 7 Nov 2020 17:02:38 +0100

This completes 
<URL:https://lists.gnu.org/archive/html/bison-patches/2020-09/msg00112.html>.

commit 5a31cda4c3a2a8e94edaea634a4f917c421f6954
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Sat Nov 7 16:21:00 2020 +0100

    style: avoid explicit symbol numbers
    
    This should have been part of commit "symbols: stop dealing with YYEMPTY
    as b4_symbol(-2, ...)" (cd40ec9526df27d0e3e1c2d41e82a3e6a47254d1).
    Give names to all the special symbols: "eof", "error" and "undef".
    
    * data/skeletons/bison.m4 (b4_symbol): Let `b4_symbol(eof, ...)` mean
    `b4_symbol(0, ...)`, `b4_symbol(error, ...)` mean `b4_symbol(1, ...)`,
    and , `b4_symbol(undef, ...)` mean `b4_symbol(2, ...)`..
    
    * data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/glr.cc,
    * data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
    * data/skeletons/lalr1.d, data/skeletons/lalr1.java,
    * data/skeletons/yacc.c:
    Prefer symbols to numbers.

diff --git a/data/README.md b/data/README.md
index 59b220b0..32c34a53 100644
--- a/data/README.md
+++ b/data/README.md
@@ -81,7 +81,12 @@ name, whether terminal, etc.), bison.exe defines one macro 
per (token,
 field), where field can `has_id`, `id`, etc.: see
 `prepare_symbols_definitions()` in `src/output.c`.
 
-The macro `b4_symbol(NUM, FIELD)` gives access to the following FIELDS:
+NUM can be:
+- `empty` to denote the "empty" pseudo-symbol when it exists,
+- `eof`, `error`, or `undef`
+- a symbol number.
+
+FIELD can be:
 
 - `has_id`: 0 or 1
   Whether the symbol has an `id`.
diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4
index bd16190d..c9df0e02 100644
--- a/data/skeletons/bison.m4
+++ b/data/skeletons/bison.m4
@@ -484,8 +484,10 @@ m4_define([b4_symbol_slot],
 #
 # If FIELD = id, prepend the token prefix.
 m4_define([b4_symbol],
-[m4_if([$1], [empty],
-       [b4_symbol([-2], [$2])],
+[m4_if([$1], [empty], [b4_symbol([-2], [$2])],
+       [$1], [eof],   [b4_symbol([0], [$2])],
+       [$1], [error], [b4_symbol([1], [$2])],
+       [$1], [undef], [b4_symbol([2], [$2])],
        [m4_case([$2],
                 [id],        [b4_symbol_token_kind([$1])],
                 [kind_base], [b4_symbol_kind_base([$1])],
diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index 256dae34..eddc76a2 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -504,7 +504,7 @@ static const b4_int_type_for([$2]) yy$1[[]] =
 m4_define([b4_symbol(-2, id)],  [b4_api_PREFIX[][EMPTY]])
 m4_define([b4_symbol(-2, tag)], [[No symbol.]])
 
-m4_if(b4_symbol(0, id), [YYEOF],
+m4_if(b4_symbol(eof, id), [YYEOF],
      [m4_define([b4_symbol(0, id)],  [b4_api_PREFIX[][EOF]])])
 m4_define([b4_symbol(1, id)],  [b4_api_PREFIX[][error]])
 m4_define([b4_symbol(2, id)],  [b4_api_PREFIX[][UNDEF]])
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 45d1ca87..f1594b2f 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -829,14 +829,14 @@ yygetToken (int *yycharp][]b4_pure_if([, yyGLRStack* 
yystackp])[]b4_user_formals
           // Map errors caught in the scanner to the undefined token,
           // so that error handling is started.  However, record this
           // with this special value of yychar.
-          *yycharp = ]b4_symbol(1, id)[;
+          *yycharp = ]b4_symbol(error, id)[;
         }
 #endif // YY_EXCEPTIONS]], [[
       *yycharp = ]b4_lex[;]])[
     }
-  if (*yycharp <= ]b4_symbol(0, [id])[)
+  if (*yycharp <= ]b4_symbol(eof, [id])[)
     {
-      *yycharp = ]b4_symbol(0, [id])[;
+      *yycharp = ]b4_symbol(eof, [id])[;
       yytoken = ]b4_symbol_prefix[YYEOF;
       YY_DPRINTF ((stderr, "Now at end of input.\n"));
     }
@@ -1034,7 +1034,7 @@ static inline int
 yygetLRActions (yy_state_t yystate, yysymbol_kind_t yytoken, const short** 
yyconflicts)
 {
   int yyindex = yypact[yystate] + yytoken;
-  if (yytoken == ]b4_symbol(1, kind)[)
+  if (yytoken == ]b4_symbol(error, kind)[)
     {
       // This is the error token.
       *yyconflicts = yyconfl;
@@ -2112,7 +2112,7 @@ yypcontext_expected_tokens (const yyGLRStack* yystackp,
       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
       int yyx;
       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-        if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[
+        if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
             && !yytable_value_is_error (yytable[yyx + yyn]))
           {
             if (!yyarg)
@@ -2320,7 +2320,7 @@ yyrecoverSyntaxError (yyGLRStack* 
yystackp]b4_user_formals[)
       {
         yysymbol_kind_t yytoken;
         int yyj;
-        if (yychar == ]b4_symbol(0, [id])[)
+        if (yychar == ]b4_symbol(eof, [id])[)
           yyFail (yystackp][]b4_lpure_args[, YY_NULLPTR);
         if (yychar != ]b4_symbol(empty, id)[)
           {]b4_locations_if([[
@@ -2372,8 +2372,8 @@ yyrecoverSyntaxError (yyGLRStack* 
yystackp]b4_user_formals[)
       int yyj = yypact[yys->yylrState];
       if (! yypact_value_is_default (yyj))
         {
-          yyj += ]b4_symbol(1, kind)[;
-          if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(1, kind)[
+          yyj += ]b4_symbol(error, kind)[;
+          if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == ]b4_symbol(error, 
kind)[
               && yyisShiftAction (yytable[yyj]))
             {
               /* Shift the error token.  */
@@ -2496,7 +2496,7 @@ b4_dollar_popdef])[]dnl
                   yystack.yyerror_range[1].yystate.yyloc = yylloc;]])[
                   /* Issue an error message unless the scanner already
                      did. */
-                  if (yychar != ]b4_symbol(1, id)[)
+                  if (yychar != ]b4_symbol(error, id)[)
                     yyreportSyntaxError (&yystack]b4_user_args[);
                   goto yyuser_error;
                 }
diff --git a/data/skeletons/glr.cc b/data/skeletons/glr.cc
index f55da2b6..9677ea57 100644
--- a/data/skeletons/glr.cc
+++ b/data/skeletons/glr.cc
@@ -241,10 +241,10 @@ m4_define([b4_glr_cc_setup],
 
 #undef ]b4_symbol(empty, [id])[
 #define ]b4_symbol(empty, [id])[ 
]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(empty, [id])[
-#undef ]b4_symbol(0, [id])[
-#define ]b4_symbol(0, [id])[ 
]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(0, [id])[
-#undef ]b4_symbol(1, [id])[
-#define ]b4_symbol(1, [id])[ 
]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(1, [id])[
+#undef ]b4_symbol(eof, [id])[
+#define ]b4_symbol(eof, [id])[ 
]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(eof, [id])[
+#undef ]b4_symbol(error, [id])[
+#define ]b4_symbol(error, [id])[ 
]b4_namespace_ref[::]b4_parser_class[::token::]b4_symbol(error, [id])[
 
 #ifndef ]b4_api_PREFIX[STYPE
 # define ]b4_api_PREFIX[STYPE 
]b4_namespace_ref[::]b4_parser_class[::semantic_type
@@ -271,8 +271,8 @@ m4_define([b4_undef_symbol_kind],
 # Remove redirections for glr.c.
 m4_define([b4_glr_cc_cleanup],
 [[#undef ]b4_symbol(empty, [id])[
-#undef ]b4_symbol(0, [id])[
-#undef ]b4_symbol(1, [id])[
+#undef ]b4_symbol(eof, [id])[
+#undef ]b4_symbol(error, [id])[
 
 ]b4_undef_symbol_kind(-2)dnl
 b4_symbol_foreach([b4_undef_symbol_kind])dnl
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 9cdad84b..9bacbdfb 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -91,8 +91,8 @@ typedef 
]b4_namespace_ref[::]b4_parser_class[::symbol_kind_type yysymbol_kind_t;
 # Remove redirections for glr.c.
 m4_define([b4_glr_cc_cleanup],
 [[#undef ]b4_symbol(empty, [id])[
-#undef ]b4_symbol(0, [id])[
-#undef ]b4_symbol(1, [id])[
+#undef ]b4_symbol(eof, [id])[
+#undef ]b4_symbol(error, [id])[
 #undef ]b4_symbol_prefix[YYEMPTY
 #undef ]b4_symbol_prefix[YYerror
 #undef ]b4_symbol_prefix[YYEOF
@@ -1919,7 +1919,7 @@ public:
             int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
             int yyx;
             for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-              if (yycheck[yyx + yyn] == yyx && yyx != 
]b4_namespace_ref::b4_parser_class::b4_symbol(1, kind)[
+              if (yycheck[yyx + yyn] == yyx && yyx != 
]b4_namespace_ref::b4_parser_class::b4_symbol(error, kind)[
                   && !yytable_value_is_error (yytable[yyx + yyn]))
                 {
                   if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
@@ -1981,7 +1981,7 @@ public:
         {
           yysymbol_kind_t yytoken;
           int yyj;
-          if (yychar == 
]b4_namespace_ref::b4_parser_class::token::b4_symbol(0, id)[)
+          if (yychar == 
]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, id)[)
             yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR);
           if (yychar != 
]b4_namespace_ref::b4_parser_class::token::b4_symbol(empty, id)[)
             {]b4_locations_if([[
@@ -2638,14 +2638,14 @@ yygetToken (int *yycharp, 
]b4_namespace_ref[::]b4_parser_class[& yyparser][]b4_p
           yyparser.error (]b4_locations_if([yylloc, ])[yyexc.what ());
           // Map errors caught in the scanner to the error token, so that error
           // handling is started.
-          *yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(1, 
id)[;
+          *yycharp = 
]b4_namespace_ref::b4_parser_class::token::b4_symbol(error, id)[;
         }
 #endif // YY_EXCEPTIONS
     }
-  if (*yycharp <= ]b4_namespace_ref::b4_parser_class::token::b4_symbol(0, id)[)
+  if (*yycharp <= ]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, 
id)[)
     {
-      *yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(0, id)[;
-      yytoken = ]b4_namespace_ref::b4_parser_class::b4_symbol(0, kind)[;
+      *yycharp = ]b4_namespace_ref::b4_parser_class::token::b4_symbol(eof, 
id)[;
+      yytoken = ]b4_namespace_ref::b4_parser_class::b4_symbol(eof, kind)[;
       YY_DEBUG_STREAM << "Now at end of input.\n";
     }
   else
@@ -2692,7 +2692,7 @@ static inline int
 yygetLRActions (state_num yystate, yysymbol_kind_t yytoken, const short** 
yyconflicts)
 {
   int yyindex = yypact[yystate] + yytoken;
-  if (yytoken == ]b4_namespace_ref::b4_parser_class[::]b4_symbol(1, kind)[)
+  if (yytoken == ]b4_namespace_ref::b4_parser_class[::]b4_symbol(error, kind)[)
     {
       // This is the error token.
       *yyconflicts = yyconfl;
@@ -2850,7 +2850,7 @@ b4_dollar_popdef])[]dnl
                   yystack.yyerror_range[1].getState().yyloc = yylloc;]])[
                   /* Don't issue an error message again for exceptions
                      thrown from the scanner.  */
-                  if (yychar != 
]b4_namespace_ref::b4_parser_class::token::b4_symbol(1, id)[)
+                  if (yychar != 
]b4_namespace_ref::b4_parser_class::token::b4_symbol(error, id)[)
                     yystack.yyreportSyntaxError ();
                   goto yyuser_error;
                 }
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index ddf70556..fbabba35 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -918,13 +918,13 @@ b4_dollar_popdef])[]dnl
       }
     YY_SYMBOL_PRINT ("Next token is", yyla);
 
-    if (yyla.kind () == ]b4_symbol(1, kind)[)
+    if (yyla.kind () == ]b4_symbol(error, kind)[)
     {
       // The scanner already issued an error message, process directly
       // to error recovery.  But do not keep the error token as
       // lookahead, it is too special and may lead us to an endless
       // loop in error recovery. */
-      yyla.kind_ = ]b4_symbol(2, kind)[;
+      yyla.kind_ = ]b4_symbol(undef, kind)[;
       goto yyerrlab1;
     }
 
@@ -1061,7 +1061,7 @@ b4_dollar_popdef])[]dnl
            error, discard it.  */
 
         // Return failure if at end of input.
-        if (yyla.kind () == ]b4_symbol(0, kind)[)
+        if (yyla.kind () == ]b4_symbol(eof, kind)[)
           YYABORT;
         else if (!yyla.empty ())
           {
@@ -1102,9 +1102,9 @@ b4_dollar_popdef])[]dnl
         yyn = yypact_[+yystack_[0].state];
         if (!yy_pact_value_is_default_ (yyn))
           {
-            yyn += ]b4_symbol(1, kind)[;
+            yyn += ]b4_symbol(error, kind)[;
             if (0 <= yyn && yyn <= yylast_
-                && yycheck_[yyn] == ]b4_symbol(1, kind)[)
+                && yycheck_[yyn] == ]b4_symbol(error, kind)[)
               {
                 yyn = yytable_[yyn];
                 if (0 < yyn)
@@ -1296,8 +1296,8 @@ b4_dollar_popdef])[]dnl
     for (int yyx = 0; yyx < YYNTOKENS; ++yyx)
       {
         symbol_kind_type yysym = YY_CAST (symbol_kind_type, yyx);
-        if (yysym != ]b4_symbol(1, kind)[
-            && yysym != ]b4_symbol(2, kind)[
+        if (yysym != ]b4_symbol(error, kind)[
+            && yysym != ]b4_symbol(undef, kind)[
             && yyparser_.yy_lac_check_ (yysym))
           {
             if (!yyarg)
@@ -1319,7 +1319,7 @@ b4_dollar_popdef])[]dnl
         int yychecklim = yylast_ - yyn + 1;
         int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
         for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
-          if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[
+          if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
               && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
             {
               if (!yyarg)
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 1168b910..2334e8c6 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -480,14 +480,14 @@ m4_popdef([b4_at_dollar])])dnl
         yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
         yy_symbol_print ("Next token is", yytoken, yylval]b4_locations_if([, 
yylloc])[);]])[
 
-        if (yytoken == ]b4_symbol(1, kind)[)
+        if (yytoken == ]b4_symbol(error, kind)[)
         {
           // The scanner already issued an error message, process directly
           // to error recovery.  But do not keep the error token as
           // lookahead, it is too special and may lead us to an endless
           // loop in error recovery. */
-          yychar = TokenKind.]b4_symbol(2, id)[;
-          yytoken = ]b4_symbol(2, kind)[;]b4_locations_if([[
+          yychar = TokenKind.]b4_symbol(undef, id)[;
+          yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
           yyerrloc = yylloc;]])[
           label = YYERRLAB1;
         }
@@ -569,10 +569,10 @@ m4_popdef([b4_at_dollar])])dnl
           /* If just tried and failed to reuse lookahead token after an
            * error, discard it.  */
 
-          if (yychar <= TokenKind.]b4_symbol(0, [id])[)
+          if (yychar <= TokenKind.]b4_symbol(eof, [id])[)
           {
             /* Return failure if at end of input.  */
-            if (yychar == TokenKind.]b4_symbol(0, [id])[)
+            if (yychar == TokenKind.]b4_symbol(eof, [id])[)
              return false;
           }
           else
@@ -609,8 +609,8 @@ m4_popdef([b4_at_dollar])])dnl
           yyn = yypact_[yystate];
           if (!yyPactValueIsDefault(yyn))
           {
-            yyn += ]b4_symbol(1, kind)[;
-            if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == ]b4_symbol(1, 
kind)[)
+            yyn += ]b4_symbol(error, kind)[;
+            if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == 
]b4_symbol(error, kind)[)
             {
               yyn = yytable_[yyn];
               if (0 < yyn)
@@ -772,7 +772,7 @@ m4_popdef([b4_at_dollar])])dnl
         int yychecklim = yylast_ - yyn + 1;
         int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
         for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
-          if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[
+          if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
               && !yyTableValueIsError(yytable_[yyx + yyn]))
           {
             if (yyarg is null)
@@ -861,11 +861,11 @@ m4_popdef([b4_at_dollar])])dnl
     immutable int code_max = ]b4_code_max[;
 
     if (t <= 0)
-      return ]b4_symbol(0, kind)[;
+      return ]b4_symbol(eof, kind)[;
     else if (t <= code_max)
       return SymbolKind(translate_table[t]);
     else
-      return ]b4_symbol(2, kind)[;]])[
+      return ]b4_symbol(undef, kind)[;]])[
   }
 
   private static immutable int yylast_ = ]b4_last[;
diff --git a/data/skeletons/lalr1.java b/data/skeletons/lalr1.java
index 26508a8c..1db2795d 100644
--- a/data/skeletons/lalr1.java
+++ b/data/skeletons/lalr1.java
@@ -199,8 +199,8 @@ import java.util.ArrayList;
    */
   public interface Lexer {
 ]b4_token_enums[
-    /** Deprecated, use ]b4_symbol(0, id)[ instead.  */
-    public static final int EOF = ]b4_symbol(0, id)[;
+    /** Deprecated, use ]b4_symbol(eof, id)[ instead.  */
+    public static final int EOF = ]b4_symbol(eof, id)[;
 ]b4_pull_if([b4_locations_if([[
     /**
      * Method to retrieve the beginning position of the last scanned token.
@@ -643,14 +643,14 @@ b4_dollar_popdef[]dnl
         yySymbolPrint("Next token is", yytoken,
                       yylval]b4_locations_if([, yylloc])[);]])[
 
-        if (yytoken == ]b4_symbol(1, kind)[)
+        if (yytoken == ]b4_symbol(error, kind)[)
           {
             // The scanner already issued an error message, process directly
             // to error recovery.  But do not keep the error token as
             // lookahead, it is too special and may lead us to an endless
             // loop in error recovery. */
-            yychar = Lexer.]b4_symbol(2, id)[;
-            yytoken = ]b4_symbol(2, kind)[;]b4_locations_if([[
+            yychar = Lexer.]b4_symbol(undef, id)[;
+            yytoken = ]b4_symbol(undef, kind)[;]b4_locations_if([[
             yyerrloc = yylloc;]])[
             label = YYERRLAB1;
           }
@@ -740,10 +740,10 @@ b4_dollar_popdef[]dnl
             /* If just tried and failed to reuse lookahead token after an
                error, discard it.  */
 
-            if (yychar <= Lexer.]b4_symbol(0, id)[)
+            if (yychar <= Lexer.]b4_symbol(eof, id)[)
               {
                 /* Return failure if at end of input.  */
-                if (yychar == Lexer.]b4_symbol(0, id)[)
+                if (yychar == Lexer.]b4_symbol(eof, id)[)
                   ]b4_push_if([{label = YYABORT; break;}], [return false;])[
               }
             else
@@ -780,9 +780,9 @@ b4_dollar_popdef[]dnl
             yyn = yypact_[yystate];
             if (!yyPactValueIsDefault (yyn))
               {
-                yyn += ]b4_symbol(1, kind)[.getCode();
+                yyn += ]b4_symbol(error, kind)[.getCode();
                 if (0 <= yyn && yyn <= YYLAST_
-                    && yycheck_[yyn] == ]b4_symbol(1, kind)[.getCode())
+                    && yycheck_[yyn] == ]b4_symbol(error, kind)[.getCode())
                   {
                     yyn = yytable_[yyn];
                     if (0 < yyn)
@@ -964,8 +964,8 @@ b4_dollar_popdef[]dnl
       for (int yyx = 0; yyx < YYNTOKENS_; ++yyx)
         {
           SymbolKind yysym = SymbolKind.get(yyx);
-          if (yysym != ]b4_symbol(1, kind)[
-              && yysym != ]b4_symbol(2, kind)[
+          if (yysym != ]b4_symbol(error, kind)[
+              && yysym != ]b4_symbol(undef, kind)[
               && yyparser.yylacCheck(yystack, yysym))
             {
               if (yyarg == null)
@@ -988,7 +988,7 @@ b4_dollar_popdef[]dnl
           int yychecklim = YYLAST_ - yyn + 1;
           int yyxend = yychecklim < NTOKENS ? yychecklim : NTOKENS;
           for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
-            if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(1, 
kind)[.getCode()
+            if (yycheck_[yyx + yyn] == yyx && yyx != ]b4_symbol(error, 
kind)[.getCode()
                 && !yyTableValueIsError(yytable_[yyx + yyn]))
               {
                 if (yyarg == null)
@@ -1282,11 +1282,11 @@ b4_dollar_popdef[]dnl
     // Last valid token kind.
     int code_max = ]b4_code_max[;
     if (t <= 0)
-      return ]b4_symbol(0, kind)[;
+      return ]b4_symbol(eof, kind)[;
     else if (t <= code_max)
       return SymbolKind.get(yytranslate_table_[t]);
     else
-      return ]b4_symbol(2, kind)[;
+      return ]b4_symbol(undef, kind)[;
   }
   ]b4_integral_parser_table_define([translate_table], [b4_translate])[
 ]])[
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index cd142055..fdec3c8a 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -755,8 +755,8 @@ enum { YYENOMEM = -2 };
   while (0)
 
 /* Backward compatibility with an undocumented macro.
-   Use ]b4_symbol(1, id)[ or ]b4_symbol(2, id)[. */
-#define YYERRCODE ]b4_symbol(2, id)[
+   Use ]b4_symbol(error, id)[ or ]b4_symbol(undef, id)[. */
+#define YYERRCODE ]b4_symbol(undef, id)[
 ]b4_locations_if([[
 ]b4_yylloc_default_define[
 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
@@ -1165,7 +1165,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
   for (yyx = 0; yyx < YYNTOKENS; ++yyx)
     {
       yysymbol_kind_t yysym = YY_CAST (yysymbol_kind_t, yyx);
-      if (yysym != ]b4_symbol(1, kind)[ && yysym != ]b4_symbol_prefix[YYUNDEF)
+      if (yysym != ]b4_symbol(error, kind)[ && yysym != 
]b4_symbol_prefix[YYUNDEF)
         switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, 
&yyps->yyes_capacity, yyps->yyssp, yysym]],
                                     [[yyctx->yyesa, yyctx->yyes, 
yyctx->yyes_capacity, yyctx->yyssp, yysym]])[))
           {
@@ -1194,7 +1194,7 @@ yypcontext_expected_tokens (const yypcontext_t *yyctx,
       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
       int yyx;
       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-        if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(1, kind)[
+        if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[
             && !yytable_value_is_error (yytable[yyx + yyn]))
           {
             if (!yyarg)
@@ -1820,20 +1820,20 @@ yyread_pushed_token:]])[
       yychar = ]b4_lex[;]])[
     }
 
-  if (yychar <= ]b4_symbol(0, [id])[)
+  if (yychar <= ]b4_symbol(eof, [id])[)
     {
-      yychar = ]b4_symbol(0, [id])[;
-      yytoken = ]b4_symbol(0, [kind])[;
+      yychar = ]b4_symbol(eof, [id])[;
+      yytoken = ]b4_symbol(eof, [kind])[;
       YYDPRINTF ((stderr, "Now at end of input.\n"));
     }
-  else if (yychar == ]b4_symbol(1, [id])[)
+  else if (yychar == ]b4_symbol(error, [id])[)
     {
       /* The scanner already issued an error message, process directly
          to error recovery.  But do not keep the error token as
          lookahead, it is too special and may lead us to an endless
          loop in error recovery. */
-      yychar = ]b4_symbol(2, [id])[;
-      yytoken = ]b4_symbol(1, [kind])[;]b4_locations_if([[
+      yychar = ]b4_symbol(undef, [id])[;
+      yytoken = ]b4_symbol(error, [kind])[;]b4_locations_if([[
       yyerror_range[1] = yylloc;]])[
       goto yyerrlab1;
     }
@@ -2026,10 +2026,10 @@ yyerrlab:
       /* If just tried and failed to reuse lookahead token after an
          error, discard it.  */
 
-      if (yychar <= ]b4_symbol(0, [id])[)
+      if (yychar <= ]b4_symbol(eof, [id])[)
         {
           /* Return failure if at end of input.  */
-          if (yychar == ]b4_symbol(0, [id])[)
+          if (yychar == ]b4_symbol(eof, [id])[)
             YYABORT;
         }
       else
@@ -2076,8 +2076,8 @@ yyerrlab1:
       yyn = yypact[yystate];
       if (!yypact_value_is_default (yyn))
         {
-          yyn += ]b4_symbol(1, kind)[;
-          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(1, 
kind)[)
+          yyn += ]b4_symbol(error, kind)[;
+          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == ]b4_symbol(error, 
kind)[)
             {
               yyn = yytable[yyn];
               if (0 < yyn)




reply via email to

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