]> git.saurik.com Git - bison.git/blobdiff - data/glr.c
data/glr.c (yyfill): Adjust comment.
[bison.git] / data / glr.c
index 36a98d8576f8d196d702cc8fddfe7bb2aea6a4ad..c04372eefc380ec96d37127d4eabe5e70420b7b4 100644 (file)
@@ -34,6 +34,14 @@ m4_define_default([b4_stack_depth_init],  [200])
 ## ------------------------ ##
 
 
+# b4_user_formals
+# ---------------
+# This is specific to GLR because it relies on ISO C formal argument
+# declarations.
+m4_define([b4_user_formals],
+[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
+
+
 # b4_lex_param
 # ------------
 # Accumule in b4_lex_param all the yylex arguments.
@@ -44,12 +52,6 @@ b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl
 m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
 
 
-# b4_user_formals
-# ---------------
-m4_define([b4_user_formals],
-[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
-
-
 # b4_yyerror_args
 # ---------------
 # Arguments passed to yyerror: user args plus yylloc.
@@ -234,6 +236,9 @@ b4_syncline([@oline@], [@ofile@])
 # endif
 #endif
 
+/* Suppress unused-variable warnings by "using" E.  */
+#define YYUSE(e) do {;} while (/*CONSTCOND*/ yyfalse && (e))
+
 #ifndef YYFREE
 # define YYFREE free
 #endif
@@ -470,7 +475,7 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
          (Current).first_column = (Current).last_column =              \
            YYRHSLOC (Rhs, 0).last_column;                              \
        }                                                               \
-    while (0)
+    while (/*CONSTCOND*/ 0)
 
 /* YY_LOCATION_PRINT -- Print the location on the stream.
    This macro was not mandated originally: define only if we know
@@ -515,43 +520,32 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;
 
 #define YYCHK(YYE)                                                          \
    do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; }      \
-   while (0)
+   while (/*CONSTCOND*/ 0)
 
 #if YYDEBUG
 
-# ifdef YYFPRINTF
-#  define YYFPUTC(Char, Stream) YYFPRINTF (Stream, "%c", Char)
-#  define YYFPUTS(Char, Stream) YYFPRINTF (Stream, "%s", String)
-# else
+#if ! defined (YYFPRINTF)
 #  define YYFPRINTF fprintf
-#  define YYFPUTC fputc
-#  define YYFPUTS fputs
-# endif
+#endif
 
 # define YYDPRINTF(Args)                       \
 do {                                           \
   if (yydebug)                                 \
     YYFPRINTF Args;                            \
-} while (0)
-
-# define YYDPUTS(String, Stream)               \
-do {                                           \
-  if (yydebug)                                 \
-    YYFPUTS (String, Stream);                  \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 ]b4_yysymprint_generate([b4_c_ansi_function_def])[
 
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location)         \
-do {                                                           \
-  if (yydebug)                                                 \
-    {                                                          \
-      YYFPRINTF (stderr, "%s ", Title);                                \
-      yysymprint (stderr,                                      \
-                  Type, Value]b4_location_if([, Location])[);  \
-      YYFPUTC ('\n', stderr);                                  \
-    }                                                          \
-} while (0)
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location)                     \
+do {                                                                       \
+  if (yydebug)                                                             \
+    {                                                                      \
+      YYFPRINTF (stderr, "%s ", Title);                                            \
+      yysymprint (stderr,                                                  \
+                  Type, Value]b4_location_if([, Location])[]b4_user_args[); \
+      YYFPRINTF (stderr, "\n");                                                    \
+    }                                                                      \
+} while (/*CONSTCOND*/ 0)
 
 /* Nonzero means print parse trace.  It is left uninitialized so that
    multiple parsers can coexist.  */
@@ -559,7 +553,6 @@ int yydebug;
 
 #else /* !YYDEBUG */
 
-# define YYDPUTS(String, File)
 # define YYDPRINTF(Args)
 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
 
@@ -789,8 +782,7 @@ yytokenName (yySymbol yytoken)
 
 /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
  *  at YYVSP[YYLOW0].yystate.yypred.  Leaves YYVSP[YYLOW1].yystate.yypred
- *  containing the pointer to the next state in the chain. Assumes
- *  YYLOW1 < YYLOW0.  */
+ *  containing the pointer to the next state in the chain. */
 static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
 static void
 yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
@@ -809,8 +801,8 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
 }
 
 /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1.  Otherwise, fill in
  YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
  For convenience, always return YYLOW1.  */
* YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
* For convenience, always return YYLOW1.  */
 static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
      __attribute__ ((__unused__));
 static inline int
