multistart: adjust computation of initial core and adjust reports

Currently the core of the initial state is limited to the single rule
on $accept.

* src/lr0.c (generate_states): There may now be several rules on
$accept.

* src/graphviz.c (conclude_red): Recognize "final" transitions by the
fact that we reduce to "$accept".
* src/print.c (print_reduction): Likewise.
* src/print-xml.c (print_reduction): Likewise.
This commit is contained in:
Akim Demaille
2020-02-22 21:55:23 +01:00
parent 4646be7db4
commit 85ccc1bab3
5 changed files with 1173 additions and 17 deletions

View File

@@ -101,6 +101,7 @@ no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
bitset_set (*no_reduce_set, s->errs->symbols[n]->content->number);
}
/* Show the reductions from state SOURCE on rule RULENO. */
static void
conclude_red (struct obstack *out, int source, rule_number ruleno,
bool enabled, bool first, FILE *fout)
@@ -112,8 +113,6 @@ conclude_red (struct obstack *out, int source, rule_number ruleno,
else
{
char const *ed = enabled ? "" : "d";
char const *color = enabled ? ruleno ? "3" : "1" : "5";
/* First, build the edge's head. The name of reduction nodes is "nRm",
with n the source state and m the rule number. This is because we
don't want all the reductions bearing a same rule number to point to
@@ -136,11 +135,16 @@ conclude_red (struct obstack *out, int source, rule_number ruleno,
/* Build the associated diamond representation of the target rule. */
fprintf (fout, " \"%dR%d%s\" [label=\"",
source, ruleno, ed);
if (ruleno)
fprintf (fout, "R%d", ruleno);
else
bool final = rules[ruleno].lhs->symbol == acceptsymbol;
if (final)
fprintf (fout, "Acc");
else
fprintf (fout, "R%d", ruleno);
char const *color
= !enabled ? "5"
: final ? "1"
: "3";
fprintf (fout, "\", fillcolor=%s, shape=diamond, style=filled]\n",
color);
}

View File

@@ -395,9 +395,10 @@ generate_states (void)
/* Create the initial state, whose accessing symbol (by convention)
is 0, aka $end. */
{
/* The items of its core. */
kernel_size[0] = 1;
kernel_base[0][0] = 0;
/* The items of its core: beginning of all the rules of $accept. */
kernel_size[0] = 0;
for (rule_number r = 0; r < nrules && rules[r].lhs->symbol == acceptsymbol; ++r)
kernel_base[0][kernel_size[0]++] = rules[r].rhs - ritem;
state_list_append (0, kernel_size[0], kernel_base[0]);
}

View File

@@ -216,17 +216,18 @@ static void
print_reduction (FILE *out, int level, char const *lookahead,
rule *r, bool enabled)
{
if (r->number)
const bool final = r->lhs->symbol == acceptsymbol;
if (final)
xml_printf (out, level,
"<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
xml_escape (lookahead),
enabled ? "true" : "false");
else
xml_printf (out, level,
"<reduction symbol=\"%s\" rule=\"%d\" enabled=\"%s\"/>",
xml_escape (lookahead),
r->number,
enabled ? "true" : "false");
else
xml_printf (out, level,
"<reduction symbol=\"%s\" rule=\"accept\" enabled=\"%s\"/>",
xml_escape (lookahead),
enabled ? "true" : "false");
}

View File

@@ -196,11 +196,12 @@ print_reduction (FILE *out, size_t width,
fputc (' ', out);
if (!enabled)
fputc ('[', out);
if (r->number)
const bool final = r->lhs->symbol == acceptsymbol;
if (final)
fprintf (out, _("accept"));
else
fprintf (out, _("reduce using rule %d (%s)"), r->number,
r->lhs->symbol->tag);
else
fprintf (out, _("accept"));
if (!enabled)
fputc (']', out);
fputc ('\n', out);

File diff suppressed because it is too large Load Diff