35 register short *itemp;
36 register short *item_end;
41 register short *symbol_count;
47 for (itemp =
ritem; itemp < item_end; itemp++)
53 symbol_count[symbol]++;
62 for (i = 0; i <
nsyms; i++)
65 count += symbol_count[i];
66 if (max < symbol_count[i])
67 max = symbol_count[i];
91 fprintf(stderr,
"Entering append_states()\n");
144 this_state = this_state->
next;
158 register short *isp1;
159 register short *isp2;
160 register short *iend;
166 fprintf(stderr,
"Entering get_state(%d)\n", symbol);
174 assert(0 <= key && key <
nitems);
187 while (found && isp1 < iend)
189 if (*isp1++ != *isp2++)
221 register short *start_derives;
225 for (i = 0; start_derives[i] >= 0; ++i)
237 for (i = 0; start_derives[i] >= 0; ++i)
240 first_state = last_state = this_state = p;
248 register int shiftcount;
253 for (i = 0; i <
nsyms; i++)
287 register short *isp1;
288 register short *isp2;
289 register short *iend;
292 fprintf(stderr,
"Entering new_state(%d)\n", symbol);
296 fatal(
"too many states");
311 last_state->
next = p;
329 for (p = first_state; p; ++k, p = p->
next)
332 printf(
"state %d, number = %d, accessing symbol = %s\n",
335 for (i = 0; i < n; ++i)
337 itemno = p->items[i];
338 printf(
"%4d ", itemno);
340 while (
ritem[j] >= 0) ++j;
346 while (ritem[j] >= 0)
361 for (i = 0; i <
nitems; ++i)
362 printf(
"ritem[%d] = %d\n", i,
ritem[i]);
371 for (i = 0; i <
nrules; ++i)
372 printf(
"rrhs[%d] = %d\n", i,
rrhs[i]);
384 for (p = first_shift; p; ++k, p = p->
next)
387 printf(
"shift %d, number = %d, nshifts = %d\n", k, p->number,
390 for (i = 0; i < j; ++i)
391 printf(
"\t%d\n", p->shift[i]);
401 register short *send;
404 (
nshifts - 1) *
sizeof(short)));
418 last_shift->
next = p;
438 register short *rend;
453 (count - 1) *
sizeof(short)));
467 last_reduction->
next = p;
483 register short *rules;
492 for (i = 0; i <
nrules; i++)
521 printf(
"\nDERIVES\n\n");
526 for (sp =
derives[i]; *sp >= 0; sp++)
547 for (i = 0; i <
nsyms; ++i)
554 for (i = 1; i <
nitems; i++)
557 while ((j =
ritem[i]) >= 0)
576 for (i = 0; i <
nsyms; i++)
static short ** kernel_end
struct reductions reductions
short * rlhs
List of left-hand sides of all rules.
static short * kernel_items
closure(short *nucleus, int n)
reductions * first_reduction
done(int k)
Shutdown function.
static reductions * last_reduction
unsigned * ruleset
Bitset of closure items for the current state.
int nrules
The number of rules in the grammar.
static short * shift_symbol
set_first_derives()
Populates first_derives, the matrix of closure productions.
int nvars
The number of variables (non-terminals) in the grammar.
int nsyms
The number of symbols (terminals + non-terminals) in the grammar.
short * rrhs
List of right-hand sides of all rules.
short * ritem
Representation of all productions (and items)
short ** derives
List of rules that derive each non-terminal.
int start_symbol
Index of the starting symbol of the grammar.
char ** symbol_name
Array of symbol names.
static short ** kernel_base
static shifts * last_shift