]> git.saurik.com Git - bison.git/blobdiff - data/bison.simple
Prepare @$ in %destructor, but currently don't bind it in the
[bison.git] / data / bison.simple
index 299623545cfeccb26832b61baad44347222ed230..6059e160794599f60247ecac0d1aefea62c66f1d 100644 (file)
@@ -68,6 +68,10 @@ m4_define_default([b4_header_guard],
                                 [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
 
 
+## ------------------------- ##
+## Assigning token numbers.  ##
+## ------------------------- ##
+
 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
 # -----------------------------------------
 # Output the definition of this token as #define.
@@ -432,14 +436,12 @@ static const short yycheck[[]] =
   b4_check
 };
 
-#if YYDEBUG
 /* YYSTOS[[STATE-NUM]] -- The (internal number of the) accessing
    symbol of state STATE-NUM.  */
 static const b4_uint_type(b4_stos_max) yystos[[]] =
 {
   b4_stos
 };
-#endif
 
 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
 # define YYSIZE_T __SIZE_TYPE__
@@ -649,6 +651,7 @@ int yyparse (void *);
 int yyparse (void);
 # endif
 #endif
+static void yydestructor (int symbol_type, YYSTYPE symbol_value);
 
 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
    variables are global, or local to YYPARSE.  */
@@ -1120,9 +1123,41 @@ yyerrlab1:
 
       /* Return failure if at end of input.  */
       if (yychar == YYEOF)
-       YYABORT;
+        {
+         /* Pop the error token.  */
+          YYPOPSTACK;
+         /* Pop the rest of the stack.  */
+         while (yyssp > yyss)
+           {
+#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]]);
+                   }
+               }
+#endif
+             yydestructor (yystos[*yyssp], *yyvsp);
+             YYPOPSTACK;
+           }
+         YYABORT;
+        }
+
       YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
                  yychar, yytname[yychar1]));
+      yydestructor (yychar1, yylval);
       yychar = YYEMPTY;
     }
 
@@ -1169,6 +1204,7 @@ yyerrlab1:
        }
 #endif
 
+      yydestructor (yystos[yystate], *yyvsp);
       yyvsp--;
       yystate = *--yyssp;
 #if YYLSP_NEEDED
@@ -1215,13 +1251,15 @@ yyabortlab:
   yyresult = 1;
   goto yyreturn;
 
-/*---------------------------------------------.
-| yyoverflowab -- parser overflow comes here.  |
-`---------------------------------------------*/
+#ifndef yyoverflow
+/*----------------------------------------------.
+| yyoverflowlab -- parser overflow comes here.  |
+`----------------------------------------------*/
 yyoverflowlab:
   yyerror ("parser stack overflow");
   yyresult = 2;
   /* Fall through.  */
+#endif
 
 yyreturn:
 #ifndef yyoverflow
@@ -1231,6 +1269,37 @@ yyreturn:
   return yyresult;
 ]}
 
+
+/*-------------------------------------------------.
+| Release the memory associated to SYMBOL-NUMBER.  |
+`-------------------------------------------------*/
+
+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
+      case $4: /* $3 */
+#line $2 "$1"
+        $5;
+#line __oline__ "__ofile__"
+        break;
+m4_popdef([b4_dollar_dollar])])
+
+m4_divert_pop([KILL])dnl# End of M4 code.
+static void
+yydestructor (int symbol_type, YYSTYPE symbol_value)
+{
+  switch (symbol_type)
+    {
+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;
+    }
+}
+
 b4_epilogue
 m4_if(b4_defines_flag, 0, [],
 [#output "b4_output_header_name"