31 static void set_state_table(
void);
32 static void set_accessing_symbol(
void);
33 static void set_shift_table(
void);
34 static void set_reduction_table(
void);
35 static void set_maxrhs(
void);
36 static void initialize_LA(
void);
37 static void set_goto_map(
void);
38 static void initialize_F(
void);
39 static void build_relations(
void);
40 static void add_lookback_edge(
int stateno,
int ruleno,
int gotono);
41 static short **transpose(
short int **R,
int n);
42 static void compute_FOLLOWS(
void);
43 static void compute_lookaheads(
void);
44 static void digraph(
short **relation);
45 static void traverse(
int i);
51 static short **includes;
55 static short *VERTICES;
65 set_accessing_symbol();
67 set_reduction_table();
86 state_table[sp->
number] = sp;
92 set_accessing_symbol(
void)
104 set_shift_table(
void)
110 shift_table[sp->
number] = sp;
116 set_reduction_table(
void)
122 reduction_table[rp->
number] = rp;
138 for (itemp =
ritem; itemp < item_end; itemp++)
146 if (length > max) max = length;
168 rp = reduction_table[
i];
181 rp = reduction_table[
i];
184 for (j = 0; j < rp->
nreds; j++)
211 for (i = sp->
nshifts - 1; i >= 0; i--)
218 fatal(
"too many gotos");
236 temp_map[
nsyms] = ngotos;
244 for (i = sp->
nshifts - 1; i >= 0; i--)
251 k = temp_map[symbol]++;
278 middle = (low + high) >> 1;
308 F =
NEW2(nwords,
unsigned);
310 reads =
NEW2(ngotos,
short *);
311 edge =
NEW2(ngotos + 1,
short);
315 for (i = 0; i < ngotos; i++)
318 sp = shift_table[stateno];
324 for (j = 0; j < k; j++)
336 edge[nedges++] =
map_goto(stateno, symbol);
341 reads[
i] = rp =
NEW2(nedges + 1,
short);
343 for (j = 0; j < nedges; j++)
357 for (i = 0; i < ngotos; i++)
370 build_relations(
void)
388 short **new_includes;
390 includes =
NEW2(ngotos,
short *);
391 edge =
NEW2(ngotos + 1,
short);
392 states =
NEW2(maxrhs + 1,
short);
394 for (i = 0; i < ngotos; i++)
400 for (rulep =
derives[symbol1]; *rulep >= 0; rulep++)
406 for (rp =
ritem +
rrhs[*rulep]; *rp >= 0; rp++)
409 sp = shift_table[stateno];
412 for (j = 0; j < k; j++)
414 stateno = sp->
shift[j];
418 states[length++] = stateno;
421 add_lookback_edge(stateno, *rulep, i);
431 stateno = states[--length];
432 edge[nedges++] =
map_goto(stateno, *rp);
433 if (
nullable[*rp] && length > 0) done = 0;
440 includes[
i] = shortp =
NEW2(nedges + 1,
short);
441 for (j = 0; j < nedges; j++)
447 new_includes = transpose(includes, ngotos);
449 for (i = 0; i < ngotos; i++)
455 includes = new_includes;
463 add_lookback_edge(
int stateno,
int ruleno,
int gotono)
472 while (!found && i < k)
482 sp->
next = lookback[
i];
490 transpose(
short int **R,
int n)
499 nedges =
NEW2(n,
short);
501 for (i = 0; i < n; i++)
511 new_R =
NEW2(n,
short *);
512 temp_R =
NEW2(n,
short *);
514 for (i = 0; i < n; i++)
519 sp =
NEW2(k + 1,
short);
528 for (i = 0; i < n; i++)
534 *temp_R[*sp++]++ =
i;
546 compute_FOLLOWS(
void)
553 compute_lookaheads(
void)
556 unsigned *fp1, *fp2, *fp3;
562 for (i = 0; i < n; i++)
565 for (sp = lookback[i]; sp; sp = sp->
next)
568 fp2 = F + tokensetsize * sp->
value;
575 for (i = 0; i < n; i++)
576 for (sp = lookback[i]; sp; sp =
next)
588 digraph(
short **relation)
592 infinity = ngotos + 2;
593 INDEX =
NEW2(ngotos + 1,
short);
594 VERTICES =
NEW2(ngotos + 1,
short);
599 for (i = 0; i < ngotos; i++)
602 for (i = 0; i < ngotos; i++)
604 if (INDEX[i] == 0 && R[i])
627 INDEX[
i] = height = top;
635 while ((j = *rp++) >= 0)
640 if (INDEX[i] > INDEX[j])
651 if (INDEX[i] == height)
reductions ** reduction_table
void fatal(char *msg) NORETURN
#define assert(exp)
Declare that a condition should be true.
int map_goto(int state, int symbol)
reductions * first_reduction