* src/lalr.c (initialize_lookaheads): New. Extracted from...

* src/LR0.c (set_state_table): here.
* src/lalr.c (lalr): Call it.
This commit is contained in:
Akim Demaille
2001-12-10 09:10:28 +00:00
parent 0279f8e90c
commit 5edafffd36
3 changed files with 43 additions and 33 deletions

View File

@@ -1,3 +1,9 @@
2001-12-10 Akim Demaille <akim@epita.fr>
* src/lalr.c (initialize_lookaheads): New. Extracted from...
* src/LR0.c (set_state_table): here.
* src/lalr.c (lalr): Call it.
2001-12-10 Akim Demaille <akim@epita.fr>
* src/state.h (shifts): Remove the `number' member: shifts are

View File

@@ -560,39 +560,6 @@ set_state_table (void)
if (!state_table[i]->shifts)
state_table[i]->shifts = shifts_new (0);
}
/* Initializing the lookaheads members. Please note that it must be
performed after having set some of the other members which are
used below. Change with extreme caution. */
{
int i;
int count = 0;
for (i = 0; i < nstates; i++)
{
int k;
reductions *rp = state_table[i]->reductions;
shifts *sp = state_table[i]->shifts;
state_table[i]->lookaheads = count;
if (rp
&& (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0))))
count += rp->nreds;
else
state_table[i]->consistent = 1;
for (k = 0; k < sp->nshifts; k++)
if (SHIFT_IS_ERROR (sp, k))
{
state_table[i]->consistent = 0;
break;
}
}
/* Seems to be needed by conflicts.c. */
state_table[nstates] = STATE_ALLOC (0);
state_table[nstates]->lookaheads = count;
}
}
/*-------------------------------------------------------------------.

View File

@@ -534,11 +534,48 @@ compute_lookaheads (void)
}
/*--------------------------------------.
| Initializing the lookaheads members. |
`--------------------------------------*/
static void
initialize_lookaheads (void)
{
int i;
int count = 0;
for (i = 0; i < nstates; i++)
{
int k;
reductions *rp = state_table[i]->reductions;
shifts *sp = state_table[i]->shifts;
state_table[i]->lookaheads = count;
if (rp
&& (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0))))
count += rp->nreds;
else
state_table[i]->consistent = 1;
for (k = 0; k < sp->nshifts; k++)
if (SHIFT_IS_ERROR (sp, k))
{
state_table[i]->consistent = 0;
break;
}
}
/* Seems to be needed by conflicts.c. */
state_table[nstates] = STATE_ALLOC (0);
state_table[nstates]->lookaheads = count;
}
void
lalr (void)
{
tokensetsize = WORDSIZE (ntokens);
initialize_lookaheads ();
initialize_LA ();
set_goto_map ();
initialize_F ();