Let yyerror always receive the msg as last argument, so that
authorAkim Demaille <akim@epita.fr>
Thu, 7 Nov 2002 12:52:19 +0000 (12:52 +0000)
committerAkim Demaille <akim@epita.fr>
Thu, 7 Nov 2002 12:52:19 +0000 (12:52 +0000)
yyerror can be variadic.
* data/yacc.c (b4_yyerror_args): New.
Use it when calling yyerror.
* data/glr.c (b4_yyerror_args, b4_lyyerror_args): New.
Use it when calling yyerror.
* doc/bison.texinfo (Error Reporting): Adjust.
* tests/calc.at (_AT_DATA_CALC_Y): Adjust.
* tests/cxx-type.at (_AT_TEST_GLR_CALC): Adjust.

ChangeLog
data/glr.c
data/yacc.c
doc/bison.texinfo
tests/calc.at
tests/cxx-type.at

index 6cbcf67797b13dd0bcb08d1d8cc7b28fa818ed79..27a868cb8509f22c00d56fd33d47c39a26686d60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-11-07  Akim Demaille  <akim@epita.fr>
+
+       Let yyerror always receive the msg as last argument, so that
+       yyerror can be variadic.
+
+       * data/yacc.c (b4_yyerror_args): New.
+       Use it when calling yyerror.
+       * data/glr.c (b4_yyerror_args, b4_lyyerror_args): New.
+       Use it when calling yyerror.
+       * doc/bison.texinfo (Error Reporting): Adjust.
+       * tests/calc.at (_AT_DATA_CALC_Y): Adjust.
+       * tests/cxx-type.at (_AT_TEST_GLR_CALC): Adjust.
+
 2002-11-07  Paul Eggert  <eggert@twinsun.com>
 
        * src/scan-gram.l (unexpected_end_of_file): New function.
 2002-11-07  Paul Eggert  <eggert@twinsun.com>
 
        * src/scan-gram.l (unexpected_end_of_file): New function.
index daea8b9919853a17b529595ba77887d755e11cec..0db475756f553ae91b4e74bc83dbf635de5c4254 100644 (file)
@@ -54,9 +54,25 @@ m4_define([b4_user_formals],
 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
 
 
 [m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
 
 
+# b4_yyerror_args
+# ---------------
+# Arguments passed to yyerror: user args plus yylloc.
+m4_define([b4_yyerror_args],
+[b4_pure_if([b4_location_if([yylocp, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
+
+
+# b4_lyyerror_args
+# ----------------
+# Same as above, but on the lookahead, hence yyllocp instead of yylocp.
+m4_define([b4_lyyerror_args],
+[b4_pure_if([b4_location_if([yyllocp, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
+
+
 # b4_pure_args
 # ------------
 # b4_pure_args
 # ------------
-# Arguments passed to yyerror: user args plus yylloc.
+# Arguments needed by yyerror: user args plus yylloc.
 m4_define([b4_pure_args],
 [b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args])
 
 m4_define([b4_pure_args],
 [b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args])
 
@@ -581,7 +597,7 @@ yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yyformat, ...)
       va_start (yyap, yyformat);
       yystack->yyerrflag = 1;
       vsprintf (yymsg, yyformat, yyap);
       va_start (yyap, yyformat);
       yystack->yyerrflag = 1;
       vsprintf (yymsg, yyformat, yyap);
-      yyerror (yymsg]b4_pure_args[);
+      yyerror (]b4_yyerror_args[yymsg);
     }
   longjmp (yystack->yyexception_buffer, 1);
 }
     }
   longjmp (yystack->yyexception_buffer, 1);
 }
@@ -636,7 +652,7 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
 # undef YYBACKUP
 # define YYBACKUP(Token, Value)                                                     \
   do {                                                                      \
 # undef YYBACKUP
 # define YYBACKUP(Token, Value)                                                     \
   do {                                                                      \
-    yyerror ("syntax error: cannot back up"]b4_pure_args[);                 \
+    yyerror (]b4_yyerror_args["syntax error: cannot back up");              \
     YYERROR;                                                                \
   } while (0)
 
     YYERROR;                                                                \
   } while (0)
 
@@ -1591,12 +1607,12 @@ yyreportParseError (yyGLRStack* yystack,
                    yyprefix = " or ";
                  }
            }
                    yyprefix = " or ";
                  }
            }
-         yyerror (yymsg]b4_lpure_args[);
+         yyerror (]b4_lyyerror_args[yymsg);
          free (yymsg);
        }
       else
 #endif
          free (yymsg);
        }
       else
 #endif
-       yyerror ("parse error"]b4_lpure_args[);
+       yyerror (]b4_lyyerror_args["parse error");
       yynerrs += 1;
     }
 }
       yynerrs += 1;
     }
 }
index c6045e2091aa22b4258baec1256123b59bfd577a..1c735a006f542fea6bd2d3d2ed168a6198759ed4 100644 (file)
@@ -48,11 +48,12 @@ m4_define([b4_Pure_if],
             [$2])])
 
 
             [$2])])
 
 
