+2001-08-06 Marc Autret <autret_@epita.fr>
+
+ Automaton VCG graph output.
+ Using option ``-g'' or long option ``--graph'', you can generate
+ a gram_filename.vcg file containing a VCG description of the LALR (1)
+ automaton of your grammar.
+
+ * src/main.c: Call to print_graph() function.
+ * src/getargs.h: Update.
+ * src/getargs.c (options): Update to catch `-g' and `--graph' options.
+ (graph_flag): New flag.
+ (longopts): Update.
+ (getargs): Add case `g'.
+ * src/files.c (graph_obstack): New obstack struct.
+ (open_files): Initialize new obstack.
+ (output_files): Saves graph_obstack if required.
+ * src/files.h (graph_obstack): New extern declaration.
+ * src/Makefile.am: Add new source files.
+
2001-08-06 Marc Autret <autret_@epita.fr>
* src/print_graph.c, src/print_graph.h (graph): New.
derives.c \
files.c getargs.c gram.c lalr.c lex.c main.c nullable.c \
output.c \
- print.c reader.c reduce.c symtab.c warshall.c
+ print.c reader.c reduce.c symtab.c warshall.c vcg.c print_graph.c
EXTRA_bison_SOURCES = vmsgetargs.c
derives.h \
files.h getargs.h gram.h lalr.h lex.h nullable.h \
output.h state.h \
- print.h reader.h reduce.h symtab.h warshall.h system.h types.h
+ print.h reader.h reduce.h symtab.h warshall.h system.h types.h \
+ vcg.h vcg_defaults.h print_graph.h
pkgdata_DATA = bison.simple bison.hairy
bin_PROGRAMS = bison
-bison_SOURCES = LR0.c closure.c complain.c conflicts.c derives.c files.c getargs.c gram.c lalr.c lex.c main.c nullable.c output.c print.c reader.c reduce.c symtab.c warshall.c
+bison_SOURCES = LR0.c closure.c complain.c conflicts.c derives.c files.c getargs.c gram.c lalr.c lex.c main.c nullable.c output.c print.c reader.c reduce.c symtab.c warshall.c vcg.c print_graph.c
EXTRA_bison_SOURCES = vmsgetargs.c
-noinst_HEADERS = LR0.h closure.h complain.h conflicts.h derives.h files.h getargs.h gram.h lalr.h lex.h nullable.h output.h state.h print.h reader.h reduce.h symtab.h warshall.h system.h types.h
+noinst_HEADERS = LR0.h closure.h complain.h conflicts.h derives.h files.h getargs.h gram.h lalr.h lex.h nullable.h output.h state.h print.h reader.h reduce.h symtab.h warshall.h system.h types.h vcg.h vcg_defaults.h print_graph.h
pkgdata_DATA = bison.simple bison.hairy
bison_OBJECTS = LR0$U.o closure$U.o complain$U.o conflicts$U.o \
derives$U.o files$U.o getargs$U.o gram$U.o lalr$U.o lex$U.o main$U.o \
nullable$U.o output$U.o print$U.o reader$U.o reduce$U.o symtab$U.o \
-warshall$U.o
+warshall$U.o vcg$U.o print_graph$U.o
bison_LDADD = $(LDADD)
bison_DEPENDENCIES = ../lib/libbison.a
bison_LDFLAGS =
DEP_FILES = .deps/LR0.P .deps/closure.P .deps/complain.P \
.deps/conflicts.P .deps/derives.P .deps/files.P .deps/getargs.P \
.deps/gram.P .deps/lalr.P .deps/lex.P .deps/main.P .deps/nullable.P \
-.deps/output.P .deps/print.P .deps/reader.P .deps/reduce.P \
-.deps/symtab.P .deps/vmsgetargs.P .deps/warshall.P
+.deps/output.P .deps/print.P .deps/print_graph.P .deps/reader.P \
+.deps/reduce.P .deps/symtab.P .deps/vcg.P .deps/vmsgetargs.P \
+.deps/warshall.P
SOURCES = $(bison_SOURCES) $(EXTRA_bison_SOURCES)
OBJECTS = $(bison_OBJECTS)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/output.c; then echo $(srcdir)/output.c; else echo output.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > output_.c
print_.c: print.c $(ANSI2KNR)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/print.c; then echo $(srcdir)/print.c; else echo print.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > print_.c
+print_graph_.c: print_graph.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/print_graph.c; then echo $(srcdir)/print_graph.c; else echo print_graph.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > print_graph_.c
reader_.c: reader.c $(ANSI2KNR)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/reader.c; then echo $(srcdir)/reader.c; else echo reader.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > reader_.c
reduce_.c: reduce.c $(ANSI2KNR)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strspn.c; then echo $(srcdir)/strspn.c; else echo strspn.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strspn_.c
symtab_.c: symtab.c $(ANSI2KNR)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/symtab.c; then echo $(srcdir)/symtab.c; else echo symtab.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > symtab_.c
+vcg_.c: vcg.c $(ANSI2KNR)
+ $(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/vcg.c; then echo $(srcdir)/vcg.c; else echo vcg.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > vcg_.c
vmsgetargs_.c: vmsgetargs.c $(ANSI2KNR)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/vmsgetargs.c; then echo $(srcdir)/vmsgetargs.c; else echo vmsgetargs.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > vmsgetargs_.c
warshall_.c: warshall.c $(ANSI2KNR)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/warshall.c; then echo $(srcdir)/warshall.c; else echo warshall.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > warshall_.c
LR0_.o alloca_.o closure_.o complain_.o conflicts_.o derives_.o \
files_.o getargs_.o gram_.o lalr_.o lex_.o main_.o memchr_.o \
-nullable_.o output_.o print_.o reader_.o reduce_.o stpcpy_.o strndup_.o \
-strnlen_.o strspn_.o symtab_.o vmsgetargs_.o warshall_.o : $(ANSI2KNR)
+nullable_.o output_.o print_.o print_graph_.o reader_.o reduce_.o \
+stpcpy_.o strndup_.o strnlen_.o strspn_.o symtab_.o vcg_.o \
+vmsgetargs_.o warshall_.o : $(ANSI2KNR)
install-pkgdataDATA: $(pkgdata_DATA)
@$(NORMAL_INSTALL)
/* Open and close files for bison,
- Copyright 1984, 1986, 1989, 1992, 2000 Free Software Foundation, Inc.
+ Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
struct obstack defines_obstack;
struct obstack guard_obstack;
struct obstack output_obstack;
+struct obstack graph_obstack;
char *spec_outfile = NULL; /* for -o. */
char *spec_file_prefix = NULL; /* for -b. */
{
src_extension = tr(ext, 'y', 'c');
src_extension = tr(src_extension, 'Y', 'C');
- }
+ }
if (!header_extension)
{
header_extension = tr(ext, 'y', 'h');
if (!src_extension)
src_extension = xstrdup(ext);
if (!header_extension)
- {
+ {
header_extension = tr(ext, 'c', 'h');
header_extension = tr(header_extension, 'C', 'H');
}
/* The verbose output. */
extern struct obstack output_obstack;
+/* The VCG graph output. */
+extern struct obstack graph_obstack;
extern char *infile;
extern char *attrsfile;
int verbose_flag = 0;
int statistics_flag = 0;
int yacc_flag = 0; /* for -y */
+int graph_flag = 0;
const char *skeleton = NULL;
extern char *program_name;
-const char *shortopts = "yvdhrltknVo:b:p:S:";
+const char *shortopts = "yvgdhrltknVo:b:p:S:";
static struct option longopts[] =
{
/* Operation modes. */
{"verbose", no_argument, 0, 'v'},
{"file-prefix", required_argument, 0, 'b'},
{"output-file", required_argument, 0, 'o'},
+ {"graph", no_argument, 0, 'g'},
/* Hidden. */
{"statistics", no_argument, &statistics_flag, 1},
version (stdout);
exit (0);
+ case 'g':
+ graph_flag = 1;
+ break;
+
case 'v':
verbose_flag = 1;
break;
extern int statistics_flag;
extern int token_table_flag; /* for -k */
extern int verbose_flag; /* for -v */
+extern int graph_flag; /* for -g */
extern int yacc_flag; /* for -y */
void getargs PARAMS ((int argc, char *argv[]));
-/* Output a VCG description on generated parser, for bison,
- Copyright 1984, 1986, 1989, 2000, 2001 Free Software Foundation, Inc.
+/* Output a VCG description on generated parser, for Bison,
+ Copyright 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
core *statep;
short *sp;
short *sp1;
-
+
statep = state_table[state];
k = statep->nitems;
if (k == 0)
return;
-
+
obstack_sgrow(&graph_obstack, "\t\tlabel:\t\"");
for (i = 0; i < k; i++)
rule = -(*sp);
obstack_fgrow1(&graph_obstack, _("%d: "), rule);
- obstack_fgrow1(&graph_obstack, " %s -> ", tags[rlhs[rule]]);
+ obstack_fgrow1(&graph_obstack, " %s -> ", tags[rlhs[rule]]);
for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
obstack_fgrow1(&graph_obstack, "%s ", tags[*sp]);
obstack_1grow(&graph_obstack, '.');
-
+
while (*sp > 0)
obstack_fgrow1(&graph_obstack, " %s", tags[*sp++]);
-
+
obstack_sgrow(&graph_obstack, "\\n");
}
obstack_sgrow(&graph_obstack, "\"\n");
int rule;
static char buff[10];
edge_t edge;
-
+
shiftp = shift_table[state];
redp = reduction_table[state];
errp = err_table[state];
if (ISVAR (symbol))
break;
-
+
{
new_edge (&edge);
edge.sourcename = node->title;
edge.targetname = buff;
sprintf (edge.targetname, "%d", state1);
- edge.color = (symbol == 0) ? blue : red;
+ edge.color = (symbol == 0) ? blue : red;
edge.label = tags[symbol];
- output_edge (&edge, &graph_obstack);
+ output_edge (&edge, &graph_obstack);
close_edge (&graph_obstack);
- }
+ }
}
}
else
symbol = errp->errs[j];
}
}
-
+
if (consistent[state] && redp)
{
rule = redp->rules[0];
symbol = rlhs[rule];
}
-
+
if (i < k)
{
for (; i < k; i++)
print_state (int state)
{
static char name[10];
- node_t node;
+ node_t node;
new_node (&node);
open_node (&graph_obstack);
-
+
sprintf(name, "%d", state);
- node.title = name;
+ node.title = name;
output_node (&node, &graph_obstack);
-
+
print_core (state); /* node label */
-
+
close_node (&graph_obstack);
-
+
print_actions (state, &node); /* edges */
}
\f
print_graph (void)
{
int i;
-
+
if (!graph_flag)
return ;
new_graph (&graph);
-
+
/* graph.smanhattan_edges = yes;
graph.manhattan_edges = yes; */
-
+
graph.display_edge_labels = yes;
graph.layoutalgorithm = 0;
-
+
graph.port_sharing = no;
graph.finetuning = yes;
graph.straight_phase = yes;
graph.priority_phase = yes;
graph.splines = yes;
-
+
graph.crossing_weight = median;
/* Output graph options. */
/* Close graph. */
close_graph (&graph, &graph_obstack);
}
-