@@ -889,9 +881,8 @@ b4_syncline([@oline@], [@ofile@])
 static void
 yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
 {
-  /* `Use' the arguments.  */
-  (void) yy0;
-  (void) yy1;
+  YYUSE (yy0);
+  YYUSE (yy1);
 
   switch (yyn)
     {
@@ -912,11 +903,11 @@ yyrhsLength (yyRuleNum yyrule)
 }
 
 static void
-yydestroyGLRState (char const *yymsg, yyGLRState *yys)
+yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
 {
   if (yys->yyresolved)
     yydestruct (yymsg, yystos[yys->yylrState],
-               &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+               &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[);
   else
     {
 #if YYDEBUG
@@ -924,8 +915,8 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys)
        {
          YYFPRINTF (stderr, "%s unresolved ", yymsg);
          yysymprint (stderr, yystos[yys->yylrState],
-                     &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
-         YYFPUTC ('\n', stderr);
+                     &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[);
+         YYFPRINTF (stderr, "\n");
        }
 #endif
 
@@ -937,7 +928,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys)
           for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
                yyn > 0;
                yyrh = yyrh->yypred, yyn -= 1)
-            yydestroyGLRState (yymsg, yyrh);
+            yydestroyGLRState (yymsg, yyrh]b4_user_args[);
         }
     }
 }
@@ -1190,7 +1181,7 @@ yyundeleteLastStack (yyGLRStack* yystack)
     return;
   yystack->yytops.yystates[0] = yystack->yylastDeleted;
   yystack->yytops.yysize = 1;
-  YYDPUTS ("Restoring last deleted stack as stack #0.\n", stderr);
+  YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
   yystack->yylastDeleted = NULL;
 }
 
@@ -1205,7 +1196,7 @@ yyremoveDeletes (yyGLRStack* yystack)
        {
          if (yyi == yyj)
            {
-             YYDPUTS ("Removing dead stacks.\n", stderr);
+             YYDPRINTF ((stderr, "Removing dead stacks.\n"));
            }
          yystack->yytops.yysize -= 1;
        }
