[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reductions during Bison error handling
From: |
Paul Eggert |
Subject: |
Re: Reductions during Bison error handling |
Date: |
Fri, 24 May 2002 05:49:13 -0700 (PDT) |
> Date: Thu, 23 May 2002 16:17:58 +0200
> From: Hans Aberg <address@hidden>
>
> In math, typically the semantically more significant (to the human
> reader's cognition) quantity should be on the LHS.
In math, one normally sees expressions like '0 < i < n'. The closest
equivalent in C is '0 < i && i < n'. That is what I was using here.
I find this more readable than 'i > 0 && i < n'. Once you get used
to the "<"-oriented style I hope you'll agree that it has its advantages.
> One should be aware of that long statements in the "for" and "while" heads
> decreases legibility.
Yes, on second thought that part of the change was a bit overboard. I
installed the following patch instead. It goes back to something that
is more like the original Bison code than what I proposed, or even
that Paul H. proposed. If RMS finds a problem with this approach we
can undo the patch.
2002-05-24 Paul Hilfinger <address@hidden>
and Paul Eggert <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.
Clean up the code a bit by removing the labels yyerrdefault,
yyerrhandle, yyerrpop.
* NEWS: Document the above.
--- NEWS.~1.43.~ 2002-05-05 04:55:45.000000000 -0700
+++ NEWS 2002-05-24 05:37:48.258881000 -0700
@@ -17,6 +17,15 @@ Changes in version 1.49b:
user specified that one of her tokens is numbered 256, then error
will be mapped onto another number.
+* Error recovery now conforms to documentation and to POSIX
+ When a Bison-generated parser encounters a syntax error, it now pops
+ the stack until it finds a state that allows shifting the error
+ token. Formerly, it popped the stack until it found a state that
+ allowed some non-error action other than a default reduction on the
+ error token. The new behavior has long been the documented behavior,
+ and has long been required by POSIX. For more details, please see
+ <http://mail.gnu.org/pipermail/bug-bison/2002-May/001452.html>.
+
* Large grammars
Large grammars are now supported (large token numbers, large grammar
size (= sum of the LHS and RHS lengths), large LALR tables).
--- data/bison.simple.~1.26.~ 2002-05-20 15:56:53.000000000 -0700
+++ data/bison.simple 2002-05-24 04:42:03.257880000 -0700
@@ -1120,71 +1120,40 @@ yyerrlab1:
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
-
-
-/*---------------------------------------------------------------.
-| yyerrpop -- pop the current state because it cannot handle the |
-| error token. |
-`---------------------------------------------------------------*/
-yyerrpop:
- if (yyssp == yyss)
- YYABORT;
- yyvsp--;
- yystate = *--yyssp;
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYFLAG)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ 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)
YYACCEPT;
- Re: Reductions during Bison error handling,
Paul Eggert <=