[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reductions during Bison error handling
From: |
Paul Hilfinger |
Subject: |
Re: Reductions during Bison error handling |
Date: |
Tue, 21 May 2002 20:18:39 -0700 |
> I'd like to see the Paul H.'s fix before it gets installed, but from
> what I've seen so far it looks like a good idea.
Ok. First, here's a simple version of the patch.
----------------------------------------------------------------------
2002-05-21 Paul Hilfinger <address@hidden>
* data/bison.simple (yyparse): Correct error handling to conform to
POSIX and yacc. Specifically, after syntax error is discovered,
do not reduce further before shifting the error token.
Index: 2.35/data/bison.simple
--- 2.35/data/bison.simple Thu, 16 May 2002 16:30:36 -0700 hilfingr
(glrbison/37_bison.simp 1.7 644)
+++ 2.36/data/bison.simple Tue, 21 May 2002 19:19:31 -0700 hilfingr
(glrbison/37_bison.simp 1.8 644)
@@ -1176,14 +1176,7 @@
goto yyerrdefault;
yyn = yytable[yyn];
- if (yyn < 0)
- {
- if (yyn == YYFLAG)
- goto yyerrpop;
- yyn = -yyn;
- goto yyreduce;
- }
- else if (yyn == 0)
+ if (yyn <= 0)
goto yyerrpop;
if (yyn == YYFINAL)
----------------------------------------------------------------------
Or, if you prefer, we can take the opportunity to clean things up in
this part of the skeleton, giving, perhaps, the following:
Index: 2.35/data/bison.simple
--- 2.35/data/bison.simple Thu, 16 May 2002 16:30:36 -0700 hilfingr
(glrbison/37_bison.simp 1.7 644)
+++ 2.37/data/bison.simple Tue, 21 May 2002 20:12:33 -0700 hilfingr
(glrbison/37_bison.simp 1.9 644)
@@ -1095,7 +1095,6 @@
#endif /* YYERROR_VERBOSE */
yyerror ("parse error");
}
- goto yyerrlab1;
/*----------------------------------------------------.
@@ -1120,73 +1119,42 @@
yyerrstatus = 3; /* Each real token shifted decrements this. */
- goto yyerrhandle;
-
-
-/*-------------------------------------------------------------------.
-| yyerrdefault -- current state does not do anything special for the |
-| error token. |
-`-------------------------------------------------------------------*/
-yyerrdefault:
-#if 0
- /* This is wrong; only states that explicitly want error tokens
- should shift them. */
-
- /* If its default is to accept any token, ok. Otherwise pop it. */
- yyn = yydefact[yystate];
- if (yyn)
- goto yydefault;
-#endif
+/*--------------.
+| yyerrhandle. |
+`--------------*/
+yyerrhandle:
+ while (1)
+ {
+ yyn = yypact[yystate] + YYTERROR;
+ if (yyn != YYFLAG + YYTERROR &&
+ yyn >= 0 && yyn <= YYLAST && yycheck[yyn] == YYTERROR &&
+ yytable[yyn] > 0)
+ break; /* Found state that can shift error token */
-/*---------------------------------------------------------------.
-| yyerrpop -- pop the current state because it cannot handle the |
-| error token. |
-`---------------------------------------------------------------*/
-yyerrpop:
- if (yyssp == yyss)
- YYABORT;
- yyvsp--;
- yystate = *--yyssp;
+ /* Otherwise, Pop the parsing stack. */
+ if (yyssp == yyss)
+ YYABORT;
+ yyvsp--;
+ yystate = *--yyssp;
#if YYLSP_NEEDED
- yylsp--;
+ yylsp--;
#endif
#if YYDEBUG
- if (yydebug)
- {
- short *yyssp1 = yyss - 1;
- YYFPRINTF (stderr, "Error: state stack now");
- while (yyssp1 != yyssp)
- YYFPRINTF (stderr, " %d", *++yyssp1);
- YYFPRINTF (stderr, "\n");
- }
+ if (yydebug)
+ {
+ short *yyssp1 = yyss - 1;
+ YYFPRINTF (stderr, "Error: state stack now");
+ while (yyssp1 != yyssp)
+ YYFPRINTF (stderr, " %d", *++yyssp1);
+ YYFPRINTF (stderr, "\n");
+ }
#endif
-
-/*--------------.
-| yyerrhandle. |
-`--------------*/
-yyerrhandle:
- yyn = yypact[yystate];
- if (yyn == YYFLAG)
- goto yyerrdefault;
-
- yyn += YYTERROR;
- if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
- goto yyerrdefault;
-
- yyn = yytable[yyn];
- if (yyn < 0)
- {
- if (yyn == YYFLAG)
- goto yyerrpop;
- yyn = -yyn;
- goto yyreduce;
}
- else if (yyn == 0)
- goto yyerrpop;
- if (yyn == YYFINAL)
+ yystate = yytable[yyn];
+ if (yystate == YYFINAL)
YYACCEPT;
YYDPRINTF ((stderr, "Shifting error token, "));
@@ -1196,7 +1164,6 @@
*++yylsp = yylloc;
#endif
- yystate = yyn;
goto yynewstate;
P. Hilfinger
- Re: Another error handling (Was: Reductions during Bison error handling), (continued)
- Re: Reductions during Bison error handling, Akim Demaille, 2002/05/20
- Re: Reductions during Bison error handling, Richard Stallman, 2002/05/20
- Re: Reductions during Bison error handling, Paul Hilfinger, 2002/05/20
- Re: Reductions during Bison error handling, Richard Stallman, 2002/05/21
- Re: Reductions during Bison error handling, Hans Aberg, 2002/05/21
- Re: Reductions during Bison error handling, Richard Stallman, 2002/05/23
- Re: Reductions during Bison error handling, Akim Demaille, 2002/05/24
- Re: Reductions during Bison error handling, Hans Aberg, 2002/05/24
- Re: Reductions during Bison error handling, Paul Eggert, 2002/05/21
- Re: Reductions during Bison error handling,
Paul Hilfinger <=
- Re: Reductions during Bison error handling, Paul Eggert, 2002/05/22
- Re: Reductions during Bison error handling, Paul Hilfinger, 2002/05/22
- Re: Reductions during Bison error handling, Akim Demaille, 2002/05/23
- Re: Reductions during Bison error handling, Hans Aberg, 2002/05/23
- Re: Reductions during Bison error handling, Richard Stallman, 2002/05/23
- Re: Reductions during Bison error handling, Paul Hilfinger, 2002/05/23
- Re: Reductions during Bison error handling, Richard Stallman, 2002/05/25
- Re: Reductions during Bison error handling, Mike Castle, 2002/05/23
Re: Reductions during Bison error handling, Paul Eggert, 2002/05/20