X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/b2ed6e5826e772162719db595446b2c58e4ac5d6..eeeb962b:/src/reduce.c diff --git a/src/reduce.c b/src/reduce.c index 71448410..a95b4bbd 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -200,38 +200,33 @@ inaccessable_symbols (void) Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1)); /* If the start symbol isn't useful, then nothing will be useful. */ - if (!BITISSET (N, start_symbol - ntokens)) - goto end_iteration; - - SETBIT (V, start_symbol); - - while (1) + if (BITISSET (N, start_symbol - ntokens)) { - for (i = WORDSIZE (nsyms) - 1; i >= 0; i--) - Vp[i] = V[i]; - for (i = 1; i <= nrules; i++) + SETBIT (V, start_symbol); + + while (1) { - if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, rule_table[i].lhs)) + for (i = WORDSIZE (nsyms) - 1; i >= 0; i--) + Vp[i] = V[i]; + for (i = 1; i <= nrules; i++) { - for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) + if (!BITISSET (Pp, i) + && BITISSET (P, i) + && BITISSET (V, rule_table[i].lhs)) { - if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens)) - { + for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) + if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens)) SETBIT (Vp, t); - } + SETBIT (Pp, i); } - SETBIT (Pp, i); } + if (bits_equal (V, Vp, WORDSIZE (nsyms))) + break; + Vs = Vp; + Vp = V; + V = Vs; } - if (bits_equal (V, Vp, WORDSIZE (nsyms))) - { - break; - } - Vs = Vp; - Vp = V; - V = Vs; } -end_iteration: XFREE (V); V = Vp; @@ -255,8 +250,8 @@ end_iteration: /* A token that was used in %prec should not be warned about. */ for (i = 1; i < nrules; i++) - if (rprecsym[i] != 0) - SETBIT (V1, rprecsym[i]); + if (rule_table[i].precsym != 0) + SETBIT (V1, rule_table[i].precsym); } static void @@ -281,8 +276,8 @@ reduce_grammar_tables (void) { rule_table[np].lhs = rule_table[pn].lhs; rline[np] = rline[pn]; - rprec[np] = rprec[pn]; - rassoc[np] = rassoc[pn]; + rule_table[np].prec = rule_table[pn].prec; + rule_table[np].assoc = rule_table[pn].assoc; rule_table[np].rhs = rule_table[pn].rhs; if (rule_table[np].rhs != ni) { @@ -370,9 +365,9 @@ reduce_grammar_tables (void) /* Ignore the rules disabled above. */ if (rule_table[i].lhs >= 0) rule_table[i].lhs = nontermmap[rule_table[i].lhs]; - if (ISVAR (rprecsym[i])) + if (ISVAR (rule_table[i].precsym)) /* Can this happen? */ - rprecsym[i] = nontermmap[rprecsym[i]]; + rule_table[i].precsym = nontermmap[rule_table[i].precsym]; } for (r = ritem; *r; r++) @@ -430,28 +425,26 @@ reduce_output (FILE *out) fprintf (out, _("Useless rules:")); fprintf (out, "\n\n"); for (i = 1; i <= nrules; i++) - { - if (!BITISSET (P, i)) - { - fprintf (out, "#%-4d ", i); - fprintf (out, "%s :\t", tags[rule_table[i].lhs]); - for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) - fprintf (out, " %s", tags[*r]); - fprintf (out, ";\n"); - } - } + if (!BITISSET (P, i)) + { + fprintf (out, "#%-4d ", i); + fprintf (out, "%s :\t", tags[rule_table[i].lhs]); + for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++) + fprintf (out, " %s", tags[*r]); + fprintf (out, ";\n"); + } } if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b) fprintf (out, "\n\n"); } -#if 0 /* XXX currently unused. */ static void dump_grammar (FILE *out) { int i; rule r; + fprintf (out, "REDUCED GRAMMAR\n\n"); fprintf (out, "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n", ntokens, nvars, nsyms, nrules, nitems); @@ -464,7 +457,11 @@ dump_grammar (FILE *out) for (i = 1; i <= nrules; i++) { fprintf (out, "%-5d(%5d%5d)%5d : (@%-5d)", - i, rprec[i], rassoc[i], rule_table[i].lhs, rule_table[i].rhs); + i, + rule_table[i].prec, + rule_table[i].assoc, + rule_table[i].lhs, + rule_table[i].rhs); for (r = &ritem[rule_table[i].rhs]; *r > 0; r++) fprintf (out, "%5d", *r); fprintf (out, " [%d]\n", -(*r)); @@ -480,7 +477,6 @@ dump_grammar (FILE *out) } fprintf (out, "\n\n"); } -#endif @@ -541,24 +537,15 @@ reduce_grammar (void) tags[start_symbol]); reduce_grammar_tables (); -#if 0 - if (verbose_flag) + + if (trace_flag) { - fprintf (out, "REDUCED GRAMMAR\n\n"); - dump_grammar (); + dump_grammar (stderr); + + fprintf (stderr, "reduced %s defines %d terminals, %d nonterminals\ +, and %d productions.\n", + infile, ntokens, nvars, nrules); } -#endif - - if (statistics_flag) - 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")); }