Instead of attaching lookaheads and duplicating the rules being

reduced by a state, attach the lookaheads to the reductions.
* src/state.h (state_t): Remove the `lookaheads',
`lookaheads_rule' member.
(reductions_t): Add a `lookaheads' member.
Use a regular array for the `rules'.
* src/state.c (reductions_new): Initialize the lookaheads member
to 0.
(state_rule_lookaheads_print): Adjust.
* src/state.h, src/state.c (state_reductions_find): New.
* src/conflicts.c (resolve_sr_conflict, set_conflicts)
(count_rr_conflicts): Adjust.
* src/lalr.c (LArule): Remove.
(add_lookback_edge): Adjust.
(state_lookaheads_count): New.
(states_lookaheads_initialize): Merge into...
(initialize_LA): this.
(lalr_free): Adjust.
* src/main.c (main): Don't free nullable and derives too early: it
is used by --verbose.
* src/print.c, src/print_graph.c, src/tables.c: Adjust.
This commit is contained in:
Akim Demaille
2002-08-01 18:14:30 +00:00
parent bb0027a9ac
commit cd08e51eda
9 changed files with 228 additions and 240 deletions

View File

@@ -86,28 +86,23 @@ print_core (struct obstack *oout, state_t *state)
obstack_fgrow1 (oout, " %s", symbols[*sp]->tag);
/* Experimental feature: display the lookaheads. */
if ((report_flag & report_lookaheads)
&& state->nlookaheads)
if (report_flag & report_lookaheads)
{
int j, k;
bitset_iterator biter;
int nlookaheads = 0;
/* Find the reduction we are handling. */
reductions_t *reds = state->reductions;
int redno = state_reduction_find (state, &rules[rule]);
/* Look for lookaheads corresponding to this rule. */
for (j = 0; j < state->nlookaheads; ++j)
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule)
nlookaheads++;
if (nlookaheads)
/* Print them if there are. */
if (reds->lookaheads && redno != -1)
{
obstack_sgrow (oout, " [");
for (j = 0; j < state->nlookaheads; ++j)
BITSET_FOR_EACH (biter, state->lookaheads[j], k, 0)
if (state->lookaheads_rule[j]->number == rule)
obstack_fgrow2 (oout, "%s%s",
symbols[k]->tag,
--nlookaheads ? ", " : "");
bitset_iterator biter;
int k;
int not_first = 0;
obstack_sgrow (oout, "[");
BITSET_FOR_EACH (biter, reds->lookaheads[redno], k, 0)
obstack_fgrow2 (oout, "%s%s",
not_first++ ? ", " : "",
symbols[k]->tag);
obstack_sgrow (oout, "]");
}
}