[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
yysyntax_error: adjust prior fixes for branch-2.5's lalr1.cc.
From: |
Joel E. Denny |
Subject: |
yysyntax_error: adjust prior fixes for branch-2.5's lalr1.cc. |
Date: |
Sun, 7 Nov 2010 17:48:15 -0500 (EST) |
User-agent: |
Alpine 1.00 (DEB 882 2007-12-20) |
I pushed this to branch-2.5.
>From 3b8378825ea8c3d2cae8c615a9ebf1f679730895 Mon Sep 17 00:00:00 2001
From: Joel E. Denny <address@hidden>
Date: Sun, 7 Nov 2010 16:10:09 -0500
Subject: [PATCH] yysyntax_error: adjust prior fixes for branch-2.5's lalr1.cc.
On master, there is no yychar in lalr1.cc, but there is on
branch-2.5, and the prior cherry-pick of "Fix handling of yychar
manipulation in user semantic actions" wasn't adjusted for that
difference.
* data/lalr1.cc (yy::parser::parse): Translate yychar before
every use of yytoken, and add comments explaining this approach.
* tests/conflicts.at (%error-verbose and consistent errors):
Extend to test yychar manipulation with lalr1.cc.
---
ChangeLog | 12 ++++++++++++
data/lalr1.cc | 23 ++++++++++++++++++++++-
tests/conflicts.at | 9 +++++++--
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0e711e5..1d80e92 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2010-11-07 Joel E. Denny <address@hidden>
+ yysyntax_error: adjust prior fixes for branch-2.5's lalr1.cc.
+ On master, there is no yychar in lalr1.cc, but there is on
+ branch-2.5, and the prior cherry-pick of "Fix handling of yychar
+ manipulation in user semantic actions" wasn't adjusted for that
+ difference.
+ * data/lalr1.cc (yy::parser::parse): Translate yychar before
+ every use of yytoken, and add comments explaining this approach.
+ * tests/conflicts.at (%error-verbose and consistent errors):
+ Extend to test yychar manipulation with lalr1.cc.
+
+2010-11-07 Joel E. Denny <address@hidden>
+
yysyntax_error: fix for consistent error with lookahead.
* NEWS (2.5): Document.
* data/yacc.c (yysyntax_error): In a verbose syntax error
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 33ab08e..8c91fb6 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -692,6 +692,17 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
default:
break;
}
+ /* User semantic actions sometimes alter yychar, and that requires
+ that yytoken be updated with the new translation. We take the
+ approach of translating immediately before every use of yytoken.
+ One alternative is translating here after every semantic action,
+ but that translation would be missed if the semantic action
+ invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
+ yychar. In the case of YYABORT or YYACCEPT, an incorrect
+ destructor might then be invoked immediately. In the case of
+ YYERROR, subsequent parser actions might lead to an incorrect
+ destructor call or verbose syntax error message before the
+ lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
yypop_ (yylen);
@@ -715,6 +726,10 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = yytranslate_ (yychar);
+
/* If not already recovering from an error, report this error. */
if (!yyerrstatus_)
{
@@ -826,7 +841,13 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
yyreturn:
if (yychar != yyempty_)
- yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
+ {
+ /* Make sure we have latest lookahead translation. See comments
+ at user semantic actions for why this is necessary. */
+ yytoken = yytranslate_ (yychar);
+ yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval,
+ &yylloc);
+ }
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
diff --git a/tests/conflicts.at b/tests/conflicts.at
index 1d4eb04..f455d1f 100644
--- a/tests/conflicts.at
+++ b/tests/conflicts.at
@@ -161,6 +161,7 @@ AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
}]], [[
%code {]AT_SKEL_CC_IF([[
+ #include <cassert>
#include <string>]], [[
#include <assert.h>
#include <stdio.h>
@@ -376,7 +377,7 @@ error-reduce:
;
consistent-reduction: /*empty*/ {
- assert (yychar == YYEMPTY);
+ assert (yychar == ]AT_SKEL_CC_IF([[yyempty_]], [[YYEMPTY]])[);
yylval = 0;
yychar = 'b';
} ;
@@ -400,7 +401,11 @@ AT_CONSISTENT_ERRORS_CHECK([[%glr-parser]],
[AT_USER_ACTION_GRAMMAR],
[AT_USER_ACTION_INPUT],
[['b']], [[none]])
-# No C++ or Java test because yychar cannot be manipulated by users.
+AT_CONSISTENT_ERRORS_CHECK([[%language "c++"]],
+ [AT_USER_ACTION_GRAMMAR],
+ [AT_USER_ACTION_INPUT],
+ [['b']], [[none]])
+# No Java test because yychar cannot be manipulated by users.
AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions consistent]],
[AT_USER_ACTION_GRAMMAR],
--
1.7.0.4
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- yysyntax_error: adjust prior fixes for branch-2.5's lalr1.cc.,
Joel E. Denny <=