bison-patches
[Top][All Lists]
Advanced

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

Re: glr & locations


From: Paul Hilfinger
Subject: Re: glr & locations
Date: Sun, 30 Oct 2005 17:20:07 -0800

I have committed the following patch, which includes a new testcase.

2005-10-30  Paul Hilfinger  <address@hidden>

        * data/glr.c (yyfill): Adjust comment.
        (yyresolveAction): Initialize default location properly 
        for empty right-hand sides.
        (yydoAction): Ditto.
        Add comment explaining apparently dead code.
        * tests/glr-regression.at 
        (Incorrectly initialized location for empty right-hand side in GLR): 
        New test.
        
Index: bison-1_5.108/data/glr.c
--- bison-1_5.108/data/glr.c Fri, 28 Oct 2005 12:32:32 -0700 hilfingr 
(glrbison/e/14_glr-parser 1.27.1.33.1.5.1.17 644)
+++ bison-1_5.108(w)/data/glr.c Sun, 30 Oct 2005 17:12:15 -0800 hilfingr 
(glrbison/e/14_glr-parser 1.27.1.33.1.5.1.17 644)
@@ -782,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)
@@ -802,8 +801,8 @@ yyfillin (yyGLRStackItem *yyvsp, int yyl
 }
 
 /* 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
@@ -1286,11 +1285,18 @@ yydoAction (yyGLRStack* yystack, size_t 
     }
   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;
@@ -1564,7 +1570,10 @@ yyresolveAction (yySemanticOption* yyopt
 
   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[);
Index: bison-1_5.108/tests/glr-regression.at
--- bison-1_5.108/tests/glr-regression.at Fri, 28 Oct 2005 12:32:32 -0700 
hilfingr (glrbison/h/9_glr-regr1. 1.14 644)
+++ bison-1_5.108(w)/tests/glr-regression.at Sun, 30 Oct 2005 17:06:45 -0800 
hilfingr (glrbison/h/9_glr-regr1. 1.14 644)
@@ -636,3 +636,100 @@ AT_CHECK([[./glr-regr7]], 2, [],
 AT_XFAIL_IF(:)
 
 AT_CLEANUP
+
+
+## ------------------------------------------------------------------------- ##
+## Incorrect default location for empty right-hand sides.  Adapted from bug  ##
+## report by Claudia Hermann.                                               ##
+## See http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00069.html and ##
+## http://lists.gnu.org/archive/html/bug-bison/2005-10/msg00072.html         ##
+## ------------------------------------------------------------------------- ##
+
+AT_SETUP([Incorrectly initialized location for empty right-hand side in GLR])
+
+AT_DATA_GRAMMAR([glr-regr8.y],
+[[
+%{
+  #include <stdio.h>
+  #include <stdlib.h>
+  static void yyerror (char const *);
+  static int yylex (void);
+  static void yyerror(const char *msg);
+%}
+
+%token T_CONSTANT
+%token T_PORT
+%token T_SIGNAL
+
+%glr-parser
+
+%%
+
+
+PortClause     : T_PORT InterfaceDeclaration T_PORT
+               { printf("%d/%d - %d/%d - %d/%d\n", 
+                        @1.first_column, @1.last_column, 
+                        @2.first_column, @2.last_column, 
+                        @3.first_column, @3.last_column); }
+       ;
+
+InterfaceDeclaration   : OptConstantWord       %dprec 1
+       | OptSignalWord %dprec 2
+       ;
+
+OptConstantWord        : /* empty */
+       | T_CONSTANT
+       ;
+
+OptSignalWord  : /* empty */
+               { printf("empty: %d/%d\n", @$.first_column, @$.last_column); }
+       | T_SIGNAL
+       ;
+
+%%
+
+void yyerror(const char *msg)
+{
+  fprintf (stderr, "error\n");
+}
+
+static int lexIndex;
+
+int yylex() 
+{
+  lexIndex += 1;
+  switch (lexIndex)
+    {
+    case 1:
+      yylloc.first_column = 1;
+      yylloc.last_column = 9;
+      return T_PORT;
+    case 2:
+      yylloc.first_column = 13;
+      yylloc.last_column = 17;
+      return T_PORT;
+    default:
+      return 0;
+    }
+}
+
+int
+main (void) 
+{
+  yyparse();
+  return 0;
+}
+]])
+
+AT_CHECK([[bison -o glr-regr8.c glr-regr8.y]], 0, [],
+[glr-regr8.y: conflicts: 1 reduce/reduce
+])
+AT_COMPILE([glr-regr8])
+
+AT_CHECK([[./glr-regr8]], 0, 
+[empty: 9/9
+1/9 - 9/9 - 13/17
+],
+[])
+
+AT_CLEANUP





reply via email to

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