Report rules which are never reduced by the parser: those hidden

by conflicts.
* src/LR0.c (save_reductions): Don't make the final state too
different: save its reduction (accept) instead of having a state
without any action (no shift or goto, no reduce).
Note: the final state is now a ``regular'' state, i.e., the
parsers now contain `reduce 0' as default reduction.
Nevertheless, since they decide to `accept' when yystate =
final_state, they still will not reduce rule 0.
* src/print.c (print_actions, print_reduction): Adjust.
* src/output.c (action_row): Track reduced rules.
(token_actions): Report rules never reduced.
* tests/conflicts.at, tests/regression.at: Adjust.
This commit is contained in:
Akim Demaille
2002-07-30 11:06:50 +00:00
parent caf23d249c
commit e8832397ea
7 changed files with 68 additions and 30 deletions

View File

@@ -598,6 +598,16 @@ action_row (state_t *state)
}
}
/* Find the rules which are reduced. */
if (!glr_parser)
{
for (i = 0; i < ntokens; i++)
if (actrow[i] < 0 && actrow[i] != ACTION_MIN)
rules[item_number_as_rule_number (actrow[i])].useful = TRUE;
if (default_rule)
default_rule->useful = TRUE;
}
/* If have no default rule, the default is an error.
So replace any action which says "error" with "use default". */
@@ -671,6 +681,7 @@ static void
token_actions (void)
{
state_number_t i;
rule_number_t r;
int nconflict = conflicts_total_count ();
rule_number_t *yydefact = XCALLOC (rule_number_t, nstates);
@@ -678,6 +689,13 @@ token_actions (void)
actrow = XCALLOC (action_t, ntokens);
conflrow = XCALLOC (unsigned int, ntokens);
/* Now that the parser was computed, we can find which rules are
really reduced, and which are not because of SR or RR conflicts.
*/
if (!glr_parser)
for (r = 0; r < nrules; ++r)
rules[r].useful = FALSE;
if (glr_parser)
{
conflict_list = XCALLOC (unsigned int, 1 + 2 * nconflict);
@@ -696,6 +714,17 @@ token_actions (void)
muscle_insert_rule_number_table ("defact", yydefact,
yydefact[0], 1, nstates);
if (!glr_parser)
for (r = 0; r < nrules ; ++r)
if (!rules[r].useful)
{
LOCATION_PRINT (stderr, rules[r].location);
fprintf (stderr, ": %s: %s: ",
_("warning"), _("rule never reduced because of conflicts"));
rule_print (&rules[r], stderr);
}
XFREE (actrow);
XFREE (conflrow);
XFREE (yydefact);