+/*--------------------------------------------------------------------.
+| Report a reduction of RULE on LOOKAHEADS (which can be `default'). |
+| If not ENABLED, the rule is masked by a shift or a reduce (S/R and |
+| R/R conflicts). |
+`--------------------------------------------------------------------*/
+
+static void
+print_reduction (FILE *out, size_t width,
+ const char *lookahead,
+ rule_t *rule, bool enabled)
+{
+ int j;
+ fprintf (out, " %s", lookahead);
+ for (j = width - strlen (lookahead); j > 0; --j)
+ fputc (' ', out);
+ if (!enabled)
+ fputc ('[', out);
+ if (rule->number)
+ fprintf (out, _("reduce using rule %d (%s)"),
+ rule->number, rule->lhs->tag);
+ else
+ fprintf (out, _("accept"));
+ if (!enabled)
+ fputc (']', out);
+ fputc ('\n', out);
+}
+
+
+/*----------------------------------------------------.
+| Report on OUT the reduction actions of this STATE. |
+`----------------------------------------------------*/
+
+static void
+print_reductions (FILE *out, state_t *state)
+{
+ transitions_t *transitions = state->transitions;
+ reductions_t *redp = state->reductions;
+ rule_t *default_rule = NULL;
+ size_t width = 0;
+ int i, j;
+
+ if (redp->num == 0)
+ return;
+
+ default_rule = state_default_rule (state);
+
+ bitset_zero (shiftset);
+ FOR_EACH_SHIFT (transitions, i)
+ bitset_set (shiftset, TRANSITION_SYMBOL (transitions, i));
+
+ /* Compute the width of the lookaheads column. */
+ if (default_rule)
+ width = strlen (_("$default"));
+
+ if (redp->lookaheads)
+ for (i = 0; i < ntokens; i++)
+ {
+ int count = bitset_test (shiftset, i);
+
+ for (j = 0; j < redp->num; ++j)
+ if (bitset_test (redp->lookaheads[j], i))
+ {
+ if (count == 0)
+ {
+ if (redp->rules[j] != default_rule)
+ max_length (&width, symbols[i]->tag);
+ count++;
+ }
+ else
+ {
+ max_length (&width, symbols[i]->tag);
+ }
+ }
+ }
+
+ /* Nothing to report. */
+ if (!width)
+ return;
+
+ fputc ('\n', out);
+ width += 2;
+
+ /* Report lookaheads (or $default) and reductions. */
+ if (redp->lookaheads)
+ for (i = 0; i < ntokens; i++)
+ {
+ int defaulted = 0;
+ int count = bitset_test (shiftset, i);
+
+ for (j = 0; j < redp->num; ++j)
+ if (bitset_test (redp->lookaheads[j], i))
+ {
+ if (count == 0)
+ {
+ if (redp->rules[j] != default_rule)
+ print_reduction (out, width,
+ symbols[i]->tag,
+ redp->rules[j], TRUE);
+ else
+ defaulted = 1;
+ count++;
+ }
+ else
+ {
+ if (defaulted)
+ print_reduction (out, width,
+ symbols[i]->tag,
+ default_rule, TRUE);
+ defaulted = 0;
+ print_reduction (out, width,
+ symbols[i]->tag,
+ redp->rules[j], FALSE);
+ }
+ }
+ }
+
+ if (default_rule)
+ print_reduction (out, width,
+ _("$default"), default_rule, TRUE);