print_core (FILE *out, state_t *state)
{
int i;
- short *sitems = state->items;
- int snitems = state->nitems;
+ item_number_t *sitems = state->items;
+ int snritems = state->nitems;
- /* New experimental feature: if TRACE_FLAGS output all the items of
- a state, not only its kernel. */
- if (trace_flag)
+ /* Output all the items of a state, not only its kernel. */
+ if (report_flag & report_itemsets)
{
- closure (sitems, snitems);
+ closure (sitems, snritems);
sitems = itemset;
- snitems = nitemset;
+ snritems = nritemset;
}
- if (snitems)
+ if (snritems)
{
- for (i = 0; i < snitems; i++)
+ for (i = 0; i < snritems; i++)
{
- short *sp;
- short *sp1;
+ item_number_t *sp;
+ item_number_t *sp1;
int rule;
sp1 = sp = ritem + sitems[i];
for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", escape (symbols[*sp]->tag));
+ /* Display the lookaheads? */
+ if (report_flag & report_lookaheads)
+ {
+ int j, k;
+ int nlookaheads = 0;
+ /* Look for lookaheads corresponding to this rule. */
+ for (j = 0; j < state->nlookaheads; ++j)
+ for (k = 0; k < ntokens; ++k)
+ if (bitset_test (LA[state->lookaheadsp + j], k)
+ && LArule[state->lookaheadsp + j]->number == rule)
+ nlookaheads++;
+ if (nlookaheads)
+ {
+ fprintf (out, " [");
+ for (j = 0; j < state->nlookaheads; ++j)
+ for (k = 0; k < ntokens; ++k)
+ if (bitset_test (LA[state->lookaheadsp + j], k)
+ && LArule[state->lookaheadsp + j]->number == rule)
+ fprintf (out, "%s%s",
+ quotearg_style (escape_quoting_style,
+ symbols[k]->tag),
+ --nlookaheads ? ", " : "");
+ fprintf (out, "]");
+ }
+ }
+
fprintf (out, _(" (rule %d)"), rule - 1);
fputc ('\n', out);
}
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- int symbol = states[state1]->accessing_symbol;
+ symbol_number_t symbol = states[state1]->accessing_symbol;
fprintf (out,
_(" %-4s\tshift, and go to state %d\n"),
escape (symbols[symbol]->tag), state1);
if (!SHIFT_IS_DISABLED (shiftp, i))
{
int state1 = shiftp->shifts[i];
- int symbol = states[state1]->accessing_symbol;
+ symbol_number_t symbol = states[state1]->accessing_symbol;
fprintf (out, _(" %-4s\tgo to state %d\n"),
escape (symbols[symbol]->tag), state1);
}
if (state->consistent)
{
int rule = redp->rules[0];
- int symbol = rules[rule].lhs->number;
+ symbol_number_t symbol = rules[rule].lhs->number;
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
rule - 1, escape (symbols[symbol]->tag));
return;
fputs ("\n\n", out);
print_core (out, state);
print_actions (out, state);
+ if ((report_flag & report_solved_conflicts)
+ && state->solved_conflicts)
+ fputs (state->solved_conflicts, out);
fputs ("\n\n", out);
}
\f
static void
print_grammar (FILE *out)
{
- int i, j;
- short *rule;
+ symbol_number_t i;
+ int j;
+ item_number_t *rule;
char buffer[90];
int column = 0;
/* rule # : LHS -> RHS */
fprintf (out, "%s\n\n", _("Grammar"));
fprintf (out, " %s\n", _("Number, Line, Rule"));
- for (i = 1; i < nrules + 1; i++)
+ for (j = 1; j < nrules + 1; j++)
{
fprintf (out, _(" %3d %3d %s ->"),
- i - 1, rules[i].line, escape (rules[i].lhs->tag));
- rule = rules[i].rhs;
+ j - 1, rules[j].line, escape (rules[j].lhs->tag));
+ rule = rules[j].rhs;
if (*rule >= 0)
while (*rule >= 0)
fprintf (out, " %s", escape (symbols[*rule++]->tag));
/* TERMINAL (type #) : rule #s terminal is on RHS */
fprintf (out, "%s\n\n", _("Terminals, with rules where they appear"));
for (i = 0; i < max_user_token_number + 1; i++)
- if (token_translations[i] != 2)
+ if (token_translations[i] != undeftoken->number)
{
buffer[0] = 0;
column = strlen (escape (symbols[token_translations[i]]->tag));
for (j = 1; j < nrules + 1; j++)
for (rule = rules[j].rhs; *rule >= 0; rule++)
- if (*rule == token_translations[i])
+ if (item_number_as_symbol_number (*rule) == token_translations[i])
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j - 1);
if (rules[j].lhs->number == i)
left_count++;
for (rule = rules[j].rhs; *rule >= 0; rule++)
- if (*rule == i)
+ if (item_number_as_symbol_number (*rule) == i)
{
right_count++;
break;
for (j = 1; j < nrules + 1; j++)
{
for (rule = rules[j].rhs; *rule >= 0; rule++)
- if (*rule == i)
+ if (item_number_as_symbol_number (*rule) == i)
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j - 1);
print_grammar (out);
- /* New experimental feature: output all the items of a state, not
- only its kernel. Requires to run closure, which need memory
- allocation/deallocation. */
- if (trace_flag)
+ /* If the whole state item sets, not only the kernels, are wanted,
+ `closure' will be run, which needs memory allocation/deallocation. */
+ if (report_flag & report_itemsets)
new_closure (nritems);
/* Storage for print_reductions. */
shiftset = bitset_create (ntokens, BITSET_FIXED);
print_state (out, states[i]);
bitset_free (shiftset);
bitset_free (lookaheadset);
- if (trace_flag)
+ if (report_flag & report_itemsets)
free_closure ();
xfclose (out);