+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
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;
#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;
short *np;
reductions *rp;
- size_t nLA = state_table[nstates]->lookaheadsp;
+ /* Avoid having to special case 0. */
if (!nLA)
nLA = 1;
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);
}
/* Free LOOKBACK. */
- for (i = 0; i < state_table[nstates]->lookaheadsp; i++)
+ for (i = 0; i < nLA; i++)
LIST_FREE (shorts, lookback[i]);
XFREE (lookback);
initialize_lookaheads (void)
{
int i;
- int count = 0;
+ nLA = 0;
for (i = 0; i < nstates; i++)
{
int k;
}
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