- if (INDEX[i] == height)
- {
- for (;;)
- {
- j = VERTICES[top--];
- INDEX[j] = infinity;
-
- if (i == j)
- break;
-
- fp1 = base;
- fp2 = F + j * tokensetsize;
-
- while (fp1 < fp3)
- *fp2++ = *fp1++;
- }
- }
-}
-
-
-static void
-digraph (short **relation)
-{
- int i;
-
- infinity = ngotos + 2;
- INDEX = NEW2 (ngotos + 1, short);
- VERTICES = NEW2 (ngotos + 1, short);
- top = 0;
-
- R = relation;
-
- for (i = 0; i < ngotos; i++)
- INDEX[i] = 0;
-
- for (i = 0; i < ngotos; i++)
- {
- if (INDEX[i] == 0 && R[i])
- traverse (i);
- }
-
- FREE (INDEX);
- FREE (VERTICES);
-}
-
-static void
-set_state_table (void)
-{
- core *sp;
-
- state_table = NEW2 (nstates, core *);
-
- for (sp = first_state; sp; sp = sp->next)
- state_table[sp->number] = sp;
-}
-
-
-static void
-set_accessing_symbol (void)
-{
- core *sp;
-
- accessing_symbol = NEW2 (nstates, short);
-
- for (sp = first_state; sp; sp = sp->next)
- accessing_symbol[sp->number] = sp->accessing_symbol;
-}
-
-
-static void
-set_shift_table (void)
-{
- shifts *sp;
-
- shift_table = NEW2 (nstates, shifts *);
-
- for (sp = first_shift; sp; sp = sp->next)
- shift_table[sp->number] = sp;
-}
-
-
-static void
-set_reduction_table (void)
-{
- reductions *rp;
-
- reduction_table = NEW2 (nstates, reductions *);
-
- for (rp = first_reduction; rp; rp = rp->next)
- reduction_table[rp->number] = rp;
-}
-
-
-static void
-set_maxrhs (void)
-{
- short *itemp;
- int length;
- int max;
-
- length = 0;
- max = 0;
- for (itemp = ritem; *itemp; itemp++)
- {
- if (*itemp > 0)
- {
- length++;
- }
- else
- {
- if (length > max)
- max = length;
- length = 0;
- }
- }
-
- maxrhs = max;
-}
-
-
-static void
-initialize_LA (void)
-{
- int i;
- int j;
- int count;
- reductions *rp;
- shifts *sp;
- short *np;
-
- consistent = NEW2 (nstates, char);
- lookaheads = NEW2 (nstates + 1, short);
-
- count = 0;
- for (i = 0; i < nstates; i++)
- {
- int k;
-
- lookaheads[i] = count;
-
- rp = reduction_table[i];
- sp = shift_table[i];
- if (rp && (rp->nreds > 1
- || (sp && !ISVAR (accessing_symbol[sp->shifts[0]]))))
- count += rp->nreds;
- else
- consistent[i] = 1;
-
- if (sp)
- for (k = 0; k < sp->nshifts; k++)
- {
- if (accessing_symbol[sp->shifts[k]] == error_token_number)
- {
- consistent[i] = 0;
- break;
- }
- }
- }
-
- lookaheads[nstates] = count;
-
- if (count == 0)
- {
- LA = NEW2 (1 * tokensetsize, unsigned);
- LAruleno = NEW2 (1, short);
- lookback = NEW2 (1, shorts *);
- }
- else
- {
- LA = NEW2 (count * tokensetsize, unsigned);
- LAruleno = NEW2 (count, short);
- lookback = NEW2 (count, shorts *);
- }
-
- np = LAruleno;
- for (i = 0; i < nstates; i++)
- {
- if (!consistent[i])
- {
- if ((rp = reduction_table[i]))
- for (j = 0; j < rp->nreds; j++)
- *np++ = rp->rules[j];
- }
- }
-}