-# b4_pure_args
-# ------------
+# b4_yyerror_args
+# ---------------
 # Arguments passed to yyerror: user args plus yylloc.
 # Arguments passed to yyerror: user args plus yylloc.
-m4_define([b4_pure_args],
-[b4_Pure_if([b4_location_if([, &yylloc])])[]b4_user_args])
+m4_define([b4_yyerror_args],
+[b4_Pure_if([b4_location_if([&yylloc, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
 
 
 # b4_lex_param
 
 
 # b4_lex_param
@@ -529,7 +530,7 @@ do                                                          \
     }                                                          \
   else                                                         \
     {                                                          \
     }                                                          \
   else                                                         \
     {                                                          \
-      yyerror ("syntax error: cannot back up"b4_pure_args);    \
+      yyerror (b4_yyerror_args"syntax error: cannot back up"); \
       YYERROR;                                                 \
     }                                                          \
 while (0)
       YYERROR;                                                 \
     }                                                          \
 while (0)
@@ -1135,15 +1136,15 @@ yyerrlab:
                        yycount++;
                      }
                }
                        yycount++;
                      }
                }
-             yyerror (yymsg]b4_pure_args[);
+             yyerror (]b4_yyerror_args[yymsg);
              YYSTACK_FREE (yymsg);
            }
          else
              YYSTACK_FREE (yymsg);
            }
          else
-           yyerror ("parse error; also virtual memory exhausted"]b4_pure_args[);
+           yyerror (]b4_yyerror_args["parse error; also virtual memory exhausted");
        }
       else
 #endif /* YYERROR_VERBOSE */
        }
       else
 #endif /* YYERROR_VERBOSE */
-       yyerror ("parse error"]b4_pure_args[);
+       yyerror (]b4_yyerror_args["parse error");
     }
   goto yyerrlab1;
 
     }
   goto yyerrlab1;
 
@@ -1258,7 +1259,7 @@ yyabortlab:
 | yyoverflowlab -- parser overflow comes here.  |
 `----------------------------------------------*/
 yyoverflowlab:
 | yyoverflowlab -- parser overflow comes here.  |
 `----------------------------------------------*/
 yyoverflowlab:
-  yyerror ("parser stack overflow"]b4_pure_args[);
+  yyerror (]b4_yyerror_args["parser stack overflow");
   yyresult = 2;
   /* Fall through.  */
 #endif
   yyresult = 2;
   /* Fall through.  */
 #endif
index 290cbab3bf05dcf2db08c0e6574e60ec5e63e762..123c5261a2e3936ee2442b073bc71b1c3bcadeee 100644 (file)
@@ -1357,7 +1357,7 @@ here is the definition we will use:
 #include <stdio.h>
 
 void
 #include <stdio.h>
 
 void
-yyerror (const char *s)  /* called by yyparse on error */
+yyerror (const char *s)  /* Called by yyparse on error.  */
 @{
   printf ("%s\n", s);
 @}
 @{
   printf ("%s\n", s);
 @}
@@ -1973,7 +1973,7 @@ main (void)
 
 @group
 void
 
 @group
 void
-yyerror (const char *s)  /* Called by yyparse on error */
+yyerror (const char *s)  /* Called by yyparse on error */
 @{
   printf ("%s\n", s);
 @}
 @{
   printf ("%s\n", s);
 @}
@@ -4050,7 +4050,7 @@ The following definition suffices in simple programs:
 @example
 @group
 void
 @example
 @group
 void
