200 |
Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1)); |
Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1)); |
201 |
|
|
202 |
/* If the start symbol isn't useful, then nothing will be useful. */ |
/* If the start symbol isn't useful, then nothing will be useful. */ |
203 |
if (!BITISSET (N, start_symbol - ntokens)) |
if (BITISSET (N, start_symbol - ntokens)) |
|
goto end_iteration; |
|
|
|
|
|
SETBIT (V, start_symbol); |
|
|
|
|
|
while (1) |
|
204 |
{ |
{ |
205 |
for (i = WORDSIZE (nsyms) - 1; i >= 0; i--) |
SETBIT (V, start_symbol); |
206 |
Vp[i] = V[i]; |
|
207 |
for (i = 1; i <= nrules; i++) |
while (1) |
208 |
{ |
{ |
209 |
if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, rule_table[i].lhs)) |
for (i = WORDSIZE (nsyms) - 1; i >= 0; i--) |
210 |
|
Vp[i] = V[i]; |
211 |
|
for (i = 1; i <= nrules; i++) |
212 |
{ |
{ |
213 |
for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) |
if (!BITISSET (Pp, i) |
214 |
|
&& BITISSET (P, i) |
215 |
|
&& BITISSET (V, rule_table[i].lhs)) |
216 |
{ |
{ |
217 |
if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens)) |
for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) |
218 |
{ |
if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens)) |
219 |
SETBIT (Vp, t); |
SETBIT (Vp, t); |
220 |
} |
SETBIT (Pp, i); |
221 |
} |
} |
|
SETBIT (Pp, i); |
|
222 |
} |
} |
223 |
|
if (bits_equal (V, Vp, WORDSIZE (nsyms))) |
224 |
|
break; |
225 |
|
Vs = Vp; |
226 |
|
Vp = V; |
227 |
|
V = Vs; |
228 |
} |
} |
|
if (bits_equal (V, Vp, WORDSIZE (nsyms))) |
|
|
{ |
|
|
break; |
|
|
} |
|
|
Vs = Vp; |
|
|
Vp = V; |
|
|
V = Vs; |
|
229 |
} |
} |
|
end_iteration: |
|
230 |
|
|
231 |
XFREE (V); |
XFREE (V); |
232 |
V = Vp; |
V = Vp; |
425 |
fprintf (out, _("Useless rules:")); |
fprintf (out, _("Useless rules:")); |
426 |
fprintf (out, "\n\n"); |
fprintf (out, "\n\n"); |
427 |
for (i = 1; i <= nrules; i++) |
for (i = 1; i <= nrules; i++) |
428 |
{ |
if (!BITISSET (P, i)) |
429 |
if (!BITISSET (P, i)) |
{ |
430 |
{ |
fprintf (out, "#%-4d ", i); |
431 |
fprintf (out, "#%-4d ", i); |
fprintf (out, "%s :\t", tags[rule_table[i].lhs]); |
432 |
fprintf (out, "%s :\t", tags[rule_table[i].lhs]); |
for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) |
433 |
for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) |
fprintf (out, " %s", tags[*r]); |
434 |
fprintf (out, " %s", tags[*r]); |
fprintf (out, ";\n"); |
435 |
fprintf (out, ";\n"); |
} |
|
} |
|
|
} |
|
436 |
} |
} |
437 |
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b) |
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b) |
438 |
fprintf (out, "\n\n"); |
fprintf (out, "\n\n"); |
439 |
} |
} |
440 |
|
|
441 |
#if 0 /* XXX currently unused. */ |
#if TRACE |
442 |
static void |
static void |
443 |
dump_grammar (FILE *out) |
dump_grammar (FILE *out) |
444 |
{ |
{ |
445 |
int i; |
int i; |
446 |
rule r; |
rule r; |
447 |
|
|
448 |
|
fprintf (out, "REDUCED GRAMMAR\n\n"); |
449 |
fprintf (out, |
fprintf (out, |
450 |
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n", |
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n", |
451 |
ntokens, nvars, nsyms, nrules, nitems); |
ntokens, nvars, nsyms, nrules, nitems); |
539 |
tags[start_symbol]); |
tags[start_symbol]); |
540 |
|
|
541 |
reduce_grammar_tables (); |
reduce_grammar_tables (); |
542 |
#if 0 |
#if TRACE |
543 |
if (verbose_flag) |
dump_grammar (stderr); |
|
{ |
|
|
fprintf (out, "REDUCED GRAMMAR\n\n"); |
|
|
dump_grammar (); |
|
|
} |
|
544 |
#endif |
#endif |
545 |
|
|
546 |
if (statistics_flag) |
if (statistics_flag) |