X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/4bc30f78dc54b245896dd04724019b9b767a7b33..d2d1b42b0730316f4f70eb416dcc767ffaaa2019:/src/print.c?ds=sidebyside diff --git a/src/print.c b/src/print.c index 2c2b8420..977be596 100644 --- a/src/print.c +++ b/src/print.c @@ -87,16 +87,10 @@ print_actions (FILE *out, int state) { int i; int k; - int state1; - int symbol; - shifts *shiftp; - errs *errp; - reductions *redp; - int rule; - shiftp = state_table[state].shift_table; - redp = state_table[state].reduction_table; - errp = err_table[state]; + shifts *shiftp = state_table[state].shift_table; + reductions *redp = state_table[state].reduction_table; + errs *errp = err_table[state]; if (!shiftp && !redp) { @@ -113,9 +107,10 @@ print_actions (FILE *out, int state) for (i = 0; i < k; i++) { - if (!shiftp->shifts[i]) + int symbol; + int state1 = shiftp->shifts[i]; + if (!state1) continue; - state1 = shiftp->shifts[i]; symbol = state_table[state1].accessing_symbol; /* The following line used to be turned off. */ if (ISVAR (symbol)) @@ -140,15 +135,12 @@ print_actions (FILE *out, int state) if (errp) { - int j, nerrs; - - nerrs = errp->nerrs; - - for (j = 0; j < nerrs; j++) + int j; + for (j = 0; j < errp->nerrs; j++) { - if (!errp->errs[j]) + int symbol = errp->errs[j]; + if (!symbol) continue; - symbol = errp->errs[j]; fprintf (out, _(" %-4s\terror (nonassociative)\n"), tags[symbol]); } @@ -159,8 +151,8 @@ print_actions (FILE *out, int state) if (state_table[state].consistent && redp) { - rule = redp->rules[0]; - symbol = rule_table[rule].lhs; + int rule = redp->rules[0]; + int symbol = rule_table[rule].lhs; fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"), rule, tags[symbol]); } @@ -173,9 +165,10 @@ print_actions (FILE *out, int state) { for (; i < k; i++) { - if (!shiftp->shifts[i]) + int symbol; + int state1 = shiftp->shifts[i]; + if (!state1) continue; - state1 = shiftp->shifts[i]; symbol = state_table[state1].accessing_symbol; fprintf (out, _(" %-4s\tgo to state %d\n"), tags[symbol], state1); @@ -188,11 +181,11 @@ print_actions (FILE *out, int state) static void print_state (FILE *out, int state) { - fputs ("\n\n", out); fprintf (out, _("state %d"), state); fputs ("\n\n", out); print_core (out, state); print_actions (out, state); + fputs ("\n\n", out); } /*-----------------------------------------. @@ -219,23 +212,27 @@ print_grammar (FILE *out) int column = 0; /* rule # : LHS -> RHS */ - fprintf (out, "\n%s\n\n", _("Grammar")); + fprintf (out, "%s\n\n", _("Grammar")); + fprintf (out, " %s\n", _("Number, Line, Rule")); for (i = 1; i <= nrules; i++) /* Don't print rules disabled in reduce_grammar_tables. */ if (rule_table[i].lhs >= 0) { - fprintf (out, _("rule %-4d %s ->"), i, tags[rule_table[i].lhs]); + fprintf (out, _(" %3d %3d %s ->"), + i, rule_table[i].line, tags[rule_table[i].lhs]); rule = &ritem[rule_table[i].rhs]; if (*rule > 0) while (*rule > 0) fprintf (out, " %s", tags[*rule++]); else - fprintf (out, " /* %s */", _("empty")); + fprintf (out, " /* %s */", _("empty")); fputc ('\n', out); } + fputs ("\n\n", out); + /* TERMINAL (type #) : rule #s terminal is on RHS */ - fprintf (out, "\n%s\n\n", _("Terminals, with rules where they appear")); + fprintf (out, "%s\n\n", _("Terminals, with rules where they appear")); fprintf (out, "%s (-1)\n", tags[0]); for (i = 0; i <= max_user_token_number; i++) @@ -257,9 +254,10 @@ print_grammar (FILE *out) } fprintf (out, "%s\n", buffer); } + fputs ("\n\n", out); - fprintf (out, "\n%s\n\n", - _("Nonterminals, with rules where they appear")); + + fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear")); for (i = ntokens; i <= nsyms - 1; i++) { int left_count = 0, right_count = 0; @@ -314,6 +312,7 @@ print_grammar (FILE *out) } fprintf (out, "%s\n", buffer); } + fputs ("\n\n", out); } void @@ -329,6 +328,8 @@ print_results (void) size_t size = obstack_object_size (&output_obstack); fwrite (obstack_finish (&output_obstack), 1, size, out); + if (size) + fputs ("\n\n", out); reduce_output (out); conflicts_output (out);