[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: Output parser file
From: |
Akim Demaille |
Subject: |
FYI: Output parser file |
Date: |
15 Dec 2001 15:30:13 +0100 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Civil Service) |
Index: ChangeLog
from Akim Demaille <address@hidden>
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.
Index: src/files.c
===================================================================
RCS file: /cvsroot/bison/bison/src/files.c,v
retrieving revision 1.56
diff -u -u -r1.56 files.c
--- src/files.c 10 Dec 2001 09:07:41 -0000 1.56
+++ src/files.c 15 Dec 2001 14:35:02 -0000
@@ -30,7 +30,6 @@
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 @@
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_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 @@
#ifndef MSDOS
attrsfile = stringappend (attrsfile, header_extension);
#endif /* MSDOS */
-
}
/*-----------------------------------------------------------------.
@@ -469,7 +471,6 @@
/* 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 @@
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);
Index: src/files.h
===================================================================
RCS file: /cvsroot/bison/bison/src/files.h,v
retrieving revision 1.20
diff -u -u -r1.20 files.h
--- src/files.h 10 Dec 2001 09:07:41 -0000 1.20
+++ src/files.h 15 Dec 2001 14:35:02 -0000
@@ -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;
@@ -48,10 +48,6 @@
/* 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;
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.89
diff -u -u -r1.89 output.c
--- src/output.c 15 Dec 2001 14:14:29 -0000 1.89
+++ src/output.c 15 Dec 2001 14:35:02 -0000
@@ -515,25 +515,25 @@
`-----------------------------*/
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 @@
`------------------------------------------------------------*/
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 @@
{
if (c == '\n')
++line;
- obstack_1grow (oout, c);
+ putc (c, out);
c = getc (fskel);
}
else if ((c = getc (fskel)) == '%')
@@ -958,19 +958,19 @@
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 @@
static void
output_master_parser (void)
{
+ FILE *parser = xfopen (parser_file_name, "w");
if (!skeleton)
{
if (semantic_parser)
@@ -992,7 +993,9 @@
skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
}
muscle_insert ("skeleton", skeleton);
- output_parser (skeleton, &table_obstack);
+
+ output_parser (skeleton, parser);
+ xfclose (parser);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: Output parser file,
Akim Demaille <=