bison-patches
[Top][All Lists]
Advanced

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

yyerror (*, msg) instead of yyerror (msg, *)


From: Akim Demaille
Subject: yyerror (*, msg) instead of yyerror (msg, *)
Date: 07 Nov 2002 13:51:56 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        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.

Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.28
diff -u -u -r1.28 glr.c
--- data/glr.c 6 Nov 2002 14:11:47 -0000 1.28
+++ data/glr.c 7 Nov 2002 12:51:07 -0000
@@ -54,9 +54,25 @@
 [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
 # ------------
-# 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])
 
@@ -581,7 +597,7 @@
       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);
 }
@@ -636,7 +652,7 @@
 # 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)
 
@@ -1591,12 +1607,12 @@
                    yyprefix = " or ";
                  }
            }
-         yyerror (yymsg]b4_lpure_args[);
+         yyerror (]b4_lyyerror_args[yymsg);
          free (yymsg);
        }
       else
 #endif
-       yyerror ("parse error"]b4_lpure_args[);
+       yyerror (]b4_lyyerror_args["parse error");
       yynerrs += 1;
     }
 }
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.29
diff -u -u -r1.29 yacc.c
--- data/yacc.c 6 Nov 2002 14:11:47 -0000 1.29
+++ data/yacc.c 7 Nov 2002 12:51:07 -0000
@@ -48,11 +48,12 @@
             [$2])])
 
 
-# b4_pure_args
-# ------------
+# b4_yyerror_args
+# ---------------
 # 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
@@ -529,7 +530,7 @@
     }                                                          \
   else                                                         \
     {                                                          \
-      yyerror ("syntax error: cannot back up"b4_pure_args);    \
+      yyerror (b4_yyerror_args"syntax error: cannot back up"); \
       YYERROR;                                                 \
     }                                                          \
 while (0)
@@ -1135,15 +1136,15 @@
                        yycount++;
                      }
                }
-             yyerror (yymsg]b4_pure_args[);
+             yyerror (]b4_yyerror_args[yymsg);
              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 */
-       yyerror ("parse error"]b4_pure_args[);
+       yyerror (]b4_yyerror_args["parse error");
     }
   goto yyerrlab1;
 
@@ -1258,7 +1259,7 @@
 | 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
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.75
diff -u -u -r1.75 bison.texinfo
--- doc/bison.texinfo 3 Nov 2002 16:41:57 -0000 1.75
+++ doc/bison.texinfo 7 Nov 2002 12:51:11 -0000
@@ -1357,7 +1357,7 @@
 #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);
 @}
@@ -1973,7 +1973,7 @@
 
 @group
 void
-yyerror (const char *s)  /* Called by yyparse on error */
+yyerror (const char *s)  /* Called by yyparse on error.  */
 @{
   printf ("%s\n", s);
 @}
@@ -4050,7 +4050,7 @@
 @example
 @group
 void
-yyerror (char *s)
+yyerror (const char *s)
 @{
 @end group
 @group
@@ -4064,7 +4064,7 @@
 (@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
@@ -4072,14 +4072,14 @@
 
 @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
-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
@@ -4104,9 +4104,17 @@
 @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
+
address@hidden
+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
Index: tests/calc.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/calc.at,v
retrieving revision 1.40
diff -u -u -r1.40 calc.at
--- tests/calc.at 4 Nov 2002 08:30:18 -0000 1.40
+++ tests/calc.at 7 Nov 2002 12:51:13 -0000
@@ -100,9 +100,9 @@
 /* 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);
@@ -154,9 +154,10 @@
 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([
Index: tests/cxx-type.at
===================================================================
RCS file: /cvsroot/bison/bison/tests/cxx-type.at,v
retrieving revision 1.8
diff -u -u -r1.8 cxx-type.at
--- tests/cxx-type.at 3 Nov 2002 16:41:57 -0000 1.8
+++ tests/cxx-type.at 7 Nov 2002 12:51:13 -0000
@@ -36,10 +36,11 @@
 ]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
-               , YYLTYPE *yylocation
+               YYLTYPE *yylocation,
 #endif
+               const char *s
               );
 
   #if YYPURE
@@ -157,10 +158,11 @@
 }
 
 int
-yyerror (const char *s
+yyerror (
 #if YYPURE && YYLSP_NEEDED
-        , YYLTYPE *yylocation
+         YYLTYPE *yylocation,
 #endif
+         const char *s
         )
 {
 #if YYPURE && YYLSP_NEEDED




reply via email to

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