- reductions *rp;
-
- reduction_table = XCALLOC (reductions *, nstates);
-
- for (rp = first_reduction; rp; rp = rp->next)
- reduction_table[rp->number] = rp;
+ /* 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);
+
+ {
+ core *sp;
+ for (sp = first_state; sp; sp = sp->next)
+ {
+ state_table[sp->number].state = sp;
+ state_table[sp->number].accessing_symbol = sp->accessing_symbol;
+ }
+ }
+
+ {
+ shifts *sp;
+ for (sp = first_shift; sp; sp = sp->next)
+ state_table[sp->number].shift_table = sp;
+ }
+
+ {
+ reductions *rp;
+ for (rp = first_reduction; rp; rp = rp->next)
+ state_table[rp->number].reduction_table = rp;
+ }
+
+ /* 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].reduction_table;
+ shifts *sp = state_table[i].shift_table;
+
+ state_table[i].lookaheads = count;
+
+ if (rp
+ && (rp->nreds > 1
+ || (sp && !ISVAR (state_table[sp->shifts[0]].accessing_symbol))))
+ count += rp->nreds;
+ else
+ state_table[i].consistent = 1;
+
+ if (sp)
+ for (k = 0; k < sp->nshifts; k++)
+ if (state_table[sp->shifts[k]].accessing_symbol
+ == error_token_number)
+ {
+ state_table[i].consistent = 0;
+ break;
+ }
+ }
+ state_table[nstates].lookaheads = count;
+ }