mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 07:43:03 +00:00
graphs: style changes
* src/graphviz.c (start_graph): Use courier font. (conclude_red): Use commas to separate attributes. Show the acceptation as a special reduction, with a blue color and an "Acc" label. Show the lookahead tokens between square brackets. (output_red): No longer label default reductions. * src/print_graph.c (print_core): Refactor spacing, and print an additional space between a rule's rhs and its lookahead tokens. Also, capitalize "State". (print_actions): Style, move a declaration. Signed-off-by: Akim Demaille <akim@lrde.epita.fr>
This commit is contained in:
committed by
Akim Demaille
parent
85935600ad
commit
8048226f50
@@ -53,7 +53,10 @@ start_graph (FILE *fout)
|
|||||||
"digraph %s\n"
|
"digraph %s\n"
|
||||||
"{\n",
|
"{\n",
|
||||||
quote (grammar_file));
|
quote (grammar_file));
|
||||||
fprintf (fout, "node [shape=box]\n");
|
fprintf (fout,
|
||||||
|
" node [fontname = courier, shape = box, colorscheme = paired6]\n"
|
||||||
|
" edge [fontname = courier]\n"
|
||||||
|
"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -94,8 +97,8 @@ no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
conclude_red (struct obstack *out, int source, int ruleno, bool enabled,
|
conclude_red (struct obstack *out, int source, rule_number ruleno,
|
||||||
bool first, FILE *fout)
|
bool enabled, bool first, FILE *fout)
|
||||||
{
|
{
|
||||||
/* If no lookahead tokens were valid transitions, this reduction is
|
/* If no lookahead tokens were valid transitions, this reduction is
|
||||||
actually hidden, so cancel everything. */
|
actually hidden, so cancel everything. */
|
||||||
@@ -104,26 +107,33 @@ conclude_red (struct obstack *out, int source, int ruleno, bool enabled,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
char const *ed = enabled ? "e" : "d";
|
char const *ed = enabled ? "e" : "d";
|
||||||
|
char const *color = enabled ? ruleno ? "3" : "1" : "5";
|
||||||
|
|
||||||
/* First, build the edge's head. */
|
/* First, build the edge's head. The name of reduction nodes is "nRm",
|
||||||
if (! first)
|
with n the source state and m the rule number. This is because we
|
||||||
fprintf (fout, " %1$d -> \"%1$dR%2$d%3$s\" [label = \"",
|
don't want all the reductions bearing a same rule number to point to
|
||||||
source, ruleno, ed);
|
the same state, since that is not the desired format. */
|
||||||
|
fprintf (fout, " %1$d -> \"%1$dR%2$d%3$s\" [",
|
||||||
|
source, ruleno, ed);
|
||||||
|
|
||||||
/* (The lookahead tokens have been added to the beginning of the
|
if (! obstack_empty_p (out))
|
||||||
obstack, in the caller function.) */
|
/* (The lookahead tokens have been added to the beginning of the
|
||||||
|
obstack, in the caller function.) */
|
||||||
|
fprintf (fout, "label = \"[%s]\" ", obstack_finish0 (out));
|
||||||
|
|
||||||
/* Then, the edge's tail. */
|
/* Then, the edge's tail. */
|
||||||
obstack_sgrow (out, "\" style = solid]\n");
|
fprintf (fout, "style = solid]\n");
|
||||||
|
|
||||||
|
/* Build the associated diamond representation of the target rule. */
|
||||||
|
fprintf (fout, " \"%dR%d%s\" [style = filled, "
|
||||||
|
"shape = diamond, fillcolor = %s, ",
|
||||||
|
source, ruleno, ed, color);
|
||||||
|
|
||||||
|
if (ruleno)
|
||||||
|
fprintf (fout, "label = \"R%d\"]\n", ruleno);
|
||||||
|
else
|
||||||
|
fprintf (fout, "label = \"Acc\"]\n");
|
||||||
|
|
||||||
/* Build the associated diamond representation or the target rule. */
|
|
||||||
obstack_printf (out, " \"%dR%d%s\" "
|
|
||||||
"[style = filled shape = diamond fillcolor = %s "
|
|
||||||
"label = \"R%d\"]\n",
|
|
||||||
source, ruleno, ed,
|
|
||||||
enabled ? "yellowgreen" : "firebrick1",
|
|
||||||
ruleno);
|
|
||||||
fprintf (fout, obstack_finish0 (out));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +143,7 @@ print_token (struct obstack *out, bool first, char const *tok)
|
|||||||
char const *q = escape (tok);
|
char const *q = escape (tok);
|
||||||
|
|
||||||
if (! first)
|
if (! first)
|
||||||
obstack_sgrow (out, ",");
|
obstack_sgrow (out, ", ");
|
||||||
obstack_sgrow (out, q);
|
obstack_sgrow (out, q);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -144,7 +154,13 @@ output_red (state const *s, reductions const *reds, FILE *fout)
|
|||||||
bitset no_reduce_set;
|
bitset no_reduce_set;
|
||||||
int j;
|
int j;
|
||||||
int source = s->number;
|
int source = s->number;
|
||||||
struct obstack dout, eout;
|
|
||||||
|
/* Two obstacks are needed: one for the enabled reductions, and one
|
||||||
|
for the disabled reductions, because in the end we want two
|
||||||
|
separate edges, even though in most cases only one will actually
|
||||||
|
be printed. */
|
||||||
|
struct obstack dout;
|
||||||
|
struct obstack eout;
|
||||||
|
|
||||||
no_reduce_bitset_init (s, &no_reduce_set);
|
no_reduce_bitset_init (s, &no_reduce_set);
|
||||||
obstack_init (&dout);
|
obstack_init (&dout);
|
||||||
@@ -153,8 +169,9 @@ output_red (state const *s, reductions const *reds, FILE *fout)
|
|||||||
for (j = 0; j < reds->num; ++j)
|
for (j = 0; j < reds->num; ++j)
|
||||||
{
|
{
|
||||||
bool defaulted = false;
|
bool defaulted = false;
|
||||||
bool firstd = true, firste = true; // first{en,dis}abled
|
bool firstd = true;
|
||||||
int ruleno = reds->rules[j]->user_number;
|
bool firste = true;
|
||||||
|
rule_number ruleno = reds->rules[j]->user_number;
|
||||||
rule *default_reduction = NULL;
|
rule *default_reduction = NULL;
|
||||||
|
|
||||||
if (yydefact[s->number] != 0)
|
if (yydefact[s->number] != 0)
|
||||||
@@ -163,10 +180,7 @@ output_red (state const *s, reductions const *reds, FILE *fout)
|
|||||||
/* Build the lookahead tokens lists, one for enabled transitions and one
|
/* Build the lookahead tokens lists, one for enabled transitions and one
|
||||||
for disabled transistions. */
|
for disabled transistions. */
|
||||||
if (default_reduction && default_reduction == reds->rules[j])
|
if (default_reduction && default_reduction == reds->rules[j])
|
||||||
{
|
defaulted = true;
|
||||||
firste = print_token (&eout, true, "$default");
|
|
||||||
defaulted = true;
|
|
||||||
}
|
|
||||||
if (reds->lookahead_tokens)
|
if (reds->lookahead_tokens)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -185,7 +199,7 @@ output_red (state const *s, reductions const *reds, FILE *fout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do the actual output. */
|
/* Do the actual output. */
|
||||||
conclude_red (&eout, source, ruleno, true, firste, fout);
|
conclude_red (&eout, source, ruleno, true, firste && !defaulted, fout);
|
||||||
conclude_red (&dout, source, ruleno, false, firstd, fout);
|
conclude_red (&dout, source, ruleno, false, firstd, fout);
|
||||||
}
|
}
|
||||||
obstack_free (&eout, 0);
|
obstack_free (&eout, 0);
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ print_core (struct obstack *oout, state *s)
|
|||||||
snritems = nitemset;
|
snritems = nitemset;
|
||||||
}
|
}
|
||||||
|
|
||||||
obstack_printf (oout, "state %d\\n", s->number);
|
obstack_printf (oout, _("State %d"), s->number);
|
||||||
|
obstack_sgrow (oout, "\\n");
|
||||||
for (i = 0; i < snritems; i++)
|
for (i = 0; i < snritems; i++)
|
||||||
{
|
{
|
||||||
item_number *sp;
|
item_number *sp;
|
||||||
@@ -69,12 +70,12 @@ print_core (struct obstack *oout, state *s)
|
|||||||
|
|
||||||
r = item_number_as_rule_number (*sp);
|
r = item_number_as_rule_number (*sp);
|
||||||
|
|
||||||
obstack_printf (oout, "%d: %s -> ", r, escape (rules[r].lhs->tag));
|
obstack_printf (oout, "%d: %s ->", r, escape (rules[r].lhs->tag));
|
||||||
|
|
||||||
for (sp = rules[r].rhs; sp < sp1; sp++)
|
for (sp = rules[r].rhs; sp < sp1; sp++)
|
||||||
obstack_printf (oout, "%s ", escape (symbols[*sp]->tag));
|
obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
|
||||||
|
|
||||||
obstack_1grow (oout, '.');
|
obstack_sgrow (oout, " .");
|
||||||
|
|
||||||
for (/* Nothing */; *sp >= 0; ++sp)
|
for (/* Nothing */; *sp >= 0; ++sp)
|
||||||
obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
|
obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
|
||||||
@@ -93,7 +94,7 @@ print_core (struct obstack *oout, state *s)
|
|||||||
bitset_iterator biter;
|
bitset_iterator biter;
|
||||||
int k;
|
int k;
|
||||||
char const *sep = "";
|
char const *sep = "";
|
||||||
obstack_1grow (oout, '[');
|
obstack_sgrow (oout, " [");
|
||||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
|
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
|
||||||
{
|
{
|
||||||
obstack_sgrow (oout, sep);
|
obstack_sgrow (oout, sep);
|
||||||
@@ -116,9 +117,8 @@ print_core (struct obstack *oout, state *s)
|
|||||||
static void
|
static void
|
||||||
print_actions (state const *s, FILE *fgraph)
|
print_actions (state const *s, FILE *fgraph)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
transitions const *trans = s->transitions;
|
transitions const *trans = s->transitions;
|
||||||
|
int i;
|
||||||
|
|
||||||
/* Display reductions. */
|
/* Display reductions. */
|
||||||
output_red (s, s->reductions, fgraph);
|
output_red (s, s->reductions, fgraph);
|
||||||
|
|||||||
Reference in New Issue
Block a user