From 2a73b93df45e9cab008947d3f8290c0c7f4bf500 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 10 Dec 2001 09:09:28 +0000 Subject: [PATCH] * 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. --- ChangeLog | 8 +++++++ src/LR0.c | 64 ++++++++++++++++++++++--------------------------------- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index bcb0024a..34ac5ff8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-12-10 Akim Demaille + + * 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 * src/LR0.c (augment_automaton): Call `insert_eof_shifting_state' diff --git a/src/LR0.c b/src/LR0.c index d21a946f..4beca5be 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -457,67 +457,55 @@ augment_automaton (void) else { state_t *statep = first_state->next; - shifts *sp = first_state->shifts; - shifts *sp1 = NULL; /* The states reached by shifts from FIRST_STATE are numbered 1..(SP->NSHIFTS). Look for one reached by START_SYMBOL. This is typical of `start: start ... ;': there is a state with the item `start: start . ...'. We want to add a `shift on EOF to eof-shifting state here. */ while (statep->accessing_symbol != start_symbol - && statep->number < sp->nshifts) + && statep->number < first_state->shifts->nshifts) statep = statep->next; 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 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; sp = sp->next; } - if (sp && sp->number == statep->number) - { - int i; - shifts *sp2 = shifts_new (sp->nshifts + 1); - sp2->number = statep->number; - statep->shifts = sp2; - sp2->shifts[0] = nstates; - for (i = sp->nshifts; i > 0; i--) - sp2->shifts[i] = sp->shifts[i - 1]; - - /* Patch sp2 into the chain of shifts in place of sp, - following sp1. */ - sp2->next = sp->next; - sp1->next = sp2; - if (sp == last_shift) - last_shift = sp2; - 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; - } + sp2 = shifts_new (sp->nshifts + 1); + sp2->number = statep->number; + statep->shifts = sp2; + sp2->shifts[0] = nstates; + for (i = sp->nshifts; i > 0; i--) + sp2->shifts[i] = sp->shifts[i - 1]; + + /* Patch sp2 into the chain of shifts in place of sp, + following sp1. */ + sp2->next = sp->next; + sp1->next = sp2; + if (sp == last_shift) + last_shift = sp2; + XFREE (sp); + insert_eof_shifting_state (); } else { /* There is no state for `start: start . ...'. */ int i, k; - shifts *sp2; - sp = first_shift; + shifts *sp = first_state->shifts; + shifts *sp2 = NULL; /* There is no next-to-final state as yet. */ /* Add one more shift in first_shift, -- 2.47.2