227 |
static void |
static void |
228 |
reduce_grammar_tables (void) |
reduce_grammar_tables (void) |
229 |
{ |
{ |
230 |
/* Flag useless productions. */ |
/* Report and flag useless productions. */ |
231 |
{ |
{ |
232 |
int pn; |
int r; |
233 |
for (pn = 1; pn < nrules + 1; pn++) |
for (r = 1; r < nrules + 1; r++) |
234 |
rules[pn].useful = bitset_test (P, pn); |
{ |
235 |
|
rules[r].useful = bitset_test (P, r); |
236 |
|
if (!rules[r].useful) |
237 |
|
{ |
238 |
|
LOCATION_PRINT (stderr, rules[r].location); |
239 |
|
fprintf (stderr, ": %s: %s: ", _("warning"), _("useless rule")); |
240 |
|
rule_print (&rules[r], stderr); |
241 |
|
} |
242 |
|
} |
243 |
} |
} |
244 |
|
|
245 |
/* Map the nonterminals to their new index: useful first, useless |
/* Map the nonterminals to their new index: useful first, useless |
298 |
nontermmap[i] = n++; |
nontermmap[i] = n++; |
299 |
for (i = ntokens; i < nsyms; i++) |
for (i = ntokens; i < nsyms; i++) |
300 |
if (!bitset_test (V, i)) |
if (!bitset_test (V, i)) |
301 |
nontermmap[i] = n++; |
{ |
302 |
|
nontermmap[i] = n++; |
303 |
|
LOCATION_PRINT (stderr, symbols[i]->location); |
304 |
|
fprintf (stderr, ": %s: %s: %s\n", |
305 |
|
_("warning"), _("useless nonterminal"), |
306 |
|
symbol_tag_get (symbols[i])); |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
/* Shuffle elements of tables indexed by symbol number. */ |
/* Shuffle elements of tables indexed by symbol number. */ |
351 |
int i; |
int i; |
352 |
fprintf (out, "%s\n\n", _("Useless nonterminals:")); |
fprintf (out, "%s\n\n", _("Useless nonterminals:")); |
353 |
for (i = 0; i < nuseless_nonterminals; ++i) |
for (i = 0; i < nuseless_nonterminals; ++i) |
354 |
fprintf (out, " %s\n", quotearg_style (escape_quoting_style, |
fprintf (out, " %s\n", symbol_tag_get (symbols[nsyms + i])); |
|
symbols[nsyms + i]->tag)); |
|
355 |
fputs ("\n\n", out); |
fputs ("\n\n", out); |
356 |
} |
} |
357 |
|
|
364 |
if (!b) |
if (!b) |
365 |
fprintf (out, "%s\n\n", _("Terminals which are not used:")); |
fprintf (out, "%s\n\n", _("Terminals which are not used:")); |
366 |
b = TRUE; |
b = TRUE; |
367 |
fprintf (out, " %s\n", quotearg_style (escape_quoting_style, |
fprintf (out, " %s\n", symbol_tag_get (symbols[i])); |
|
symbols[i]->tag)); |
|
368 |
} |
} |
369 |
if (b) |
if (b) |
370 |
fputs ("\n\n", out); |
fputs ("\n\n", out); |
378 |
{ |
{ |
379 |
item_number_t *r; |
item_number_t *r; |
380 |
fprintf (out, "#%-4d ", rules[i].user_number - 1); |
fprintf (out, "#%-4d ", rules[i].user_number - 1); |
381 |
fprintf (out, "%s:", quotearg_style (escape_quoting_style, |
fprintf (out, "%s:", symbol_tag_get (rules[i].lhs)); |
|
rules[i].lhs->tag)); |
|
382 |
for (r = rules[i].rhs; *r >= 0; r++) |
for (r = rules[i].rhs; *r >= 0; r++) |
383 |
fprintf (out, " %s", quotearg_style (escape_quoting_style, |
fprintf (out, " %s", symbol_tag_get (symbols[*r])); |
|
symbols[*r]->tag)); |
|
384 |
fputs (";\n", out); |
fputs (";\n", out); |
385 |
} |
} |
386 |
fputs ("\n\n", out); |
fputs ("\n\n", out); |
404 |
nuseless_productions), |
nuseless_productions), |
405 |
nuseless_productions); |
nuseless_productions); |
406 |
|
|
407 |
fprintf (stderr, _("%s contains "), infile); |
fprintf (stderr, "%s: %s: ", infile, _("warning")); |
408 |
|
|
409 |
if (nuseless_nonterminals > 0) |
if (nuseless_nonterminals > 0) |
410 |
fprintf (stderr, ngettext ("%d useless nonterminal", |
fprintf (stderr, ngettext ("%d useless nonterminal", |
447 |
|
|
448 |
if (!bitset_test (N, axiom->number - ntokens)) |
if (!bitset_test (N, axiom->number - ntokens)) |
449 |
fatal (_("Start symbol %s does not derive any sentence"), |
fatal (_("Start symbol %s does not derive any sentence"), |
450 |
quotearg_style (escape_quoting_style, symbols[axiom->number]->tag)); |
symbol_tag_get (symbols[axiom->number])); |
451 |
|
|
452 |
/* First reduce the nonterminals, as they renumber themselves in the |
/* First reduce the nonterminals, as they renumber themselves in the |
453 |
whole grammar. If you change the order, nonterms would be |
whole grammar. If you change the order, nonterms would be |