mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 14:23:04 +00:00
If conflict resolution makes states unreachable, remove those states,
report rules that are then unused, and don't report conflicts in those states. * src/conflicts.c, src/conflicts.h (conflicts_update_state_numbers): New global function. * src/lalr.c, src/lalr.h (lalr_update_state_numbers): New global function. * src/main.c (main): After conflict resolution, remove the unreachable states and update all data structures that reference states by number. * src/state.c (state_new): Initialize each state's reachable member to false. (state_mark_reachable_states): New static function. (state_remove_unreachable_states): New global function. * src/state.h (struct state): Add member bool reachable. (state_remove_unreachable_states): Prototype. * tests/conflicts.at (Unreachable States After Conflict Resolution): New test case. * tests/existing.at (GNU pic Grammar): Update test case output now that an unused rule is discovered.
This commit is contained in:
31
src/lalr.c
31
src/lalr.c
@@ -453,6 +453,37 @@ lalr (void)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
lalr_update_state_numbers (state_number old_to_new[], state_number nstates_old)
|
||||
{
|
||||
goto_number ngotos_reachable = 0;
|
||||
symbol_number nonterminal = 0;
|
||||
aver (nsyms == nvars + ntokens);
|
||||
for (goto_number i = 0; i < ngotos; ++i)
|
||||
{
|
||||
while (i == goto_map[nonterminal])
|
||||
goto_map[nonterminal++] = ngotos_reachable;
|
||||
/* If old_to_new[from_state[i]] = nstates_old, remove this goto
|
||||
entry. */
|
||||
if (old_to_new[from_state[i]] != nstates_old)
|
||||
{
|
||||
/* from_state[i] is not removed, so it and thus to_state[i] are
|
||||
reachable, so to_state[i] != nstates_old. */
|
||||
aver (old_to_new[to_state[i]] != nstates_old);
|
||||
from_state[ngotos_reachable] = old_to_new[from_state[i]];
|
||||
to_state[ngotos_reachable] = old_to_new[to_state[i]];
|
||||
++ngotos_reachable;
|
||||
}
|
||||
}
|
||||
while (nonterminal <= nvars)
|
||||
{
|
||||
aver (ngotos == goto_map[nonterminal]);
|
||||
goto_map[nonterminal++] = ngotos_reachable;
|
||||
}
|
||||
ngotos = ngotos_reachable;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
lalr_free (void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user