bug-bison
[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: Fri, 28 Oct 2005 19:41:15 -0700

> On Fri, 28 Oct 2005, Claudia Hermann wrote:

> > i have a parser with glr activated and use the location tracking
> > function.  every things works fine as long as i don't use
> > ambiguous rules where i have to choose between with '%dprec'.
> > additionally i have an optional nonterminal at the beginning of
> > the rule. in this special case i get undefined values for the
> > optional nonterminal as well as for the whole rule. 
...
> 
> It's a bug in bison still in the latest CVS sources.
> 
> YYLLOC_DEFAULT is supposed to copy the location for an empty non-terminal 
> from the location of the previous symbol, but the current implementation 
> loses that location during a split GLR parse.


The following patch works for me, and passes make check. However, I
haven't really had time to properly test it.

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

        * data/glr.c (yyfill): Adjust comment.
        (yydoAction, yyresolveAction): Initialize default location properly 
        for empty right-hand sides.


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 Fri, 28 Oct 2005 19:37:04 -0700 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
@@ -1290,7 +1289,10 @@ yydoAction (yyGLRStack* yystack, size_t 
       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 +1566,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[);





reply via email to

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