- if (!BITISSET(N, start_symbol - ntokens))
- fatals(_("Start symbol %s does not derive any sentence"),
- tags[start_symbol]);
-
- reduce_grammar_tables();
- /* if (verboseflag) {
- fprintf(foutput, "REDUCED GRAMMAR\n\n");
- dump_grammar();
- }
- */
-
- /**/ statisticsflag = FALSE; /* someday getopts should handle this */
- if (statisticsflag == TRUE)
- fprintf(stderr,
- _("reduced %s defines %d terminal%s, %d nonterminal%s\
-, and %d production%s.\n"), infile,
- ntokens, (ntokens == 1 ? "" : "s"),
- nvars, (nvars == 1 ? "" : "s"),
- nrules, (nrules == 1 ? "" : "s"));
-
- done_reducing:
-
- /* Free the global sets used to compute the reduced grammar */
-
- FREE(N);
- FREE(V);
- FREE(P);
-
-}
-\f
-/*
- * Another way to do this would be with a set for each production and then do
- * subset tests against N0, but even for the C grammar the whole reducing
- * process takes only 2 seconds on my 8Mhz AT.
- */
-
-static bool
-useful_production (int i, BSet N0)
-{
- rule r;
- short n;
-
- /*
- * A production is useful if all of the nonterminals in its RHS
- * appear in the set of useful nonterminals.
- */
-
- for (r = &ritem[rrhs[i]]; *r > 0; r++)
- if (ISVAR(n = *r))
- if (!BITISSET(N0, n - ntokens))
- return FALSE;
- return TRUE;
-}
-
-
-/* Remember that rules are 1-origin, symbols are 0-origin. */
-
-static void
-useless_nonterminals (void)
-{
- BSet Np, Ns;
- int i, n;
-
- /*
- * N is set as built. Np is set being built this iteration. P is set
- * of all productions which have a RHS all in N.
- */
-
- Np = NEW2(WORDSIZE(nvars), unsigned);
-
- /*
- * The set being computed is a set of nonterminals which can derive
- * the empty string or strings consisting of all terminals. At each
- * iteration a nonterminal is added to the set if there is a
- * production with that nonterminal as its LHS for which all the
- * nonterminals in its RHS are already in the set. Iterate until the
- * set being computed remains unchanged. Any nonterminals not in the
- * set at that point are useless in that they will never be used in
- * deriving a sentence of the language.
- *
- * This iteration doesn't use any special traversal over the
- * productions. A set is kept of all productions for which all the
- * nonterminals in the RHS are in useful. Only productions not in
- * this set are scanned on each iteration. At the end, this set is
- * saved to be used when finding useful productions: only productions
- * in this set will appear in the final grammar.
- */
-
- n = 0;