All the hacks using a final pseudo state are now useless.

* src/LR0.c (set_state_table): state_table holds exactly nstates.
* src/lalr.c (nLA): New.
(initialize_LA, compute_lookaheads, initialize_lookaheads): Use it
instead of lookaheadsp from the pseudo state (nstate + 1).
This commit is contained in:
Akim Demaille
2001-12-27 18:05:30 +00:00
parent f9507c28ae
commit d200e455d0
3 changed files with 19 additions and 18 deletions

View File

@@ -1,3 +1,12 @@
2001-12-27 Akim Demaille <akim@epita.fr>
All the hacks using a final pseudo state are now useless.
* src/LR0.c (set_state_table): state_table holds exactly nstates.
* src/lalr.c (nLA): New.
(initialize_LA, compute_lookaheads, initialize_lookaheads): Use it
instead of lookaheadsp from the pseudo state (nstate + 1).
2001-12-27 Akim Demaille <akim@epita.fr>
* src/output.c (action_row, token_actions): Use a state_t instead

View File

@@ -541,10 +541,7 @@ save_reductions (void)
static void
set_state_table (void)
{
/* NSTATES + 1 because lookahead for the pseudo state number NSTATES
might be used (see conflicts.c). It is too opaque for me to
provide a probably less hacky implementation. --akim */
state_table = XCALLOC (state_t *, nstates + 1);
state_table = XCALLOC (state_t *, nstates);
{
state_t *sp;

View File

@@ -33,14 +33,13 @@
#include "derives.h"
#include "getargs.h"
/* All the decorated states, indexed by the state number. Warning:
there is a state_TABLE in LR0.c, but it is different and static.
*/
/* All the decorated states, indexed by the state number. */
state_t **state_table = NULL;
int tokensetsize;
short *LAruleno;
unsigned *LA;
size_t nLA;
static int ngotos;
short *goto_map;
@@ -140,7 +139,7 @@ initialize_LA (void)
short *np;
reductions *rp;
size_t nLA = state_table[nstates]->lookaheadsp;
/* Avoid having to special case 0. */
if (!nLA)
nLA = 1;
@@ -504,10 +503,10 @@ compute_FOLLOWS (void)
static void
compute_lookaheads (void)
{
int i;
size_t i;
shorts *sp;
for (i = 0; i < state_table[nstates]->lookaheadsp; i++)
for (i = 0; i < nLA; i++)
for (sp = lookback[i]; sp; sp = sp->next)
{
int size = LA (i + 1) - LA (i);
@@ -517,7 +516,7 @@ compute_lookaheads (void)
}
/* Free LOOKBACK. */
for (i = 0; i < state_table[nstates]->lookaheadsp; i++)
for (i = 0; i < nLA; i++)
LIST_FREE (shorts, lookback[i]);
XFREE (lookback);
@@ -533,7 +532,7 @@ static void
initialize_lookaheads (void)
{
int i;
int count = 0;
nLA = 0;
for (i = 0; i < nstates; i++)
{
int k;
@@ -555,13 +554,9 @@ initialize_lookaheads (void)
}
state_table[i]->nlookaheads = nlookaheads;
state_table[i]->lookaheadsp = count;
count += nlookaheads;
state_table[i]->lookaheadsp = nLA;
nLA += nlookaheads;
}
/* Seems to be needed by conflicts.c. */
state_table[nstates] = STATE_ALLOC (0);
state_table[nstates]->lookaheadsp = count;
}
void