]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
5671771e947c4b57b5b5e96c2b21601706ddc86e
1 /* Output a VCG description on generated parser, for Bison,
2 Copyright 2001 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 #include "conflicts.h"
33 #include "print_graph.h"
38 /* This part will construct the label of nodes. */
40 print_core (int state
)
49 statep
= state_table
[state
];
55 obstack_sgrow (&graph_obstack
, "\t\tlabel:\t\"");
57 for (i
= 0; i
< k
; i
++)
59 sp1
= sp
= ritem
+ statep
->items
[i
];
66 obstack_fgrow1 (&graph_obstack
, _("%d: "), rule
);
67 obstack_fgrow1 (&graph_obstack
, " %s -> ", tags
[rlhs
[rule
]]);
69 for (sp
= ritem
+ rrhs
[rule
]; sp
< sp1
; sp
++)
70 obstack_fgrow1 (&graph_obstack
, "%s ", tags
[*sp
]);
72 obstack_1grow (&graph_obstack
, '.');
75 obstack_fgrow1 (&graph_obstack
, " %s", tags
[*sp
++]);
77 obstack_sgrow (&graph_obstack
, "\\n");
79 obstack_sgrow (&graph_obstack
, "\"\n");
83 print_actions (int state
, node_t
*node
)
96 shiftp
= shift_table
[state
];
97 redp
= reduction_table
[state
];
98 errp
= err_table
[state
];
100 if (!shiftp
&& !redp
)
103 if (final_state
== state
)
104 fprintf (f
, " $default\taccept\n");
106 fprintf (f
, " NO ACTIONS\n");
115 for (i
= 0; i
< k
; i
++)
117 if (!shiftp
->shifts
[i
])
119 state1
= shiftp
->shifts
[i
];
120 symbol
= accessing_symbol
[state1
];
129 edge
.type
= back_edge
;
130 open_edge (&edge
, &graph_obstack
);
131 edge
.sourcename
= node
->title
;
132 edge
.targetname
= buff
;
133 sprintf (edge
.targetname
, "%d", state1
);
134 edge
.color
= (symbol
== 0) ? blue
: red
;
135 edge
.label
= tags
[symbol
];
136 output_edge (&edge
, &graph_obstack
);
137 close_edge (&graph_obstack
);
153 for (j
= 0; j
< nerrs
; j
++)
157 symbol
= errp
->errs
[j
];
161 if (consistent
[state
] && redp
)
163 rule
= redp
->rules
[0];
171 if (!shiftp
->shifts
[i
])
173 state1
= shiftp
->shifts
[i
];
174 symbol
= accessing_symbol
[state1
];
177 open_edge (&edge
, &graph_obstack
);
178 edge
.sourcename
= node
->title
;
179 edge
.targetname
= buff
;
181 sprintf (edge
.targetname
, "%d", state1
);
182 edge
.label
= tags
[symbol
];
183 output_edge (&edge
, &graph_obstack
);
184 close_edge (&graph_obstack
);
190 print_state (int state
)
192 static char name
[10];
196 open_node (&graph_obstack
);
198 sprintf (name
, "%d", state
);
200 output_node (&node
, &graph_obstack
);
202 print_core (state
); /* node label */
204 close_node (&graph_obstack
);
206 print_actions (state
, &node
); /* edges */
219 /* graph.smanhattan_edges = yes;
220 graph.manhattan_edges = yes; */
222 graph
.display_edge_labels
= yes
;
223 graph
.layoutalgorithm
= 0;
225 graph
.port_sharing
= no
;
226 graph
.finetuning
= yes
;
227 graph
.straight_phase
= yes
;
228 graph
.priority_phase
= yes
;
231 graph
.crossing_weight
= median
;
233 /* Output graph options. */
234 open_graph (&graph_obstack
);
235 output_graph (&graph
, &graph_obstack
);
237 for (i
= 0; i
< nstates
; i
++)
238 /* Output nodes & edges. */
242 close_graph (&graph
, &graph_obstack
);