mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 17:53:02 +00:00
* src/LR0.c (augment_automaton): Formatting changes.
Better variable locality.
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/LR0.c (augment_automaton): Formatting changes.
|
||||||
|
Better variable locality.
|
||||||
|
|
||||||
|
|
||||||
2001-12-05 Akim Demaille <akim@epita.fr>
|
2001-12-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/lalr.c (matrix_print): New.
|
* src/lalr.c (matrix_print): New.
|
||||||
|
|||||||
63
src/LR0.c
63
src/LR0.c
@@ -387,44 +387,53 @@ insert_start_shift (void)
|
|||||||
static void
|
static void
|
||||||
augment_automaton (void)
|
augment_automaton (void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int k;
|
|
||||||
core *statep;
|
core *statep;
|
||||||
shifts *sp;
|
shifts *sp;
|
||||||
shifts *sp2;
|
|
||||||
shifts *sp1 = NULL;
|
shifts *sp1 = NULL;
|
||||||
|
|
||||||
sp = first_shift;
|
sp = first_shift;
|
||||||
|
|
||||||
if (sp)
|
if (!sp)
|
||||||
{
|
{
|
||||||
if (sp->number == 0)
|
/* There are no shifts for any state. Make one shift, from the
|
||||||
|
initial state to the next-to-final state. */
|
||||||
|
|
||||||
|
sp = shifts_new (1);
|
||||||
|
sp->shifts[0] = nstates;
|
||||||
|
|
||||||
|
/* Initialize the chain of shifts with sp. */
|
||||||
|
first_shift = sp;
|
||||||
|
last_shift = sp;
|
||||||
|
|
||||||
|
/* Create the next-to-final state, with shift to
|
||||||
|
what will be the final state. */
|
||||||
|
insert_start_shift ();
|
||||||
|
}
|
||||||
|
else if (sp->number == 0)
|
||||||
{
|
{
|
||||||
k = sp->nshifts;
|
|
||||||
statep = first_state->next;
|
statep = first_state->next;
|
||||||
|
|
||||||
/* The states reached by shifts from first_state are numbered 1...K.
|
/* The states reached by shifts from FIRST_STATE are numbered
|
||||||
Look for one reached by start_symbol. */
|
1..(SP->NSHIFTS). Look for one reached by START_SYMBOL. */
|
||||||
while (statep->accessing_symbol < start_symbol
|
while (statep->accessing_symbol < start_symbol
|
||||||
&& statep->number < k)
|
&& statep->number < sp->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.
|
/* We already have a next-to-final state.
|
||||||
Make sure it has a shift to what will be the final state. */
|
Make sure it has a shift to what will be the final state. */
|
||||||
k = statep->number;
|
while (sp && sp->number < statep->number)
|
||||||
|
|
||||||
while (sp && sp->number < k)
|
|
||||||
{
|
{
|
||||||
sp1 = sp;
|
sp1 = sp;
|
||||||
sp = sp->next;
|
sp = sp->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sp && sp->number == k)
|
if (sp && sp->number == statep->number)
|
||||||
{
|
{
|
||||||
sp2 = shifts_new (sp->nshifts + 1);
|
int i;
|
||||||
sp2->number = k;
|
shifts *sp2 = shifts_new (sp->nshifts + 1);
|
||||||
|
sp2->number = statep->number;
|
||||||
sp2->shifts[0] = nstates;
|
sp2->shifts[0] = nstates;
|
||||||
for (i = sp->nshifts; i > 0; i--)
|
for (i = sp->nshifts; i > 0; i--)
|
||||||
sp2->shifts[i] = sp->shifts[i - 1];
|
sp2->shifts[i] = sp->shifts[i - 1];
|
||||||
@@ -439,8 +448,8 @@ augment_automaton (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sp2 = shifts_new (1);
|
shifts *sp2 = shifts_new (1);
|
||||||
sp2->number = k;
|
sp2->number = statep->number;
|
||||||
sp2->shifts[0] = nstates;
|
sp2->shifts[0] = nstates;
|
||||||
|
|
||||||
/* Patch sp2 into the chain of shifts between sp1 and sp. */
|
/* Patch sp2 into the chain of shifts between sp1 and sp. */
|
||||||
@@ -452,6 +461,9 @@ augment_automaton (void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
int i, k;
|
||||||
|
shifts *sp2;
|
||||||
|
|
||||||
/* 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,
|
||||||
going to the next-to-final state (yet to be made). */
|
going to the next-to-final state (yet to be made). */
|
||||||
@@ -496,23 +508,6 @@ augment_automaton (void)
|
|||||||
sp->next = first_shift;
|
sp->next = first_shift;
|
||||||
first_shift = sp;
|
first_shift = sp;
|
||||||
|
|
||||||
/* Create the next-to-final state, with shift to
|
|
||||||
what will be the final state. */
|
|
||||||
insert_start_shift ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* There are no shifts for any state.
|
|
||||||
Make one shift, from the initial state to the next-to-final state. */
|
|
||||||
|
|
||||||
sp = shifts_new (1);
|
|
||||||
sp->shifts[0] = nstates;
|
|
||||||
|
|
||||||
/* Initialize the chain of shifts with sp. */
|
|
||||||
first_shift = sp;
|
|
||||||
last_shift = sp;
|
|
||||||
|
|
||||||
/* Create the next-to-final state, with shift to
|
/* Create the next-to-final state, with shift to
|
||||||
what will be the final state. */
|
what will be the final state. */
|
||||||
insert_start_shift ();
|
insert_start_shift ();
|
||||||
|
|||||||
Reference in New Issue
Block a user