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 <akim@epita.fr>
+
+ 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 <akim@epita.fr>
Attach actions to rules, instead of pre-outputting them to
2001-12-15 Akim Demaille <akim@epita.fr>
Attach actions to rules, instead of pre-outputting them to
struct obstack action_obstack;
struct obstack attrs_obstack;
struct obstack action_obstack;
struct obstack attrs_obstack;
-struct obstack table_obstack;
struct obstack defines_obstack;
struct obstack guard_obstack;
struct obstack output_obstack;
struct obstack defines_obstack;
struct obstack guard_obstack;
struct obstack output_obstack;
char *spec_verbose_file = NULL; /* for --verbose. */
char *spec_graph_file = NULL; /* for -g. */
char *spec_defines_file = NULL; /* for --defines. */
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;
char *infile = NULL;
char *attrsfile = NULL;
+ parser_file_name =
+ spec_outfile ? spec_outfile : stringappend (base_name, src_extension);
+
/* If not yet done. */
if (!src_extension)
src_extension = ".c";
/* If not yet done. */
if (!src_extension)
src_extension = ".c";
#ifndef MSDOS
attrsfile = stringappend (attrsfile, header_extension);
#endif /* MSDOS */
#ifndef MSDOS
attrsfile = stringappend (attrsfile, header_extension);
#endif /* MSDOS */
}
/*-----------------------------------------------------------------.
}
/*-----------------------------------------------------------------.
/* Initialize the obstacks. */
obstack_init (&action_obstack);
obstack_init (&attrs_obstack);
/* 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);
obstack_init (&defines_obstack);
obstack_init (&guard_obstack);
obstack_init (&output_obstack);
void
output_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);
/* Output the header file if wanted. */
if (defines_flag)
defines_obstack_save (spec_defines_file);
-#ifndef FILES_H_
-# define FILES_H_
/* File names and variables for bison,
/* 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.
This file is part of Bison, the GNU Compiler Compiler.
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
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 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;
/* For -a. */
extern const char *spec_name_prefix;
/* Output all the action code; precise form depends on which parser. */
extern struct obstack action_obstack;
/* 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;
/* optionally output #define's for token numbers. */
extern struct obstack defines_obstack;
`-----------------------------*/
static 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)
{
{
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);
- 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. */
/* 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 ? ";" : "");
`------------------------------------------------------------*/
static void
`------------------------------------------------------------*/
static void
-output_parser (const char *skel_filename, struct obstack *oout)
+output_parser (const char *skel_filename, FILE *out)
- obstack_1grow (oout, c);
c = getc (fskel);
}
else if ((c = getc (fskel)) == '%')
c = getc (fskel);
}
else if ((c = getc (fskel)) == '%')
muscle_key = obstack_finish (&muscle_obstack);
muscle_value = muscle_find (muscle_key);
if (!strcmp (muscle_key, "actions"))
muscle_key = obstack_finish (&muscle_obstack);
muscle_value = muscle_find (muscle_key);
if (!strcmp (muscle_key, "actions"))
else if (!strcmp (muscle_key, "line"))
else if (!strcmp (muscle_key, "line"))
- obstack_fgrow1 (oout, "%d", line + 1);
+ fprintf (out, "%d", line + 1);
- obstack_sgrow (oout, muscle_value);
+ fputs (muscle_value, out);
- obstack_sgrow (oout, "%%");
- obstack_sgrow (oout, muscle_key);
+ fputs ("%%", out);
+ fputs (muscle_key, out);
- obstack_1grow (oout, '%');
static void
output_master_parser (void)
{
static void
output_master_parser (void)
{
+ FILE *parser = xfopen (parser_file_name, "w");
if (!skeleton)
{
if (semantic_parser)
if (!skeleton)
{
if (semantic_parser)
skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
}
muscle_insert ("skeleton", skeleton);
skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
}
muscle_insert ("skeleton", skeleton);
- output_parser (skeleton, &table_obstack);
+
+ output_parser (skeleton, parser);
+ xfclose (parser);