mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 10:43:02 +00:00
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.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
2010-11-07 Joel E. Denny <jdenny@clemson.edu>
|
||||||
|
|
||||||
|
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 <jdenny@clemson.edu>
|
2010-11-07 Joel E. Denny <jdenny@clemson.edu>
|
||||||
|
|
||||||
yysyntax_error: fix for consistent error with lookahead.
|
yysyntax_error: fix for consistent error with lookahead.
|
||||||
|
|||||||
@@ -692,6 +692,17 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
|||||||
default:
|
default:
|
||||||
break;
|
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);
|
YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);
|
||||||
|
|
||||||
yypop_ (yylen);
|
yypop_ (yylen);
|
||||||
@@ -715,6 +726,10 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
|||||||
| yyerrlab -- here on detecting error |
|
| yyerrlab -- here on detecting error |
|
||||||
`------------------------------------*/
|
`------------------------------------*/
|
||||||
yyerrlab:
|
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 not already recovering from an error, report this error. */
|
||||||
if (!yyerrstatus_)
|
if (!yyerrstatus_)
|
||||||
{
|
{
|
||||||
@@ -826,7 +841,13 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
|||||||
|
|
||||||
yyreturn:
|
yyreturn:
|
||||||
if (yychar != yyempty_)
|
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
|
/* Do not reclaim the symbols of the rule which action triggered
|
||||||
this YYABORT or YYACCEPT. */
|
this YYABORT or YYACCEPT. */
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ AT_SKEL_JAVA_IF([AT_DATA], [AT_DATA_GRAMMAR])([input.y],
|
|||||||
}]], [[
|
}]], [[
|
||||||
|
|
||||||
%code {]AT_SKEL_CC_IF([[
|
%code {]AT_SKEL_CC_IF([[
|
||||||
|
#include <cassert>
|
||||||
#include <string>]], [[
|
#include <string>]], [[
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -376,7 +377,7 @@ error-reduce:
|
|||||||
;
|
;
|
||||||
|
|
||||||
consistent-reduction: /*empty*/ {
|
consistent-reduction: /*empty*/ {
|
||||||
assert (yychar == YYEMPTY);
|
assert (yychar == ]AT_SKEL_CC_IF([[yyempty_]], [[YYEMPTY]])[);
|
||||||
yylval = 0;
|
yylval = 0;
|
||||||
yychar = 'b';
|
yychar = 'b';
|
||||||
} ;
|
} ;
|
||||||
@@ -400,7 +401,11 @@ AT_CONSISTENT_ERRORS_CHECK([[%glr-parser]],
|
|||||||
[AT_USER_ACTION_GRAMMAR],
|
[AT_USER_ACTION_GRAMMAR],
|
||||||
[AT_USER_ACTION_INPUT],
|
[AT_USER_ACTION_INPUT],
|
||||||
[['b']], [[none]])
|
[['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_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions consistent]],
|
||||||
[AT_USER_ACTION_GRAMMAR],
|
[AT_USER_ACTION_GRAMMAR],
|
||||||
|
|||||||
Reference in New Issue
Block a user