bug-bison
[Top][All Lists]
Advanced

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

Re: fprintf -> YYFPRINTF


From: Joel E. Denny
Subject: Re: fprintf -> YYFPRINTF
Date: Sun, 1 Jul 2007 22:08:36 -0400 (EDT)

On Fri, 29 Jun 2007, Bob Smith wrote:

> Using bison 2.3 to generate a parser which runs under Windows, I browsed the
> .C file which bison generates and noticed that I wasn't seeing all of the
> messages in the output that bison generates, e.g.
> 
> Reducing stack by rule 6 (line 122):
>    $1 = nterm Stmt ()
> 
> Then I noticed that there are three places in the .C file generated by bison
> where fprintf is used (two in the body of yy_reduce_print and one in the
> #define for YY_LOCATION_PRINT).  To make it easier to redirect those calls, it
> would be helpful if those names were changed to YYFPRINTF or some other
> redefinable name.

Thanks for the report.

yy_reduce_print is fixed in CVS.

YYFPRINTF is defined only when YYDEBUG is true, but YY_LOCATION_PRINT does 
not have this dependency.  Moreover, YY_LOCATION_PRINT is already 
redefinable.  Thus, I think it may be best to leave it as is.

I just noticed that fprintf is used in a section in glr.c where YYFPRINTF 
seems better.  Unfortunately, this section is guarded by #ifdef YYDEBUG 
rather than the usual #if YYDEBUG.  Surely this is a mistake.  I committed 
the following to fix this:

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1706
diff -p -u -r1.1706 ChangeLog
--- ChangeLog   29 May 2007 04:24:17 -0000      1.1706
+++ ChangeLog   2 Jul 2007 01:39:49 -0000
@@ -1,3 +1,10 @@
+2007-07-01  Joel E. Denny  <address@hidden>
+
+       * data/glr.c (yy_yypstack, yypstates, yypdumpstack): Use YYFPRINTF
+       instead of fprintf.  Guard these functions with #if YYDEBUG instead of
+       #ifdef YYDEBUG for consistency with all other uses of YYDEBUG in Bison
+       and so that YYFPRINTF is guaranteed to be defined here.
+
 2007-05-29  Joel E. Denny  <address@hidden>
 
        * src/muscle_tab.c (muscle_percent_define_invalid_value): Replace
Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.205
diff -p -u -r1.205 glr.c
--- data/glr.c  26 May 2007 19:10:43 -0000      1.205
+++ data/glr.c  2 Jul 2007 01:39:50 -0000
@@ -2554,7 +2554,7 @@ m4_popdef([b4_at_dollar])])dnl
 }
 
 /* DEBUGGING ONLY */
-#ifdef YYDEBUG
+#if YYDEBUG
 static void yypstack (yyGLRStack* yystackp, size_t yyk)
   __attribute__ ((__unused__));
 static void yypdumpstack (yyGLRStack* yystackp) __attribute__ ((__unused__));
@@ -2565,19 +2565,20 @@ yy_yypstack (yyGLRState* yys)
   if (yys->yypred)
     {
       yy_yypstack (yys->yypred);
-      fprintf (stderr, " -> ");
+      YYFPRINTF (stderr, " -> ");
     }
-  fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn);
+  YYFPRINTF (stderr, "%d@@%lu", yys->yylrState,
+             (unsigned long int) yys->yyposn);
 }
 
 static void
 yypstates (yyGLRState* yyst)
 {
   if (yyst == NULL)
-    fprintf (stderr, "<null>");
+    YYFPRINTF (stderr, "<null>");
   else
     yy_yypstack (yyst);
-  fprintf (stderr, "\n");
+  YYFPRINTF (stderr, "\n");
 }
 
 static void
@@ -2597,31 +2598,33 @@ yypdumpstack (yyGLRStack* yystackp)
   size_t yyi;
   for (yyp = yystackp->yyitems; yyp < yystackp->yynextFree; yyp += 1)
     {
-      fprintf (stderr, "%3lu. ", (unsigned long int) (yyp - 
yystackp->yyitems));
+      YYFPRINTF (stderr, "%3lu. ",
+                 (unsigned long int) (yyp - yystackp->yyitems));
       if (*(yybool *) yyp)
        {
-         fprintf (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
-                  yyp->yystate.yyresolved, yyp->yystate.yylrState,
-                  (unsigned long int) yyp->yystate.yyposn,
-                  (long int) YYINDEX (yyp->yystate.yypred));
+         YYFPRINTF (stderr, "Res: %d, LR State: %d, posn: %lu, pred: %ld",
+                    yyp->yystate.yyresolved, yyp->yystate.yylrState,
+                    (unsigned long int) yyp->yystate.yyposn,
+                    (long int) YYINDEX (yyp->yystate.yypred));
          if (! yyp->yystate.yyresolved)
-           fprintf (stderr, ", firstVal: %ld",
-                    (long int) YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
+           YYFPRINTF (stderr, ", firstVal: %ld",
+                      (long int) YYINDEX (yyp->yystate
+                                             .yysemantics.yyfirstVal));
        }
       else
        {
-         fprintf (stderr, "Option. rule: %d, state: %ld, next: %ld",
-                  yyp->yyoption.yyrule - 1,
-                  (long int) YYINDEX (yyp->yyoption.yystate),
-                  (long int) YYINDEX (yyp->yyoption.yynext));
+         YYFPRINTF (stderr, "Option. rule: %d, state: %ld, next: %ld",
+                    yyp->yyoption.yyrule - 1,
+                    (long int) YYINDEX (yyp->yyoption.yystate),
+                    (long int) YYINDEX (yyp->yyoption.yynext));
        }
-      fprintf (stderr, "\n");
+      YYFPRINTF (stderr, "\n");
     }
-  fprintf (stderr, "Tops:");
+  YYFPRINTF (stderr, "Tops:");
   for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
-    fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi,
-            (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
-  fprintf (stderr, "\n");
+    YYFPRINTF (stderr, "%lu: %ld; ", (unsigned long int) yyi,
+              (long int) YYINDEX (yystackp->yytops.yystates[yyi]));
+  YYFPRINTF (stderr, "\n");
 }
 #endif
 ]




reply via email to

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