-#include "derives.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.
- */
-state_t *state_table = NULL;
-
-int tokensetsize;
-short *LAruleno;
-unsigned *LA;
-
-short *goto_map;
-short *from_state;
-short *to_state;
-
-extern void berror PARAMS ((const char *));
-
-static int infinity;
-static int ngotos;
-
-/* And for the famous F variable, which name is so descriptive that a
- comment is hardly needed. <grin>. */
-static unsigned *F = NULL;
-#define F(Rule) (F + (Rule) * tokensetsize)
-
-static short **includes;
-static shorts **lookback;
-static short **R;
-static short *INDEX;
-static short *VERTICES;
-static int top;
-
-
-static void
-traverse (int i)
-{
- int j;
- size_t k;
- int height;
- size_t size = F (i + 1) - F(i);
-
- VERTICES[++top] = i;
- INDEX[i] = height = top;
-
- if (R[i])
- for (j = 0; R[i][j] >= 0; ++j)
- {
- if (INDEX[R[i][j]] == 0)
- traverse (R[i][j]);
-
- if (INDEX[i] > INDEX[R[i][j]])
- INDEX[i] = INDEX[R[i][j]];
-
- for (k = 0; k < size; ++k)
- F (i)[k] |= F (R[i][j])[k];
- }
-
- if (INDEX[i] == height)
- for (;;)
- {
- j = VERTICES[top--];
- INDEX[j] = infinity;
-
- if (i == j)
- break;
-
- for (k = 0; k < size; ++k)
- F (i)[k] = F (j)[k];
- }
-}
-
-
-static void
-digraph (short **relation)
-{
- int i;
-
- infinity = ngotos + 2;
- INDEX = XCALLOC (short, ngotos + 1);
- VERTICES = XCALLOC (short, ngotos + 1);
- 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);
-
- XFREE (INDEX);
- XFREE (VERTICES);
-}
-
-
-/*--------------------.
-| Build STATE_TABLE. |
-`--------------------*/
-
-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);
-
- {
- 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;
- }
-}
-
-
-/*------------------------------------------.
-| Return the size of the longest rule RHS. |
-`------------------------------------------*/
-
-static size_t
-maxrhs (void)