* src/LR0.c (new_state): Recognize the final state by the fact it

is reached by eoftoken.
(insert_start_shifting_state, insert_eof_shifting_state)
(insert_accepting_state, augment_automaton): Remove, since now
these states are automatically computed from the initial state.
(generate_states): Adjust.
* src/print.c: When reporting a rule number to the user, substract
1, so that the axiom rule is rule 0, and the first user rule is 1.
* src/reduce.c: Likewise.
* src/print_graph.c (print_core): For the time being, just as for
the report, depend upon --trace-flags to dump the full set of
items.
* src/reader.c (readgram): Once the grammar read, insert the rule
0: `$axiom: START-SYMBOL $'.
* tests/set.at: Adjust: rule 0 is now displayed, and since the
number of the states has changed (the final state is no longer
necessarily the last), catch up.
This commit is contained in:
Akim Demaille
2001-12-27 18:13:47 +00:00
parent 75142d452b
commit 30171f79ab
7 changed files with 154 additions and 241 deletions

View File

@@ -102,7 +102,7 @@ print_core (FILE *out, state_t *state)
for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", escape (tags[*sp]));
fprintf (out, _(" (rule %d)"), rule);
fprintf (out, _(" (rule %d)"), rule - 1);
fputc ('\n', out);
}
@@ -189,7 +189,7 @@ print_reductions (FILE *out, state_t *state)
int rule = redp->rules[0];
int symbol = rule_table[rule].lhs;
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
rule, escape (tags[symbol]));
rule - 1, escape (tags[symbol]));
return;
}
@@ -221,11 +221,11 @@ print_reductions (FILE *out, state_t *state)
for (i = 0; i < ntokens; i++)
if (BITISSET (lookaheadset, i))
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
escape (tags[i]), default_rule,
escape (tags[i]), default_rule - 1,
escape2 (tags[rule_table[default_rule].lhs]));
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
default_rule, escape (tags[rule_table[default_rule].lhs]));
default_rule - 1, escape (tags[rule_table[default_rule].lhs]));
}
else if (state->nlookaheads >= 1)
{
@@ -280,7 +280,7 @@ print_reductions (FILE *out, state_t *state)
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
escape (tags[i]),
LAruleno[state->lookaheadsp + j],
LAruleno[state->lookaheadsp + j] - 1,
escape2 (tags[rule_table[LAruleno[state->lookaheadsp + j]].lhs]));
else
defaulted = 1;
@@ -293,13 +293,13 @@ print_reductions (FILE *out, state_t *state)
fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"),
escape (tags[i]),
LAruleno[default_LA],
LAruleno[default_LA] - 1,
escape2 (tags[rule_table[LAruleno[default_LA]].lhs]));
defaulted = 0;
fprintf (out,
_(" %-4s\t[reduce using rule %d (%s)]\n"),
escape (tags[i]),
LAruleno[state->lookaheadsp + j],
LAruleno[state->lookaheadsp + j] - 1,
escape2 (tags[rule_table[LAruleno[state->lookaheadsp + j]].lhs]));
}
}
@@ -308,7 +308,8 @@ print_reductions (FILE *out, state_t *state)
if (default_LA >= 0)
fprintf (out, _(" $default\treduce using rule %d (%s)\n"),
default_rule, escape (tags[rule_table[default_rule].lhs]));
default_rule - 1,
escape (tags[rule_table[default_rule].lhs]));
}
}
@@ -322,9 +323,9 @@ print_actions (FILE *out, state_t *state)
if (shiftp->nshifts == 0 && redp->nreds == 0)
{
if (final_state == state->number)
fprintf (out, _(" $default\taccept\n"));
fprintf (out, _(" $default\taccept\n"));
else
fprintf (out, _(" NO ACTIONS\n"));
fprintf (out, _(" NO ACTIONS\n"));
return;
}
@@ -375,7 +376,7 @@ print_grammar (FILE *out)
if (rule_table[i].useful)
{
fprintf (out, _(" %3d %3d %s ->"),
i, rule_table[i].line, escape (tags[rule_table[i].lhs]));
i - 1, rule_table[i].line, escape (tags[rule_table[i].lhs]));
rule = &ritem[rule_table[i].rhs];
if (*rule >= 0)
while (*rule >= 0)
@@ -403,7 +404,7 @@ print_grammar (FILE *out)
if (*rule == token_translations[i])
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j);
sprintf (buffer + strlen (buffer), " %d", j - 1);
break;
}
fprintf (out, "%s\n", buffer);
@@ -443,7 +444,7 @@ print_grammar (FILE *out)
{
END_TEST (65);
if (rule_table[j].lhs == i)
sprintf (buffer + strlen (buffer), " %d", j);
sprintf (buffer + strlen (buffer), " %d", j - 1);
}
}
@@ -459,7 +460,7 @@ print_grammar (FILE *out)
if (*rule == i)
{
END_TEST (65);
sprintf (buffer + strlen (buffer), " %d", j);
sprintf (buffer + strlen (buffer), " %d", j - 1);
break;
}
}