bison-patches
[Top][All Lists]
Advanced

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

[PATCH 7/9] yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error


From: Akim Demaille
Subject: [PATCH 7/9] yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error
Date: Sat, 28 Mar 2020 18:40:04 +0100

* data/skeletons/bison.m4 (b4_symbol_sid): Map "error" to YYSYMBOL_YYERROR.
* data/skeletons/yacc.c: Adjust.
---
 TODO                    | 16 ----------------
 data/skeletons/bison.m4 |  7 ++++---
 data/skeletons/yacc.c   |  8 ++++----
 3 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/TODO b/TODO
index 0913481a..2489f7a4 100644
--- a/TODO
+++ b/TODO
@@ -52,22 +52,6 @@ would actually also make the following point gracefully 
handled (status of
 YYERRCODE, YYUNDEFTOK, etc.).  Possibly we could also define YYEMPTY (twice:
 as a token and as a symbol).  And YYEOF.
 
-It seems to work well.  Yet we have a weird case: the "error" token:
-
-enum yysymbol_code_t
-{
-  YYSYMBOL_YYEMPTY = -2,
-  YYSYMBOL_YYEOF = 0,
-  YYSYMBOL_error = 1,
-  YYSYMBOL_YYUNDEF = 2,
-  YYSYMBOL_YYACCEPT = 61,
-  ...
-
-YYSYMBOL_error looks weird.  We should maybe rename this as
-"YYSYMBOL_YYERROR", even though it should not be confonded with the YYERROR
-macro.
-
-
 ** Consistency
 YYUNDEFTOK is an internal symbol number, as YYTERROR.
 But YYERRCODE is an external token number.
diff --git a/data/skeletons/bison.m4 b/data/skeletons/bison.m4
index 20de1b7e..d54ea2b7 100644
--- a/data/skeletons/bison.m4
+++ b/data/skeletons/bison.m4
@@ -413,9 +413,10 @@ m4_define([b4_symbol_sid],
 [m4_case([$1],
   [-2],                           [[YYSYMBOL_YYEMPTY]],
   [0],                            [[YYSYMBOL_YYEOF]],
-  [m4_bmatch(m4_quote(b4_symbol([$1], [tag])),
-      [^\$accept$],               [[YYSYMBOL_YYACCEPT]],
-      [^\$undefined$],            [[YYSYMBOL_YYUNDEF]],
+  [m4_case(m4_quote(b4_symbol([$1], [tag])),
+      [$accept],                  [[YYSYMBOL_YYACCEPT]],
+      [error],                    [[YYSYMBOL_YYERROR]],
+      [$undefined],               [[YYSYMBOL_YYUNDEF]],
       [m4_quote(b4_symbol_if([$1], [has_id],
                                   [[YYSYMBOL_]]m4_quote(_b4_symbol([$1], 
[id]))))])])])
 
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 2ee1fe3f..6d8091ec 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -1147,7 +1147,7 @@ yyexpected_tokens (const yyparse_context_t *yyctx,
 ]b4_lac_if([[
   int yyx;
   for (yyx = 0; yyx < YYNTOKENS; ++yyx)
-    if (yyx != YYSYMBOL_error && yyx != YYSYMBOL_YYUNDEF)
+    if (yyx != YYSYMBOL_YYERROR && yyx != YYSYMBOL_YYUNDEF)
       switch (yy_lac (]b4_push_if([[yyps->yyesa, &yyps->yyes, 
&yyps->yyes_capacity, yyps->yyssp, yyx]],
                                   [[yyctx->yyesa, yyctx->yyes, 
yyctx->yyes_capacity, yyctx->yyssp, yyx]])[))
         {
@@ -1175,7 +1175,7 @@ yyexpected_tokens (const yyparse_context_t *yyctx,
       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
       int yyx;
       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
-        if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_error
+        if (yycheck[yyx + yyn] == yyx && yyx != YYSYMBOL_YYERROR
             && !yytable_value_is_error (yytable[yyx + yyn]))
           {
             if (!yyarg)
@@ -1998,8 +1998,8 @@ yyerrlab1:
       yyn = yypact[yystate];
       if (!yypact_value_is_default (yyn))
         {
-          yyn += YYSYMBOL_error;
-          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_error)
+          yyn += YYSYMBOL_YYERROR;
+          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYERROR)
             {
               yyn = yytable[yyn];
               if (0 < yyn)
-- 
2.25.1




reply via email to

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