@@ -1294,11 +1285,18 @@ yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
     }
   else
     {
+      /* At present, doAction is never called in nondeterministic
+       * mode, so this branch is never taken.  It is here in
+       * anticipation of a future feature that will allow immediate
+       * evaluation of selected actions in nondeterministic mode. */
       int yyi;
       yyGLRState* yys;
       yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
       yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
-       = yystack->yytops.yystates[yyk];
+       = yystack->yytops.yystates[yyk];]b4_location_if([[
+      if (yynrhs == 0)
+       /* Set default location. */
+        yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
       for (yyi = 0; yyi < yynrhs; yyi += 1)
        {
          yys = yys->yypred;
@@ -1318,7 +1316,7 @@ yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
 do {                                   \
   if (yydebug)                         \
     yy_reduce_print (K, Rule);         \
-} while (0)
+} while (/*CONSTCOND*/ 0)
 
 /*----------------------------------------------------------.
 | Report that the RULE is going to be reduced on stack #K.  |
@@ -1572,7 +1570,10 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
 
   yynrhs = yyrhsLength (yyopt->yyrule);
   YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[));
-  yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;
+  yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_location_if([[
+  if (yynrhs == 0)
+    /* Set default location. */
+    yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
   return yyuserAction (yyopt->yyrule, yynrhs,
                       yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
                       yyvalp, yylocp, yystack]b4_user_args[);
@@ -1633,16 +1634,16 @@ static void
 yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
                   yyGLRStack* yystack]b4_pure_formals[)
 {
-  /* `Unused' warnings.  */
-  (void) yyx0;
-  (void) yyx1;
+  YYUSE (yyx0);
+  YYUSE (yyx1);
 
 #if YYDEBUG
-  YYFPUTS ("Ambiguity detected.\nOption 1,\n", stderr);
+  YYFPRINTF (stderr, "Ambiguity detected.\n");
+  YYFPRINTF (stderr, "Option 1,\n");
   yyreportTree (yyx0, 2);
-  YYFPUTS ("\nOption 2,\n", stderr);
+  YYFPRINTF (stderr, "\nOption 2,\n");
   yyreportTree (yyx1, 2);
-  YYFPUTC ('\n', stderr);
+  YYFPRINTF (stderr, "\n");
 #endif
   yyFail (yystack][]b4_pure_args[, YY_("syntax is ambiguous"));
 }
@@ -1798,7 +1799,7 @@ yyprocessOneStack (yyGLRStack* yystack, size_t yyk,
        {
          if (*yytokenp == YYEMPTY)
            {
-             YYDPUTS ("Reading a token: ", stderr);
+             YYDPRINTF ((stderr, "Reading a token: "));
              yychar = YYLEX;
              *yytokenp = YYTRANSLATE (yychar);
              YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
@@ -1847,9 +1848,8 @@ static void
 yyreportSyntaxError (yyGLRStack* yystack,
                     YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[)
 {
-  /* `Unused' warnings. */
-  (void) yylvalp;
-  (void) yyllocp;
+  YYUSE (yylvalp);
+  YYUSE (yyllocp);
 
   if (yystack->yyerrState == 0)
     {
@@ -1979,9 +1979,9 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
            yyerror_range[2].yystate.yyloc = *yyllocp;
            YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
            yydestruct ("Error: discarding",
-                       *yytokenp, yylvalp]b4_location_if([, yyllocp])[);
+                       *yytokenp, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[);
          }
-       YYDPUTS ("Reading a token: ", stderr);
+       YYDPRINTF ((stderr, "Reading a token: "));
        yychar = YYLEX;
        *yytokenp = YYTRANSLATE (yychar);
        YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
@@ -2034,7 +2034,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
            }
        }
 ]b4_location_if([[      yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
-      yydestroyGLRState ("Error: popping", yys);
+      yydestroyGLRState ("Error: popping", yys]b4_user_args[);
       yystack->yytops.yystates[0] = yys->yypred;
       yystack->yynextFree -= 1;
       yystack->yyspaceLeft += 1;
@@ -2057,7 +2057,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
     default:                                                                \
       goto yybuglab;                                                        \
     }                                                                       \
-  } while (0)
+  } while (/*CONSTCOND*/ 0)
 
 
 /*----------.
@@ -2081,7 +2081,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
   YYSTYPE* const yylvalp = &yylval;
   YYLTYPE* const yyllocp = &yylloc;
 
-  YYDPUTS ("Starting parse\n", stderr);
+  YYDPRINTF ((stderr, "Starting parse\n"));
 
   yytoken = YYEMPTY;
   yylval = yyval_default;
@@ -2145,7 +2145,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
            {
              if (yytoken == YYEMPTY)
                {
-                 YYDPUTS ("Reading a token: ", stderr);
+                 YYDPRINTF ((stderr, "Reading a token: "));
                  yychar = YYLEX;
                  yytoken = YYTRANSLATE (yychar);
                   YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp);
@@ -2190,7 +2190,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
              if (yystack.yytops.yysize == 0)
                yyFail (&yystack][]b4_lpure_args[, YY_("syntax error"));
              YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
-             YYDPUTS ("Returning to deterministic operation.\n", stderr);
+             YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
 ]b4_location_if([[           yystack.yyerror_range[1].yystate.yyloc = *yyllocp;]])[
              yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
              goto yyuser_error;
@@ -2198,7 +2198,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
          else if (yystack.yytops.yysize == 1)
            {
              YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
-             YYDPUTS ("Returning to deterministic operation.\n", stderr);
+             YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
              yycompressStack (&yystack);
              break;
            }
@@ -2229,7 +2229,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
  yyreturn:
   if (yytoken != YYEOF && yytoken != YYEMPTY)
     yydestruct ("Cleanup: discarding lookahead",
-                yytoken, yylvalp]b4_location_if([, yyllocp])[);
+                yytoken, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[);
 
   /* If the stack is well-formed, pop the stack until it is empty,
      destroying its entries as we go.  But free the stack regardless
@@ -2242,7 +2242,7 @@ b4_syncline([@oline@], [@ofile@])])dnl
          {
            yyGLRState *yys = yystates[0];
 ]b4_location_if([[       yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
-)[         yydestroyGLRState ("Cleanup: popping", yys);
+)[         yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
            yystates[0] = yys->yypred;
            yystack.yynextFree -= 1;
            yystack.yyspaceLeft += 1;
@@ -2265,7 +2265,7 @@ yy_yypstack (yyGLRState* yys)
   if (yys->yypred)
     {
       yy_yypstack (yys->yypred);
-      fputs (" -> ", stderr);
+      fprintf (stderr, " -> ");
     }
   fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long int) yys->yyposn);
 }
@@ -2274,10 +2274,10 @@ static void
 yypstates (yyGLRState* yyst)
 {
   if (yyst == NULL)
-    fputs ("<null>", stderr);
+    fprintf (stderr, "<null>");
   else
     yy_yypstack (yyst);
-  fputc ('\n', stderr);
+  fprintf (stderr, "\n");
 }
 
 static void
@@ -2315,13 +2315,13 @@ yypdumpstack (yyGLRStack* yystack)
                   (long int) YYINDEX (yyp->yyoption.yystate),
                   (long int) YYINDEX (yyp->yyoption.yynext));
        }
-      fputc ('\n', stderr);
+      fprintf (stderr, "\n");
     }
-  fputs ("Tops:", stderr);
+  fprintf (stderr, "Tops:");
   for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
     fprintf (stderr, "%lu: %ld; ", (unsigned long int) yyi,
             (long int) YYINDEX (yystack->yytops.yystates[yyi]));
-  fputc ('\n', stderr);
+  fprintf (stderr, "\n");
 }
 #endif
 ]