]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
6cab7234a9c7bff2eb20da328f5647d7e0f7a485
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
)
102 if (final_state
== state
)
103 ;//fprintf(f, " $default\taccept\n");
105 ;//fprintf(f, " NO ACTIONS\n");
113 for (i
= 0; i
< k
; i
++)
115 if (!shiftp
->shifts
[i
])
117 state1
= shiftp
->shifts
[i
];
118 symbol
= accessing_symbol
[state1
];
127 edge
.type
= back_edge
;
128 open_edge (&edge
, &graph_obstack
);
129 edge
.sourcename
= node
->title
;
130 edge
.targetname
= buff
;
131 sprintf (edge
.targetname
, "%d", state1
);
132 edge
.color
= (symbol
== 0) ? blue
: red
;
133 edge
.label
= tags
[symbol
];
134 output_edge (&edge
, &graph_obstack
);
135 close_edge (&graph_obstack
);
151 for (j
= 0; j
< nerrs
; j
++)
155 symbol
= errp
->errs
[j
];
159 if (consistent
[state
] && redp
)
161 rule
= redp
->rules
[0];
169 if (!shiftp
->shifts
[i
])
171 state1
= shiftp
->shifts
[i
];
172 symbol
= accessing_symbol
[state1
];
175 open_edge (&edge
, &graph_obstack
);
176 edge
.sourcename
= node
->title
;
177 edge
.targetname
= buff
;
179 sprintf (edge
.targetname
, "%d", state1
);
180 edge
.label
= tags
[symbol
];
181 output_edge (&edge
, &graph_obstack
);
182 close_edge (&graph_obstack
);
188 print_state (int state
)
190 static char name
[10];
194 open_node (&graph_obstack
);
196 sprintf(name
, "%d", state
);
198 output_node (&node
, &graph_obstack
);
200 print_core (state
); /* node label */
202 close_node (&graph_obstack
);
204 print_actions (state
, &node
); /* edges */
217 /* graph.smanhattan_edges = yes;
218 graph.manhattan_edges = yes; */
220 graph
.display_edge_labels
= yes
;
221 graph
.layoutalgorithm
= 0;
223 graph
.port_sharing
= no
;
224 graph
.finetuning
= yes
;
225 graph
.straight_phase
= yes
;
226 graph
.priority_phase
= yes
;
229 graph
.crossing_weight
= median
;
231 /* Output graph options. */
232 open_graph (&graph_obstack
);
233 output_graph (&graph
, &graph_obstack
);
235 for (i
= 0; i
< nstates
; i
++)
236 /* Output nodes & edges. */
240 close_graph (&graph
, &graph_obstack
);