19 |
Boston, MA 02111-1307, USA. */ |
Boston, MA 02111-1307, USA. */ |
20 |
|
|
21 |
#include "system.h" |
#include "system.h" |
22 |
|
#include "quotearg.h" |
23 |
#include "files.h" |
#include "files.h" |
24 |
#include "gram.h" |
#include "gram.h" |
25 |
#include "LR0.h" |
#include "LR0.h" |
37 |
static graph_t graph; |
static graph_t graph; |
38 |
static FILE *fgraph = NULL; |
static FILE *fgraph = NULL; |
39 |
|
|
40 |
|
static inline const char * |
41 |
|
escape (const char *s) |
42 |
|
{ |
43 |
|
return quotearg_n_style (1, escape_quoting_style, s); |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
/* This part will construct the label of nodes. */ |
/* This part will construct the label of nodes. */ |
48 |
static void |
static void |
49 |
print_core (state_t *state, struct obstack *node_obstack) |
print_core (state_t *state, struct obstack *node_obstack) |
57 |
sitems = itemset; |
sitems = itemset; |
58 |
snitems = nitemset; |
snitems = nitemset; |
59 |
|
|
60 |
obstack_fgrow1 (node_obstack, "%2d: ", state->number); |
obstack_fgrow1 (node_obstack, "state %2d\n", state->number); |
61 |
for (i = 0; i < snitems; i++) |
for (i = 0; i < snitems; i++) |
62 |
{ |
{ |
63 |
short *sp; |
short *sp; |
72 |
rule = -(*sp); |
rule = -(*sp); |
73 |
|
|
74 |
if (i) |
if (i) |
75 |
obstack_sgrow (node_obstack, "\n "); |
obstack_1grow (node_obstack, '\n'); |
76 |
obstack_fgrow1 (node_obstack, " %s -> ", |
obstack_fgrow1 (node_obstack, " %s -> ", |
77 |
tags[rule_table[rule].lhs]); |
escape (tags[rule_table[rule].lhs])); |
78 |
|
|
79 |
for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++) |
for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++) |
80 |
obstack_fgrow1 (node_obstack, "%s ", tags[*sp]); |
obstack_fgrow1 (node_obstack, "%s ", escape (tags[*sp])); |
81 |
|
|
82 |
obstack_1grow (node_obstack, '.'); |
obstack_1grow (node_obstack, '.'); |
83 |
|
|
84 |
for (/* Nothing */; *sp > 0; ++sp) |
for (/* Nothing */; *sp > 0; ++sp) |
85 |
obstack_fgrow1 (node_obstack, " %s", tags[*sp]); |
obstack_fgrow1 (node_obstack, " %s", escape (tags[*sp])); |
86 |
} |
} |
87 |
} |
} |
88 |
|
|
121 |
edge.sourcename = node_name; |
edge.sourcename = node_name; |
122 |
sprintf (buff, "%d", state1); |
sprintf (buff, "%d", state1); |
123 |
edge.targetname = buff; |
edge.targetname = buff; |
124 |
/* Shifts are blue, gotos are red. */ |
/* Shifts are blue, gotos are green, and error is red. */ |
125 |
edge.color = SHIFT_IS_SHIFT(shiftp, i) ? blue : red; |
if (SHIFT_IS_ERROR (shiftp, i)) |
126 |
edge.label = tags[symbol]; |
edge.color = red; |
127 |
|
else |
128 |
|
edge.color = SHIFT_IS_SHIFT(shiftp, i) ? blue : green; |
129 |
|
edge.label = escape (tags[symbol]); |
130 |
output_edge (&edge, fgraph); |
output_edge (&edge, fgraph); |
131 |
close_edge (fgraph); |
close_edge (fgraph); |
132 |
} |
} |