[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch to fix problem with embedded rules in GLR parsers.
From: |
Paul Eggert |
Subject: |
Re: Patch to fix problem with embedded rules in GLR parsers. |
Date: |
Sun, 1 Jun 2003 23:23:12 -0700 (PDT) |
I installed the following patch to glr.c to fix the problem I
mentioned a few months ago. This uses a conservative patch, instead
of the more speculative one I suggested in February.
2003-06-01 Paul Eggert <address@hidden>
Fix a GLR parser bug I reported in February; see
<http://mail.gnu.org/archive/html/bison-patches/2003-02/msg00008.html>.
The problem was that GLR parsers did not conform to the C standard,
because actions like { $1 = $2 + $3; } expanded to expressions
that invoked YYFILL in separate subexpressions, and YYFILL assigned
to a local variable. The C standard says that expressions
like (var = f ()) + (var = f ()) have undefined behavior.
Another problem was that GCC sometimes issues warnings that
yyfill and its parameters are unused.
* data/glr.c (yyfillin): Renamed from the old yyfill. Mark
as possibly unused.
(yyfill): New function.
(YYFILL): Use it.
(yyuserAction): Change type of yynormal to bool, so that it matches
the new yyfill signature. Mark it as possibly unused.
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.55
diff -p -u -r1.55 glr.c
--- data/glr.c 25 May 2003 06:43:19 -0000 1.55
+++ data/glr.c 2 Jun 2003 06:15:07 -0000
@@ -615,9 +615,10 @@ 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. For convenience, returns YYLOW1. */
-static int
-yyfill (yyGLRStackItem* yyvsp, int yylow0, int yylow1)
+ * YYLOW1 < YYLOW0. */
+static void yyfillin (yyGLRStackItem *, int, int) ATTRIBUTE_UNUSED;
+static void
+yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
{
yyGLRState* s;
int i;
@@ -631,6 +632,21 @@ yyfill (yyGLRStackItem* yyvsp, int yylow
yyvsp[i].yystate.yyloc = s->yyloc;
s = yyvsp[i].yystate.yypred = s->yypred;
}
+}
+
+/* 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. */
+static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
+ ATTRIBUTE_UNUSED;
+static inline int
+yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
+{
+ if (!yynormal && yylow1 < *yylow)
+ {
+ yyfillin (yyvsp, *yylow, yylow1);
+ *yylow = yylow1;
+ }
return yylow1;
}
@@ -644,7 +660,7 @@ yyuserAction (yyRuleNum yyn, int yyrhsle
YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack
]b4_user_formals[)
{
- int yynormal = (yystack->yysplitPoint == NULL);
+ yybool yynormal ATTRIBUTE_UNUSED = (yystack->yysplitPoint == NULL);
int yylow;
if (yyrhslen == 0)
@@ -670,8 +686,7 @@ yyuserAction (yyRuleNum yyn, int yyrhsle
# undef yyclearin
# define yyclearin (yychar = *(yystack->yytokenp) = YYEMPTY)
# undef YYFILL
-# define YYFILL(N) \
- ((yynormal || yylow <= (N)) ? (N) : (yylow = yyfill (yyvsp, yylow, N)))
+# define YYFILL(N) yyfill (yyvsp, &yylow, N, yynormal)
# undef YYBACKUP
# define YYBACKUP(Token, Value)
\
do { \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Patch to fix problem with embedded rules in GLR parsers.,
Paul Eggert <=