bison-patches
[Top][All Lists]
Advanced

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

Re: user destructor for unresolved GLR semantic value


From: Paul Eggert
Subject: Re: user destructor for unresolved GLR semantic value
Date: Wed, 24 Aug 2005 23:14:21 -0700
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

"Joel E. Denny" <address@hidden> writes:

> Sorry for so many posts, but I think I now have a much more reasonable
> approach.  The following patch replaces all previous patches in this
> thread.  The test case was in my first post.

Thanks for diagnosing the problem and providing a patch.  I installed
the following somewhat-different patch to glr.c, along with your test
case; does it work for you?

2005-08-24  Paul Eggert  <address@hidden>

        * data/glr.c (yyrecoverSyntaxError, yyreturn):
        Don't invoke destructor on unresolved entries.
        * tests/glr-regression.at
        (User destructor for unresolved GLR semantic value): New test case.
        Problem reported by Joel E. Denny in:
        http://lists.gnu.org/archive/html/bison-patches/2005-08/msg00016.html

--- data/glr.c  22 Aug 2005 02:31:10 -0000      1.114
+++ data/glr.c  25 Aug 2005 06:09:58 -0000
@@ -1981,9 +1981,10 @@ yyrecoverSyntaxError (yyGLRStack* yystac
            }
        }
 ]b4_location_if([[      yystack->yyerror_range[1].yystate.yyloc = 
yys->yyloc;]])[
-      yydestruct ("Error: popping",
-                 yystos[yys->yylrState],
-                 &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+      if (yys->yyresolved)
+       yydestruct ("Error: popping",
+                   yystos[yys->yylrState],
+                   &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
       yystack->yytops.yystates[0] = yys->yypred;
       yystack->yynextFree -= 1;
       yystack->yyspaceLeft += 1;
@@ -2183,9 +2184,10 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
          {
            yyGLRState *yys = yystates[0];
 ]b4_location_if([[       yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
-)[         yydestruct ("Cleanup: popping",
-                       yystos[yys->yylrState],
-                       &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[);
+)[         if (yys->yyresolved)
+             yydestruct ("Cleanup: popping",
+                         yystos[yys->yylrState],
+                         &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[);
            yystates[0] = yys->yypred;
            yystack.yynextFree -= 1;
            yystack.yyspaceLeft += 1;
--- tests/glr-regression.at     21 Aug 2005 23:43:56 -0000      1.13
+++ tests/glr-regression.at     25 Aug 2005 06:09:58 -0000
@@ -420,3 +420,73 @@ AT_CHECK([[./glr-regr4]], 0,
 ]], [])
 
 AT_CLEANUP
+
+
+## ---------------------------------------------------------------------- ##
+## User destructor for unresolved GLR semantic value                      ##
+## Thanks to Joel E. Denny for this test; see                             ##
+## <http://lists.gnu.org/archive/html/help-bison/2005-07/msg00013.html>.  ##
+## ---------------------------------------------------------------------- ##
+
+AT_SETUP([User destructor for unresolved GLR semantic value])
+
+AT_DATA_GRAMMAR([glr-regr5.y],
+[[%{
+  #include <stdio.h>
+  #include <stdlib.h>
+  static void yyerror (char const *);
+  static int yylex (void);
+  enum { MAGIC_VALUE = -1057808125 }; /* originally chosen at random */
+%}
+
+%glr-parser
+%union { int value; }
+%type <value> start
+
+%destructor {
+  if ($$ != MAGIC_VALUE)
+    {
+      fprintf (stderr, "Bad destructor call.\n");
+      exit (EXIT_FAILURE);
+    }
+} start
+
+%%
+
+start:
+   'a' { $$ = MAGIC_VALUE; }
+   | 'a' { $$ = MAGIC_VALUE; }
+   ;
+
+%%
+
+static int
+yylex (void)
+{
+  static char const *input = "a";
+  return *input++;
+}
+
+static void
+yyerror (char const *msg)
+{
+  printf ("%s\n", msg);
+}
+
+int
+main (void)
+{
+  return yyparse () != 1;
+}
+]])
+
+AT_CHECK([[bison -o glr-regr5.c glr-regr5.y]], 0, [],
+[glr-regr5.y: conflicts: 1 reduce/reduce
+])
+AT_COMPILE([glr-regr5])
+
+AT_CHECK([[./glr-regr5]], 0,
+[syntax is ambiguous
+])
+
+AT_CLEANUP




reply via email to

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