]> git.saurik.com Git - bison.git/blobdiff - data/bison.simple
* src/symtab.h, src/symtab.c (symbol_t): printer and
[bison.git] / data / bison.simple
index 7515cb182950c9f96826d65e0dc6284aa4ba6818..906f31395d362c46c3992a795dc8a6c666040e8e 100644 (file)
@@ -667,7 +667,15 @@ int yyparse (void *);
 int yyparse (void);
 # endif
 #endif
-static void yydestructor (int symbol_type, YYSTYPE symbol_value);
+
+#if defined (__STDC__) || defined (__cplusplus)
+static void yydestructor (int yytype,
+                         YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
+# if YYDEBUG
+static void yysymprint (FILE* out, int yytype,
+                       YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
+# endif
+#endif
 
 m4_divert_push([KILL])# ======================== M4 code.
 # b4_declare_parser_variables
@@ -883,14 +891,9 @@ yybackup:
        which are defined only if `YYDEBUG' is set.  */
       if (yydebug)
        {
-         YYFPRINTF (stderr, "Next token is %d (%s",
-                    yychar, yytname[yychar1]);
-         /* Give the individual parser a way to print the precise
-            meaning of a token, for further debugging info.  */
-# ifdef YYPRINT
-         YYPRINT (stderr, yychar, yylval);
-# endif
-         YYFPRINTF (stderr, ")\n");
+         YYFPRINTF (stderr, "Next token is ");
+         yysymprint (stderr, yychar1, yylval]b4_location_if([, yyloc])[);
+         YYFPRINTF (stderr, "\n");
        }
 #endif
     }
@@ -1109,24 +1112,14 @@ yyerrlab1:
 #if YYDEBUG
              if (yydebug)
                {
-                 if (yystos[*yyssp] < YYNTOKENS)
-                   {
-                     YYFPRINTF (stderr, "Error: popping token %d (%s",
-                                yytoknum[yystos[*yyssp]],
-                                yytname[yystos[*yyssp]]);
-# ifdef YYPRINT
-                     YYPRINT (stderr, yytoknum[yystos[*yyssp]], *yyvsp);
-# endif
-                     YYFPRINTF (stderr, ")\n");
-                   }
-                 else
-                   {
-                     YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n",
-                                yytname[yystos[*yyssp]]);
-                   }
+                 YYFPRINTF (stderr, "Error: popping ");
+                 yysymprint (stderr,
+                             yystos[*yyssp],
+                             *yyvsp]b4_location_if([, *yylsp])[);
+                 YYFPRINTF (stderr, "\n");
                }
 #endif
-             yydestructor (yystos[*yyssp], *yyvsp);
+             yydestructor (yystos[*yyssp], *yyvsp]b4_location_if([, *yylsp])[);
              YYPOPSTACK;
            }
          YYABORT;
@@ -1134,7 +1127,7 @@ yyerrlab1:
 
       YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
                  yychar, yytname[yychar1]));
-      yydestructor (yychar1, yylval);
+      yydestructor (yychar1, yylval]b4_location_if([, yylloc])[);
       yychar = YYEMPTY;
     }
 
@@ -1164,24 +1157,15 @@ yyerrlab1:
 #if YYDEBUG
       if (yydebug)
        {
-         if (yystos[yystate] < YYNTOKENS)
-           {
-             YYFPRINTF (stderr, "Error: popping token %d (%s",
-                        yytoknum[yystos[yystate]], yytname[yystos[yystate]]);
-# ifdef YYPRINT
-             YYPRINT (stderr, yytoknum[yystos[yystate]], *yyvsp);
-# endif
-             YYFPRINTF (stderr, ")\n");
-           }
-         else
-           {
-             YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n",
-                        yytname[yystos[yystate]]);
-           }
+         YYFPRINTF (stderr, "Error: popping ");
+         yysymprint (stderr,
+                     yystos[*yyssp],
+                     *yyvsp]b4_location_if([, *yylsp])[);
+         YYFPRINTF (stderr, "\n");
        }
 #endif
 
-      yydestructor (yystos[yystate], *yyvsp);
+      yydestructor (yystos[yystate], *yyvsp]b4_location_if([, *yylsp])[);
       yyvsp--;
       yystate = *--yyssp;
 ]b4_location_if([      yylsp--;])[
@@ -1243,36 +1227,80 @@ yyreturn:
 ]}
 
 
-/*-------------------------------------------------.
-| Release the memory associated to SYMBOL-NUMBER.  |
-`-------------------------------------------------*/
+/*-----------------------------------------------.
+| Release the memory associated to this symbol.  |
+`-----------------------------------------------*/
 
 m4_divert_push([KILL])# M4 code.
 # b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME)
 # ----------------------------------------------------------
 m4_define([b4_symbol_destructor],
-[m4_pushdef([b4_dollar_dollar], [symbol_value.$6])dnl
+[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
+m4_pushdef([b4_at_dollar], [yylocation])dnl
       case $4: /* $3 */
 #line $2 "$1"
         $5;
 #line __oline__ "__ofile__"
         break;
+m4_popdef([b4_at_dollar])dnl
 m4_popdef([b4_dollar_dollar])])
 
 m4_divert_pop([KILL])dnl# End of M4 code.
 static void
-yydestructor (int symbol_type, YYSTYPE symbol_value)
+yydestructor (int yytype,
+             YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]))
 {
-  switch (symbol_type)
+  switch (yytype)
     {
 m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl
       default:
-        YYDPRINTF ((stderr, "yydestructor: unknown symbol type: %d (%s)\n",
-                   symbol_type, yytname[[symbol_type]]));
         break;
     }
 }
 
+
+#if YYDEBUG
+/*---------------------------.
+| Print this symbol on OUT.  |
+`---------------------------*/
+
+m4_divert_push([KILL])# M4 code.
+# b4_symbol_printer(SYMBOL-NUMBER, PRINTER, TYPE-NAME)
+# ----------------------------------------------------------
+m4_define([b4_symbol_printer],
+[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
+m4_pushdef([b4_at_dollar], [yylocation])dnl
+      case $4: /* $3 */
+#line $2 "$1"
+        $5;
+#line __oline__ "__ofile__"
+        break;
+m4_popdef([b4_at_dollar])dnl
+m4_popdef([b4_dollar_dollar])])
+
+m4_divert_pop([KILL])dnl# End of M4 code.
+static void
+yysymprint (FILE* out, int yytype,
+           YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]))
+{
+  if (yytype < YYNTOKENS)
+    YYFPRINTF (out, "token %d (%s ", yytoknum[[yytype]], yytname[[yytype]]);
+  else
+    YYFPRINTF (out, "nterm %s (", yytname[[yytype]]);
+# ifdef YYPRINT
+  YYPRINT (out, yytype, yyvalue);
+# else
+  switch (yytype)
+    {
+m4_map([b4_symbol_printer], m4_defn([b4_symbol_printers]))dnl
+      default:
+        break;
+    }
+# endif /* !defined YYPRINT. */
+  YYFPRINTF (out, ")");
+}
+#endif /* YYDEBUG. */
+
 b4_epilogue
 m4_if(b4_defines_flag, 0, [],
 [#output "b4_output_header_name"