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:
Joel E. Denny
2007-05-07 02:56:56 +00:00
parent b09f4f4851
commit 5967f0cf59
10 changed files with 347 additions and 1 deletions

View File

@@ -327,6 +327,16 @@ conflicts_solve (void)
}
void
conflicts_update_state_numbers (state_number old_to_new[],
state_number nstates_old)
{
for (state_number i = 0; i < nstates_old; ++i)
if (old_to_new[i] != nstates_old)
conflicts[old_to_new[i]] = conflicts[i];
}
/*---------------------------------------------.
| Count the number of shift/reduce conflicts. |
`---------------------------------------------*/