* src/LR0.c (augment_automaton): Better variable locality.

Remove an impossible branch: if there is a state corresponding to
the start symbol being shifted, then there is shift for the start
symbol from the initial state.
This commit is contained in:
Akim Demaille
2001-12-10 09:09:28 +00:00
parent 74392f6a54
commit 2a73b93df4
2 changed files with 32 additions and 36 deletions

View File

@@ -1,3 +1,11 @@
2001-12-10 Akim Demaille <akim@epita.fr>
* src/LR0.c (augment_automaton): Better variable locality.
Remove an impossible branch: if there is a state corresponding to
the start symbol being shifted, then there is shift for the start
symbol from the initial state.
2001-12-10 Akim Demaille <akim@epita.fr> 2001-12-10 Akim Demaille <akim@epita.fr>
* src/LR0.c (augment_automaton): Call `insert_eof_shifting_state' * src/LR0.c (augment_automaton): Call `insert_eof_shifting_state'

View File

@@ -457,32 +457,33 @@ augment_automaton (void)
else else
{ {
state_t *statep = first_state->next; state_t *statep = first_state->next;
shifts *sp = first_state->shifts;
shifts *sp1 = NULL;
/* The states reached by shifts from FIRST_STATE are numbered /* The states reached by shifts from FIRST_STATE are numbered
1..(SP->NSHIFTS). Look for one reached by START_SYMBOL. 1..(SP->NSHIFTS). Look for one reached by START_SYMBOL.
This is typical of `start: start ... ;': there is a state This is typical of `start: start ... ;': there is a state
with the item `start: start . ...'. We want to add a `shift with the item `start: start . ...'. We want to add a `shift
on EOF to eof-shifting state here. */ on EOF to eof-shifting state here. */
while (statep->accessing_symbol != start_symbol while (statep->accessing_symbol != start_symbol
&& statep->number < sp->nshifts) && statep->number < first_state->shifts->nshifts)
statep = statep->next; statep = statep->next;
if (statep->accessing_symbol == start_symbol) if (statep->accessing_symbol == start_symbol)
{ {
/* We already have a next-to-final state, i.e., for `start: /* We already have STATEP, a next-to-final state for `start:
start . ...'. Make sure it has a shift to what will be start . ...'. Make sure it has a shift to what will be
the final state. */ the final state. */
while (sp && sp->number < statep->number) int i;
/* Find the shift that leads to this STATEP. */
shifts *sp = first_state->shifts;
shifts *sp1 = NULL;
shifts *sp2 = NULL;
while (sp->number < statep->number)
{ {
sp1 = sp; sp1 = sp;
sp = sp->next; sp = sp->next;
} }
if (sp && sp->number == statep->number) sp2 = shifts_new (sp->nshifts + 1);
{
int i;
shifts *sp2 = shifts_new (sp->nshifts + 1);
sp2->number = statep->number; sp2->number = statep->number;
statep->shifts = sp2; statep->shifts = sp2;
sp2->shifts[0] = nstates; sp2->shifts[0] = nstates;
@@ -496,28 +497,15 @@ augment_automaton (void)
if (sp == last_shift) if (sp == last_shift)
last_shift = sp2; last_shift = sp2;
XFREE (sp); XFREE (sp);
}
else
{
shifts *sp2 = shifts_new (1);
sp2->number = statep->number;
statep->shifts = sp2;
sp2->shifts[0] = nstates;
/* Patch sp2 into the chain of shifts between sp1 and sp. */
sp2->next = sp;
sp1->next = sp2;
if (sp == 0)
last_shift = sp2;
}
insert_eof_shifting_state (); insert_eof_shifting_state ();
} }
else else
{ {
/* There is no state for `start: start . ...'. */ /* There is no state for `start: start . ...'. */
int i, k; int i, k;
shifts *sp2; shifts *sp = first_state->shifts;
sp = first_shift; shifts *sp2 = NULL;
/* There is no next-to-final state as yet. */ /* There is no next-to-final state as yet. */
/* Add one more shift in first_shift, /* Add one more shift in first_shift,