-#include "machine.h"
-#include "types.h"
-#include "state.h"
-#include "alloc.h"
-#include "gram.h"
-
-
-extern short **derives;
-extern char *nullable;
-
-
-int tokensetsize;
-short *lookaheads;
-short *LAruleno;
-unsigned *LA;
-short *accessing_symbol;
-char *consistent;
-core **state_table;
-shifts **shift_table;
-reductions **reduction_table;
-short *goto_map;
-short *from_state;
-short *to_state;
-
-short **transpose();
-void set_state_table();
-void set_accessing_symbol();
-void set_shift_table();
-void set_reduction_table();
-void set_maxrhs();
-void initialize_LA();
-void set_goto_map();
-void initialize_F();
-void build_relations();
-void add_lookback_edge();
-void compute_FOLLOWS();
-void compute_lookaheads();
-void digraph();
-void traverse();
-
-extern void toomany();
-extern void berror();
-
-static int infinity;
-static int maxrhs;
-static int ngotos;
-static unsigned *F;
-static short **includes;
-static shorts **lookback;
-static short **R;
-static short *INDEX;
-static short *VERTICES;
-static int top;
-
-
-void
-lalr()
-{
- tokensetsize = WORDSIZE(ntokens);
-
- set_state_table();
- set_accessing_symbol();
- set_shift_table();
- set_reduction_table();
- set_maxrhs();
- initialize_LA();
- set_goto_map();
- initialize_F();
- build_relations();
- compute_FOLLOWS();
- compute_lookaheads();
-}
-
-
-void
-set_state_table()
-{
- register core *sp;
-
- state_table = NEW2(nstates, core *);
-
- for (sp = first_state; sp; sp = sp->next)
- state_table[sp->number] = sp;
-}
-
-
-void
-set_accessing_symbol()
-{
- register core *sp;
-
- accessing_symbol = NEW2(nstates, short);
-
- for (sp = first_state; sp; sp = sp->next)
- accessing_symbol[sp->number] = sp->accessing_symbol;
-}
-
-
-void
-set_shift_table()
-{
- register shifts *sp;
-
- shift_table = NEW2(nstates, shifts *);
-
- for (sp = first_shift; sp; sp = sp->next)
- shift_table[sp->number] = sp;
-}
-
-
-void
-set_reduction_table()
-{
- register reductions *rp;
-
- reduction_table = NEW2(nstates, reductions *);
-
- for (rp = first_reduction; rp; rp = rp->next)
- reduction_table[rp->number] = rp;
-}
-
-
-void
-set_maxrhs()
-{
- register short *itemp;
- register int length;
- register 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;
-}