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 (parse.error=verbose and consistent errors): Reorganize.
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 (parse.error=verbose and consistent errors):
|
||||||
|
Reorganize.
|
||||||
|
|
||||||
2010-11-07 Joel E. Denny <jdenny@clemson.edu>
|
2010-11-07 Joel E. Denny <jdenny@clemson.edu>
|
||||||
|
|
||||||
yysyntax_error: prepare for readability of next patches.
|
yysyntax_error: prepare for readability of next patches.
|
||||||
|
|||||||
11
data/glr.c
11
data/glr.c
@@ -2076,9 +2076,11 @@ yyprocessOneStack (yyGLRStack* yystackp, size_t yyk,
|
|||||||
/*ARGSUSED*/ static void
|
/*ARGSUSED*/ static void
|
||||||
yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
||||||
{
|
{
|
||||||
if (yystackp->yyerrState == 0)
|
if (yystackp->yyerrState != 0)
|
||||||
{
|
return;
|
||||||
#if YYERROR_VERBOSE
|
#if ! YYERROR_VERBOSE
|
||||||
|
yyerror (]b4_lyyerror_args[YY_("syntax error"));
|
||||||
|
#else
|
||||||
int yyn;
|
int yyn;
|
||||||
yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
|
yyn = yypact[yystackp->yytops.yystates[0]->yylrState];
|
||||||
if (YYPACT_NINF < yyn && yyn <= YYLAST)
|
if (YYPACT_NINF < yyn && yyn <= YYLAST)
|
||||||
@@ -2175,11 +2177,10 @@ if (YYPACT_NINF < yyn && yyn <= YYLAST)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* YYERROR_VERBOSE */
|
|
||||||
yyerror (]b4_lyyerror_args[YY_("syntax error"));
|
yyerror (]b4_lyyerror_args[YY_("syntax error"));
|
||||||
|
#endif /* YYERROR_VERBOSE */
|
||||||
yynerrs += 1;
|
yynerrs += 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
|
/* Recover from a syntax error on *YYSTACKP, assuming that *YYSTACKP->YYTOKENP,
|
||||||
yylval, and yylloc are the syntactic category, semantic value, and location
|
yylval, and yylloc are the syntactic category, semantic value, and location
|
||||||
|
|||||||
@@ -977,8 +977,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[
|
|||||||
]b4_parser_class_name[::yysyntax_error_ (]dnl
|
]b4_parser_class_name[::yysyntax_error_ (]dnl
|
||||||
b4_error_verbose_if([state_type yystate, int yytoken],
|
b4_error_verbose_if([state_type yystate, int yytoken],
|
||||||
[int, int])[)
|
[int, int])[)
|
||||||
{
|
{]b4_error_verbose_if([[
|
||||||
std::string yyres;]b4_error_verbose_if([[
|
std::string yyres;
|
||||||
int yyn = yypact_[yystate];
|
int yyn = yypact_[yystate];
|
||||||
if (yypact_ninf_ < yyn && yyn <= yylast_)
|
if (yypact_ninf_ < yyn && yyn <= yylast_)
|
||||||
{
|
{
|
||||||
@@ -1038,9 +1038,9 @@ b4_error_verbose_if([state_type yystate, int yytoken],
|
|||||||
yyres += *yyp;
|
yyres += *yyp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
]])dnl
|
yyres = YY_("syntax error");
|
||||||
[ yyres = YY_("syntax error");
|
return yyres;]], [[
|
||||||
return yyres;
|
return YY_("syntax error");]])[
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -147,21 +147,6 @@ AT_SETUP([[parse.error=verbose and consistent errors]])
|
|||||||
|
|
||||||
m4_pushdef([AT_CONSISTENT_ERRORS_CHECK], [
|
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],
|
AT_DATA_GRAMMAR([input.y],
|
||||||
[[%code {
|
[[%code {
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@@ -171,63 +156,20 @@ AT_DATA_GRAMMAR([input.y],
|
|||||||
#define USE(Var)
|
#define USE(Var)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
]$1[
|
||||||
|
|
||||||
%define parse.error verbose
|
%define parse.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
|
]$2[
|
||||||
// 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' ;
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
int
|
int
|
||||||
yylex (void)
|
yylex (void)
|
||||||
{
|
{
|
||||||
static char const *input = "aa";
|
static char const *input = "]$3[";
|
||||||
yylval = 1;
|
yylval = 1;
|
||||||
return *input++;
|
return *input++;
|
||||||
}
|
}
|
||||||
@@ -244,18 +186,91 @@ main (void)
|
|||||||
return yyparse ();
|
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.
|
# See comments in grammar for why this test doesn't succeed.
|
||||||
AT_XFAIL_IF([[:]])
|
AT_XFAIL_IF([[:]])
|
||||||
|
|
||||||
AT_CONSISTENT_ERRORS_CHECK([], [['b']], [[none]])
|
AT_CONSISTENT_ERRORS_CHECK([[]],
|
||||||
AT_CONSISTENT_ERRORS_CHECK([[-Dlr.default-reductions=consistent]],
|
[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]])
|
[['b']], [[none]])
|
||||||
|
|
||||||
# Canonical LR doesn't foresee the error for 'a'!
|
# 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]])
|
[[$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])
|
m4_popdef([AT_CONSISTENT_ERRORS_CHECK])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user