More fixes related to last two patches.

* data/bison.m4 (b4_integral_parser_tables_map): Fix YYTABLE
comments: zero indicates syntax error not default action.
* data/c.m4 (b4_table_value_equals): Comment that YYID must be
defined.
* data/glr.c (yyis_pact_ninf): Rename to...
(yypact_value_is_default): ... this.
(yyisDefaultedState): Update for rename.
(yyis_table_ninf): Rename to...
(yytable_value_is_error): ... this, and check for value zero
besides just YYTABLE_NINF.
(yygetLRActions): Check for default value from yypact.  It
appears that this check is always performed before this function
is invoked, and so adding the check here is probably redundant.
However, the code may evolve after this subtlety is forgotten.
Also, update for rename to yytable_value_is_error.  Because that
macro now checks for zero, a different but equivalent branch of
the if-then-else here is evaluated.
(yyreportSyntaxError): Update for rename to
yytable_value_is_error.  The zero condition was mishandled
before.
(yyrecoverSyntaxError): Update for renames.  No behavioral
changes.
* data/lalr1.cc, data/lalr1.java (yy_pact_value_is_default_):
New function.
(yy_table_value_is_error_): New function.
(parse): Use new functions where possible.  No behavioral
changes.
(yysyntax_error_, yysyntax_error): Use yy_table_value_is_error_.
The zero condition was mishandled before.
* data/yacc.c (yyis_pact_ninf): Rename to...
(yypact_value_is_default): ... this.
(yyis_table_ninf): Rename to...
(yytable_value_is_error): ... this, and check for value zero
besides just YYTABLE_NINF.
(yysyntax_error): Update for rename to yytable_value_is_error.
The zero condition was mishandled before.
(yyparse): Update for renames.  No behavioral changes.
* src/tables.h: Improve comments about yypact, yytable, etc.
more.  Most importantly, say yytable value of zero means syntax
error not default action.
This commit is contained in:
Joel E. Denny
2009-08-25 19:41:49 -04:00
parent 53f036ce02
commit f2b30bdf37
10 changed files with 366 additions and 277 deletions

View File

@@ -953,7 +953,7 @@ yylhsNonterm (yyRuleNum yyrule)
return yyr1[yyrule];
}
#define yyis_pact_ninf(yystate) \
#define yypact_value_is_default(yystate) \
]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
/** True iff LR state STATE has only a default reduction (regardless
@@ -961,7 +961,7 @@ yylhsNonterm (yyRuleNum yyrule)
static inline yybool
yyisDefaultedState (yyStateNum yystate)
{
return yyis_pact_ninf (yypact[yystate]);
return yypact_value_is_default (yypact[yystate]);
}
/** The default reduction for STATE, assuming it has one. */
@@ -971,8 +971,9 @@ yydefaultAction (yyStateNum yystate)
return yydefact[yystate];
}
#define yyis_table_ninf(yytable_value) \
]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
#define yytable_value_is_error(yytable_value) \
(]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[ \
|| ]b4_table_value_equals([[table]], [[yytable_value]], [[0]])[)
/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
* Result R means
@@ -987,12 +988,13 @@ yygetLRActions (yyStateNum yystate, int yytoken,
int* yyaction, const short int** yyconflicts)
{
int yyindex = yypact[yystate] + yytoken;
if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
if (yypact_value_is_default (yypact[yystate])
|| yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
{
*yyaction = -yydefact[yystate];
*yyconflicts = yyconfl;
}
else if (! yyis_table_ninf (yytable[yyindex]))
else if (! yytable_value_is_error (yytable[yyindex]))
{
*yyaction = yytable[yyindex];
*yyconflicts = yyconfl + yyconflp[yyindex];
@@ -2061,7 +2063,7 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
&& !yyis_table_ninf (yytable[yyx + yyn]))
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
@@ -2172,7 +2174,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
if (yyis_pact_ninf (yyj))
if (yypact_value_is_default (yyj))
return;
yyj += yytoken;
if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != yytoken)
@@ -2180,7 +2182,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
if (yydefact[yystackp->yytops.yystates[0]->yylrState] != 0)
return;
}
else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))
else if (! yytable_value_is_error (yytable[yyj]))
return;
}
@@ -2201,7 +2203,7 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
{
yyGLRState *yys = yystackp->yytops.yystates[0];
yyj = yypact[yys->yylrState];
if (! yyis_pact_ninf (yyj))
if (! yypact_value_is_default (yyj))
{
yyj += YYTERROR;
if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR