bug-bison
[Top][All Lists]
Advanced

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

Re: undefining YYRHSLOC in the GLR parser


From: Paul Eggert
Subject: Re: undefining YYRHSLOC in the GLR parser
Date: Tue, 14 Dec 2004 10:48:03 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Frank Heckenbach <address@hidden> writes:

> perhaps one could reuse YYLLOC_DEFAULT like this:
>
> - call YYLLOC_DEFAULT with N=2 (this might involve creating a
>   temporary array of these two locations)
>
> - copy the result entirely to the error location

Thanks for the suggestion.  I did that.  While doing that, I noticed
that the current usage of yyerror_range wasn't portable, since it
subtracts 1 from the start of an array, which has undefined behavior
in C.  So I installed this patch to fix both problems.  Please give it
a try.

2004-12-14  Paul Eggert  <address@hidden>

        * data/glr.c (struct yyGLRStack): yyerror_range now has 3 items,
        not 2, since it's not portable to subtract 1 from the start of an
        array.  The new item 0 is never set or used.  All uses changed.

        (yyrecoverSyntaxError): Use YYLLOC_DEFAULT instead of assuming
        the default definition of YYLLOC_DEFAULT.  Problem reported
        by Frank Heckenbach.

--- glr.c       12 Dec 2004 09:25:45 -0000      1.84
+++ glr.c       14 Dec 2004 18:48:42 -0000      1.85
@@ -612,8 +612,8 @@ union yyGLRStackItem {
 struct yyGLRStack {
   int yyerrflag;
   int yyerrState;
-]b4_location_if([[  /* To compute the location of the error token,  */
-  yyGLRStackItem yyerror_range[2];]])[
+]b4_location_if([[  /* To compute the location of the error token.  */
+  yyGLRStackItem yyerror_range[3];]])[
 ]b4_pure_if(
 [
   int yyerrcnt;
@@ -1722,7 +1722,7 @@ yyrecoverSyntaxError (yyGLRStack* yystac
            while (yystack->yytops.yystates[0] != NULL)
              {
                yyGLRState *yys = yystack->yytops.yystates[0];
-]b4_location_if([[             yystack->yyerror_range[0].yystate.yyloc = 
yys->yyloc;]])[
+]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])[);
@@ -1737,8 +1737,10 @@ yyrecoverSyntaxError (yyGLRStack* yystac
            /* We throw away the lookahead, but the error range
               of the shifted error token must take it into account. */
            yyGLRState *yys = yystack->yytops.yystates[0];
-           yys->yyloc.last_line   = yyllocp->last_line;
-           yys->yyloc.last_column = yyllocp->last_column;]])[
+           yyGLRStackItem yyerror_range[3];
+           yyerror_range[1].yystate.yyloc = yys->yyloc;
+           yyerror_range[2].yystate.yyloc = *yyllocp;
+           YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
            yydestruct ("Error: discarding",
                        *yytokenp, yylvalp]b4_location_if([, yyllocp])[);
          }
@@ -1784,8 +1786,8 @@ yyrecoverSyntaxError (yyGLRStack* yystac
            {
              /* Shift the error token having adjusted its location.  */
              YYLTYPE yyerrloc;]b4_location_if([[
-             yystack->yyerror_range[1].yystate.yyloc = *yyllocp;
-             YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range - 1, 2);]])[
+             yystack->yyerror_range[2].yystate.yyloc = *yyllocp;
+             YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range, 2);]])[
              YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
                               yylvalp, &yyerrloc);
              yyglrShift (yystack, 0, yytable[yyj],
@@ -1794,7 +1796,7 @@ yyrecoverSyntaxError (yyGLRStack* yystac
              break;
            }
        }
-]b4_location_if([[      yystack->yyerror_range[0].yystate.yyloc = 
yys->yyloc;]])[
+]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])[);
@@ -1893,7 +1895,7 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
              yyrule = yydefaultAction (yystate);
              if (yyrule == 0)
                {
-]b4_location_if([[               yystack.yyerror_range[0].yystate.yyloc = 
*yyllocp;]])[
+]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = 
*yyllocp;]])[
                  yyreportSyntaxError (&yystack, yylvalp, 
yyllocp]b4_user_args[);
                  goto yyuser_error;
                }
@@ -1924,7 +1926,7 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
                }
              else if (yyisErrorAction (yyaction))
                {
-]b4_location_if([[               yystack.yyerror_range[0].yystate.yyloc = 
*yyllocp;]])[
+]b4_location_if([[               yystack.yyerror_range[1].yystate.yyloc = 
*yyllocp;]])[
                  yyreportSyntaxError (&yystack, yylvalp, 
yyllocp]b4_user_args[);
                  goto yyuser_error;
                }
@@ -1950,7 +1952,7 @@ b4_syncline(address@hidden@], address@hidden@])])dnl
                yyFail (&yystack][]b4_lpure_args[, "syntax error");
              YYCHK1 (yyresolveStack (&yystack]b4_user_args[));
              YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
-]b4_location_if([[           yystack.yyerror_range[0].yystate.yyloc = 
*yyllocp;]])[
+]b4_location_if([[           yystack.yyerror_range[1].yystate.yyloc = 
*yyllocp;]])[
              yyreportSyntaxError (&yystack, yylvalp, yyllocp]b4_user_args[);
              goto yyuser_error;
            }






reply via email to

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