From ea52d7066d461da102602b25d371dd09e82eb371 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 15 Dec 2001 14:35:57 +0000 Subject: [PATCH] Still making progress in separating Bison into (i) input, (ii) process, (iii) output: now we can directly output the parser file without using table_obstack at all. * src/files.c, src/files.h (table_obstack): Bye bye. (parser_file_name): New. * src/files.c (compute_output_file_names): Compute it. * src/output.c (actions_output, output_parser) (output_master_parser): To a file instead of an obstack. --- ChangeLog | 12 ++++++++++++ src/files.c | 14 ++++---------- src/files.h | 16 ++++++---------- src/output.c | 39 +++++++++++++++++++++------------------ 4 files changed, 43 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index b256520e..ae9d826f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2001-12-15 Akim Demaille + + Still making progress in separating Bison into (i) input, (ii) + process, (iii) output: now we can directly output the parser file + without using table_obstack at all. + + * src/files.c, src/files.h (table_obstack): Bye bye. + (parser_file_name): New. + * src/files.c (compute_output_file_names): Compute it. + * src/output.c (actions_output, output_parser) + (output_master_parser): To a file instead of an obstack. + 2001-12-15 Akim Demaille Attach actions to rules, instead of pre-outputting them to diff --git a/src/files.c b/src/files.c index fa31b032..dc6eb1e6 100644 --- a/src/files.c +++ b/src/files.c @@ -30,7 +30,6 @@ FILE *finput = NULL; struct obstack action_obstack; struct obstack attrs_obstack; -struct obstack table_obstack; struct obstack defines_obstack; struct obstack guard_obstack; struct obstack output_obstack; @@ -41,6 +40,7 @@ const char *spec_name_prefix = "yy"; /* for -p. */ char *spec_verbose_file = NULL; /* for --verbose. */ char *spec_graph_file = NULL; /* for -g. */ char *spec_defines_file = NULL; /* for --defines. */ +char *parser_file_name = NULL; char *infile = NULL; char *attrsfile = NULL; @@ -433,6 +433,9 @@ compute_output_file_names (void) { compute_base_names (); + parser_file_name = + spec_outfile ? spec_outfile : stringappend (base_name, src_extension); + /* If not yet done. */ if (!src_extension) src_extension = ".c"; @@ -453,7 +456,6 @@ compute_output_file_names (void) #ifndef MSDOS attrsfile = stringappend (attrsfile, header_extension); #endif /* MSDOS */ - } /*-----------------------------------------------------------------. @@ -469,7 +471,6 @@ open_files (void) /* Initialize the obstacks. */ obstack_init (&action_obstack); obstack_init (&attrs_obstack); - obstack_init (&table_obstack); obstack_init (&defines_obstack); obstack_init (&guard_obstack); obstack_init (&output_obstack); @@ -494,13 +495,6 @@ close_files (void) void output_files (void) { - /* Output the main file. */ - if (spec_outfile) - obstack_save (&table_obstack, spec_outfile); - else - obstack_save (&table_obstack, stringappend (base_name, src_extension)); - obstack_free (&table_obstack, NULL); - /* Output the header file if wanted. */ if (defines_flag) defines_obstack_save (spec_defines_file); diff --git a/src/files.h b/src/files.h index 2ef0a4ad..30108635 100644 --- a/src/files.h +++ b/src/files.h @@ -1,7 +1,5 @@ -#ifndef FILES_H_ -# define FILES_H_ /* File names and variables for bison, - Copyright 1984, 1989, 2000 Free Software Foundation, Inc. + Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -20,13 +18,15 @@ the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* These two should be pathnames for opening the sample parser files. - When bison is installed, they should be absolute pathnames. - XPFILE1 and XPFILE2 normally come from config.h. */ +#ifndef FILES_H_ +# define FILES_H_ /* File name specified with -o for the output file, or 0 if no -o. */ extern char *spec_outfile; +/* File name for the parser (i.e., the one above, or its default.) */ +extern char *parser_file_name; + /* For -a. */ extern const char *spec_name_prefix; @@ -49,10 +49,6 @@ extern FILE *finput; /* Output all the action code; precise form depends on which parser. */ extern struct obstack action_obstack; -/* Output the tables and the parser and also contains all the %{ - ... %} definitions. */ -extern struct obstack table_obstack; - /* optionally output #define's for token numbers. */ extern struct obstack defines_obstack; diff --git a/src/output.c b/src/output.c index 7c2d0136..b919c6a3 100644 --- a/src/output.c +++ b/src/output.c @@ -515,25 +515,25 @@ token_actions (void) `-----------------------------*/ static void -actions_output (struct obstack *oout) +actions_output (FILE *out) { int rule; for (rule = 1; rule < nrules + 1; ++rule) if (rule_table[rule].action) { - obstack_fgrow1 (oout, " case %d:\n", rule); + fprintf (out, " case %d:\n", rule); if (!no_lines_flag) - obstack_fgrow2 (oout, muscle_find ("linef"), - rule_table[rule].action_line, - quotearg_style (c_quoting_style, - muscle_find ("filename"))); - obstack_1grow (oout, '{'); - obstack_sgrow (oout, rule_table[rule].action); + fprintf (out, muscle_find ("linef"), + rule_table[rule].action_line, + quotearg_style (c_quoting_style, + muscle_find ("filename"))); /* As a Bison extension, add the ending semicolon. Since some Yacc don't do that, help people using bison as a Yacc finding their missing semicolons. */ - obstack_fgrow1 (oout, "%s}\n break;\n\n", yacc_flag ? ";" : ""); + fprintf (out, "{ %s%s }\n break;\n\n", + rule_table[rule].action, + yacc_flag ? ";" : ""); } } @@ -924,7 +924,7 @@ output_actions (void) `------------------------------------------------------------*/ static void -output_parser (const char *skel_filename, struct obstack *oout) +output_parser (const char *skel_filename, FILE *out) { int c; FILE *fskel; @@ -941,7 +941,7 @@ output_parser (const char *skel_filename, struct obstack *oout) { if (c == '\n') ++line; - obstack_1grow (oout, c); + putc (c, out); c = getc (fskel); } else if ((c = getc (fskel)) == '%') @@ -958,19 +958,19 @@ output_parser (const char *skel_filename, struct obstack *oout) muscle_key = obstack_finish (&muscle_obstack); muscle_value = muscle_find (muscle_key); if (!strcmp (muscle_key, "actions")) - actions_output (oout); + actions_output (out); else if (!strcmp (muscle_key, "line")) - obstack_fgrow1 (oout, "%d", line + 1); + fprintf (out, "%d", line + 1); else if (muscle_value) - obstack_sgrow (oout, muscle_value); + fputs (muscle_value, out); else { - obstack_sgrow (oout, "%%"); - obstack_sgrow (oout, muscle_key); + fputs ("%%", out); + fputs (muscle_key, out); } } else - obstack_1grow (oout, '%'); + putc ('%', out); } /* End. */ @@ -984,6 +984,7 @@ output_parser (const char *skel_filename, struct obstack *oout) static void output_master_parser (void) { + FILE *parser = xfopen (parser_file_name, "w"); if (!skeleton) { if (semantic_parser) @@ -992,7 +993,9 @@ output_master_parser (void) skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE); } muscle_insert ("skeleton", skeleton); - output_parser (skeleton, &table_obstack); + + output_parser (skeleton, parser); + xfclose (parser); } -- 2.45.2