-yyerror (char *s)
+yyerror (const char *s)
 @{
 @end group
 @group
 @{
 @end group
 @group
@@ -4064,7 +4064,7 @@ error recovery if you have written suitable error recovery grammar rules
 (@pxref{Error Recovery}).  If recovery is impossible, @code{yyparse} will
 immediately return 1.
 
 (@pxref{Error Recovery}).  If recovery is impossible, @code{yyparse} will
 immediately return 1.
 
-Oviously, in location tracking pure parsers, @code{yyerror} should have
+Obviously, in location tracking pure parsers, @code{yyerror} should have
 an access to the current location.  This is indeed the case for the GLR
 parsers, but not for the Yacc parser, for historical reasons.  I.e., if
 @samp{%locations %pure-parser} is passed then the prototypes for
 an access to the current location.  This is indeed the case for the GLR
 parsers, but not for the Yacc parser, for historical reasons.  I.e., if
 @samp{%locations %pure-parser} is passed then the prototypes for
@@ -4072,14 +4072,14 @@ parsers, but not for the Yacc parser, for historical reasons.  I.e., if
 
 @example
 void yyerror (const char *msg);                 /* Yacc parsers.  */
 
 @example
 void yyerror (const char *msg);                 /* Yacc parsers.  */
-void yyerror (const char *msg, YYLTYPE *locp);  /* GLR parsers.   */
+void yyerror (YYLTYPE *locp, const char *msg);  /* GLR parsers.   */
 @end example
 
 If @samp{%parse-param "int *nastiness"  "nastiness"} is used, then:
 
 @example
 @end example
 
 If @samp{%parse-param "int *nastiness"  "nastiness"} is used, then:
 
 @example
-void yyerror (int *randomness);  /* Yacc parsers.  */
-void yyerror (int *randomness);  /* GLR parsers.   */
+void yyerror (int *randomness, const char *msg);  /* Yacc parsers.  */
+void yyerror (int *randomness, const char *msg);  /* GLR parsers.   */
 @end example
 
 Finally, GLR and Yacc parsers share the same @code{yyerror} calling
 @end example
 
 Finally, GLR and Yacc parsers share the same @code{yyerror} calling
@@ -4104,10 +4104,18 @@ results in the following signatures for all the parser kinds:
 @example
 int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
 int yyparse (int *nastiness, int *randomness);
 @example
 int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
 int yyparse (int *nastiness, int *randomness);
-void yyerror (const char *msg, YYLTYPE *locp,
-              int *nastiness, int *randomness);
+void yyerror (YYLTYPE *locp,
+              int *nastiness, int *randomness,
+              const char *msg);
 @end example
 
 @end example
 
+@noident
+Please, note that the prototypes are only indications of how the code
+produced by Bison will use @code{yyerror}, but you still have freedom
+and the exit value, and even on making @code{yyerror} a variadic
+function.  It is precisely to enable this that the message is passed
+last.
+
 @vindex yynerrs
 The variable @code{yynerrs} contains the number of syntax errors
 encountered so far.  Normally this variable is global; but if you
 @vindex yynerrs
 The variable @code{yynerrs} contains the number of syntax errors
 encountered so far.  Normally this variable is global; but if you
index 4399d257e6ff68f6fc89f4da8317e8f2da5223bc..aff3b455fc9e0c1bf08a90331d4e8c6538a56e67 100644 (file)
@@ -100,9 +100,9 @@ static int power (int base, int exponent);
 /* yyerror receives the location if:
    - %location & %pure & %glr
    - %location & %pure & %yacc & %parse-param. */
 /* yyerror receives the location if:
    - %location & %pure & %glr
    - %location & %pure & %yacc & %parse-param. */
-static void yyerror (const char *s
-                     ]AT_YYERROR_ARG_LOC_IF([, YYLTYPE *yylloc])[
-                     ]AT_PARAM_IF([, value_t *result, int *count])[
+static void yyerror (]AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])[
+                     ]AT_PARAM_IF([value_t *result, int *count, ])[
+                     const char *s
                      );
 static int yylex (LEX_FORMALS);
 static int yygetc (LEX_FORMALS);
                      );
 static int yylex (LEX_FORMALS);
 static int yygetc (LEX_FORMALS);
@@ -154,9 +154,10 @@ exp:
 FILE *yyin;
 
 static void
 FILE *yyin;
 
 static void
-yyerror (const char *s
-         ]AT_YYERROR_ARG_LOC_IF([, YYLTYPE *yylloc])[
-         ]AT_PARAM_IF([, value_t *result, int *count])[)
+yyerror (]AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])[
+         ]AT_PARAM_IF([value_t *result, int *count, ])[
+         const char *s
+         )
 {
 ]AT_PARAM_IF([(void) result; (void) count; ])[
 ]AT_YYERROR_SEES_LOC_IF([
 {
 ]AT_PARAM_IF([(void) result; (void) count; ])[
 ]AT_YYERROR_SEES_LOC_IF([
index 61c7f50b9571fd0902dd7d24d6f427715ed91789..b63b2dd380eb5c2a0f9f0d1a22956dc7d8ab3b12 100644 (file)
@@ -36,10 +36,11 @@ $1
 ]m4_bmatch([$2], [stmtMerge],
 [ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[
   #define YYINITDEPTH 10
 ]m4_bmatch([$2], [stmtMerge],
 [ static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);])[
   #define YYINITDEPTH 10
-  int yyerror (const char *s
+  int yyerror (
 #if YYPURE && YYLSP_NEEDED
 #if YYPURE && YYLSP_NEEDED
-               , YYLTYPE *yylocation
+               YYLTYPE *yylocation,
 #endif
 #endif
+               const char *s
               );
 
   #if YYPURE
               );
 
   #if YYPURE
@@ -157,10 +158,11 @@ yylex ()
 }
 
 int
 }
 
 int
-yyerror (const char *s
+yyerror (
 #if YYPURE && YYLSP_NEEDED
 #if YYPURE && YYLSP_NEEDED
-        , YYLTYPE *yylocation
+         YYLTYPE *yylocation,
 #endif
 #endif
+         const char *s
         )
 {
 #if YYPURE && YYLSP_NEEDED
         )
 {
 #if YYPURE && YYLSP_NEEDED