mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
yysyntax_error: more preparation for readability of next patch.
There are no behavioral changes here.
* data/glr.c (yyreportSyntaxError): Reorganize.
* data/lalr1.cc (yy::parser::yysyntax_error_): Reorganize.
* tests/conflicts.at (%error-verbose and consistent errors):
Reorganize.
(cherry picked from commit 25a648d8a6)
Conflicts:
tests/conflicts.at
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
2010-11-07 Joel E. Denny <jdenny@clemson.edu>
|
||||
|
||||
yysyntax_error: more preparation for readability of next patch.
|
||||
There are no behavioral changes here.
|
||||
* data/glr.c (yyreportSyntaxError): Reorganize.
|
||||
* data/lalr1.cc (yy::parser::yysyntax_error_): Reorganize.
|
||||
* tests/conflicts.at (%error-verbose and consistent errors):
|
||||
Reorganize.
|
||||
|
||||
2010-11-07 Joel E. Denny <jdenny@clemson.edu>
|
||||
|
||||
yysyntax_error: prepare for readability of next patches.
|
||||
|
||||
11
data/glr.c
11
data/glr.c
@@ -2089,9 +2089,11 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
|
||||
/*ARGSUSED*/ static void
|
||||
yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
||||
{
|
||||
if (yystackp->yyerrState == 0)
|
||||
{
|
||||
#if YYERROR_VERBOSE
|
||||
if (yystackp->yyerrState != 0)
|
||||
return;
|
||||
#if ! YYERROR_VERBOSE
|
||||
yyerror (]b4_lyyerror_args[YY_("syntax error"));
|
||||
#else
|
||||
int yyn;
|
||||
yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
|
||||
if (YYPACT_NINF < yyn && yyn <= YYLAST)
|
||||
@@ -2188,11 +2190,10 @@ if (YYPACT_NINF < yyn && yyn <= YYLAST)
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif /* YYERROR_VERBOSE */
|
||||
yyerror (]b4_lyyerror_args[YY_("syntax error"));
|
||||
#endif /* YYERROR_VERBOSE */
|
||||
yynerrs += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
|
||||
yylval, and yylloc are the syntactic category, semantic value, and location
|
||||
|
||||
@@ -846,8 +846,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
||||
]b4_parser_class_name[::yysyntax_error_ (]dnl
|
||||
b4_error_verbose_if([int yystate, int yytoken],
|
||||
[int, int])[)
|
||||
{
|
||||
std::string yyres;]b4_error_verbose_if([[
|
||||
{]b4_error_verbose_if([[
|
||||
std::string yyres;
|
||||
int yyn = yypact_[yystate];
|
||||
if (yypact_ninf_ < yyn && yyn <= yylast_)
|
||||
{
|
||||
@@ -907,9 +907,9 @@ b4_error_verbose_if([int yystate, int yytoken],
|
||||
yyres += *yyp;
|
||||
}
|
||||
else
|
||||
]])dnl
|
||||
[ yyres = YY_("syntax error");
|
||||
return yyres;
|
||||
yyres = YY_("syntax error");
|
||||
return yyres;]], [[
|
||||
return YY_("syntax error");]])[
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -147,21 +147,6 @@ AT_SETUP([[%error-verbose and consistent errors]])
|
||||
|
||||
m4_pushdef([AT_CONSISTENT_ERRORS_CHECK], [
|
||||
|
||||
AT_BISON_CHECK([$1[ -o input.c input.y]])
|
||||
AT_COMPILE([[input]])
|
||||
|
||||
m4_pushdef([AT_EXPECTING], [m4_if($3, [ab], [[, expecting 'a' or 'b']],
|
||||
$3, [a], [[, expecting 'a']],
|
||||
$3, [b], [[, expecting 'b']])])
|
||||
|
||||
AT_PARSER_CHECK([[./input]], [[1]], [],
|
||||
[[syntax error, unexpected ]$2[]AT_EXPECTING[
|
||||
]])
|
||||
|
||||
m4_popdef([AT_EXPECTING])
|
||||
|
||||
])
|
||||
|
||||
AT_DATA_GRAMMAR([input.y],
|
||||
[[%code {
|
||||
#include <assert.h>
|
||||
@@ -171,63 +156,20 @@ AT_DATA_GRAMMAR([input.y],
|
||||
#define USE(Var)
|
||||
}
|
||||
|
||||
]$1[
|
||||
|
||||
%error-verbose
|
||||
|
||||
// The point isn't to test IELR here, but state merging happens to
|
||||
// complicate the example.
|
||||
%define lr.type ielr
|
||||
|
||||
%nonassoc 'a'
|
||||
|
||||
// If yylval=0 here, then we know that the 'a' destructor is being
|
||||
// invoked incorrectly for the 'b' set in the semantic action below.
|
||||
// All 'a' tokens are returned by yylex, which sets yylval=1.
|
||||
%destructor {
|
||||
if (!$$)
|
||||
fprintf (stderr, "Wrong destructor.\n");
|
||||
} 'a'
|
||||
|
||||
%%
|
||||
|
||||
// The lookahead assigned by the semantic action isn't needed before
|
||||
// either error action is encountered. In a previous version of Bison,
|
||||
// this was a problem as it meant yychar was not translated into yytoken
|
||||
// before either error action. The second error action thus invoked a
|
||||
// destructor that it selected according to the incorrect yytoken. The
|
||||
// first error action would have reported an incorrect unexpected token
|
||||
// except that, due to another bug, the unexpected token is not reported
|
||||
// at all because the error action is the default action in a consistent
|
||||
// state. That bug still needs to be fixed.
|
||||
start: error-reduce consistent-error 'a' { USE ($3); } ;
|
||||
|
||||
error-reduce:
|
||||
'a' 'a' consistent-reduction consistent-error 'a'
|
||||
{ USE (($1, $2, $5)); }
|
||||
| 'a' error
|
||||
{ USE ($1); }
|
||||
;
|
||||
|
||||
consistent-reduction: /*empty*/ {
|
||||
assert (yychar == YYEMPTY);
|
||||
yylval = 0;
|
||||
yychar = 'b';
|
||||
} ;
|
||||
|
||||
consistent-error:
|
||||
'a' { USE ($1); }
|
||||
| /*empty*/ %prec 'a'
|
||||
;
|
||||
|
||||
// Provide another context in which all rules are useful so that this
|
||||
// test case looks a little more realistic.
|
||||
start: 'b' consistent-error 'b' ;
|
||||
]$2[
|
||||
|
||||
%%
|
||||
|
||||
int
|
||||
yylex (void)
|
||||
{
|
||||
static char const *input = "aa";
|
||||
static char const *input = "]$3[";
|
||||
yylval = 1;
|
||||
return *input++;
|
||||
}
|
||||
@@ -244,18 +186,91 @@ main (void)
|
||||
return yyparse ();
|
||||
}
|
||||
]])
|
||||
AT_BISON_CHECK([[-o input.c input.y]])
|
||||
AT_COMPILE([[input]])
|
||||
|
||||
m4_pushdef([AT_EXPECTING], [m4_if($5, [ab], [[, expecting 'a' or 'b']],
|
||||
$5, [a], [[, expecting 'a']],
|
||||
$5, [b], [[, expecting 'b']])])
|
||||
|
||||
AT_PARSER_CHECK([[./input]], [[1]], [[]],
|
||||
[[syntax error, unexpected ]$4[]AT_EXPECTING[
|
||||
]])
|
||||
|
||||
m4_popdef([AT_EXPECTING])
|
||||
|
||||
])
|
||||
|
||||
m4_pushdef([AT_USER_ACTION_GRAMMAR],
|
||||
[[%nonassoc 'a';
|
||||
|
||||
// If yylval=0 here, then we know that the 'a' destructor is being
|
||||
// invoked incorrectly for the 'b' set in the semantic action below.
|
||||
// All 'a' tokens are returned by yylex, which sets yylval=1.
|
||||
%destructor {
|
||||
if (!$$)
|
||||
fprintf (stderr, "Wrong destructor.\n");
|
||||
} 'a';
|
||||
|
||||
// The lookahead assigned by the semantic action isn't needed before
|
||||
// either error action is encountered. In a previous version of Bison,
|
||||
// this was a problem as it meant yychar was not translated into yytoken
|
||||
// before either error action. The second error action thus invoked a
|
||||
// destructor that it selected according to the incorrect yytoken. The
|
||||
// first error action would have reported an incorrect unexpected token
|
||||
// except that, due to another bug, the unexpected token is not reported
|
||||
// at all because the error action is the default action in a consistent
|
||||
// state. That bug still needs to be fixed.
|
||||
start: error-reduce consistent-error 'a' { USE ($][3); } ;
|
||||
|
||||
error-reduce:
|
||||
'a' 'a' consistent-reduction consistent-error 'a'
|
||||
{ USE (($][1, $][2, $][5)); }
|
||||
| 'a' error
|
||||
{ USE ($][1); }
|
||||
;
|
||||
|
||||
consistent-reduction: /*empty*/ {
|
||||
assert (yychar == YYEMPTY);
|
||||
yylval = 0;
|
||||
yychar = 'b';
|
||||
} ;
|
||||
|
||||
consistent-error:
|
||||
'a' { USE ($][1); }
|
||||
| /*empty*/ %prec 'a'
|
||||
;
|
||||
|
||||
// Provide another context in which all rules are useful so that this
|
||||
// test case looks a little more realistic.
|
||||
start: 'b' consistent-error 'b' ;
|
||||
]])
|
||||
m4_pushdef([AT_USER_ACTION_INPUT], [[aa]])
|
||||
|
||||
# See comments in grammar for why this test doesn't succeed.
|
||||
AT_XFAIL_IF([[:]])
|
||||
|
||||
AT_CONSISTENT_ERRORS_CHECK([], [['b']], [[none]])
|
||||
AT_CONSISTENT_ERRORS_CHECK([[-Dlr.default-reductions=consistent]],
|
||||
AT_CONSISTENT_ERRORS_CHECK([[]],
|
||||
[AT_USER_ACTION_GRAMMAR],
|
||||
[AT_USER_ACTION_INPUT],
|
||||
[['b']], [[none]])
|
||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions consistent]],
|
||||
[AT_USER_ACTION_GRAMMAR],
|
||||
[AT_USER_ACTION_INPUT],
|
||||
[['b']], [[none]])
|
||||
|
||||
# Canonical LR doesn't foresee the error for 'a'!
|
||||
AT_CONSISTENT_ERRORS_CHECK([[-Dlr.default-reductions=accepting]],
|
||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions accepting]],
|
||||
[AT_USER_ACTION_GRAMMAR],
|
||||
[AT_USER_ACTION_INPUT],
|
||||
[[$end]], [[a]])
|
||||
AT_CONSISTENT_ERRORS_CHECK([[-Flr.type=canonical-lr]], [[$end]], [[a]])
|
||||
AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
|
||||
[AT_USER_ACTION_GRAMMAR],
|
||||
[AT_USER_ACTION_INPUT],
|
||||
[[$end]], [[a]])
|
||||
|
||||
m4_popdef([AT_USER_ACTION_GRAMMAR])
|
||||
m4_popdef([AT_USER_ACTION_INPUT])
|
||||
|
||||
m4_popdef([AT_CONSISTENT_ERRORS_CHECK])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user