mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 15:53:03 +00:00
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.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
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>
|
2001-12-15 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
Attach actions to rules, instead of pre-outputting them to
|
Attach actions to rules, instead of pre-outputting them to
|
||||||
|
|||||||
14
src/files.c
14
src/files.c
@@ -30,7 +30,6 @@ FILE *finput = NULL;
|
|||||||
|
|
||||||
struct obstack action_obstack;
|
struct obstack action_obstack;
|
||||||
struct obstack attrs_obstack;
|
struct obstack attrs_obstack;
|
||||||
struct obstack table_obstack;
|
|
||||||
struct obstack defines_obstack;
|
struct obstack defines_obstack;
|
||||||
struct obstack guard_obstack;
|
struct obstack guard_obstack;
|
||||||
struct obstack output_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_verbose_file = NULL; /* for --verbose. */
|
||||||
char *spec_graph_file = NULL; /* for -g. */
|
char *spec_graph_file = NULL; /* for -g. */
|
||||||
char *spec_defines_file = NULL; /* for --defines. */
|
char *spec_defines_file = NULL; /* for --defines. */
|
||||||
|
char *parser_file_name = NULL;
|
||||||
|
|
||||||
char *infile = NULL;
|
char *infile = NULL;
|
||||||
char *attrsfile = NULL;
|
char *attrsfile = NULL;
|
||||||
@@ -433,6 +433,9 @@ compute_output_file_names (void)
|
|||||||
{
|
{
|
||||||
compute_base_names ();
|
compute_base_names ();
|
||||||
|
|
||||||
|
parser_file_name =
|
||||||
|
spec_outfile ? spec_outfile : stringappend (base_name, src_extension);
|
||||||
|
|
||||||
/* If not yet done. */
|
/* If not yet done. */
|
||||||
if (!src_extension)
|
if (!src_extension)
|
||||||
src_extension = ".c";
|
src_extension = ".c";
|
||||||
@@ -453,7 +456,6 @@ compute_output_file_names (void)
|
|||||||
#ifndef MSDOS
|
#ifndef MSDOS
|
||||||
attrsfile = stringappend (attrsfile, header_extension);
|
attrsfile = stringappend (attrsfile, header_extension);
|
||||||
#endif /* MSDOS */
|
#endif /* MSDOS */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------.
|
/*-----------------------------------------------------------------.
|
||||||
@@ -469,7 +471,6 @@ open_files (void)
|
|||||||
/* Initialize the obstacks. */
|
/* Initialize the obstacks. */
|
||||||
obstack_init (&action_obstack);
|
obstack_init (&action_obstack);
|
||||||
obstack_init (&attrs_obstack);
|
obstack_init (&attrs_obstack);
|
||||||
obstack_init (&table_obstack);
|
|
||||||
obstack_init (&defines_obstack);
|
obstack_init (&defines_obstack);
|
||||||
obstack_init (&guard_obstack);
|
obstack_init (&guard_obstack);
|
||||||
obstack_init (&output_obstack);
|
obstack_init (&output_obstack);
|
||||||
@@ -494,13 +495,6 @@ close_files (void)
|
|||||||
void
|
void
|
||||||
output_files (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. */
|
/* Output the header file if wanted. */
|
||||||
if (defines_flag)
|
if (defines_flag)
|
||||||
defines_obstack_save (spec_defines_file);
|
defines_obstack_save (spec_defines_file);
|
||||||
|
|||||||
16
src/files.h
16
src/files.h
@@ -1,7 +1,5 @@
|
|||||||
#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.
|
||||||
|
|
||||||
@@ -20,13 +18,15 @@
|
|||||||
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
Boston, MA 02111-1307, USA. */
|
Boston, MA 02111-1307, USA. */
|
||||||
|
|
||||||
/* These two should be pathnames for opening the sample parser files.
|
#ifndef FILES_H_
|
||||||
When bison is installed, they should be absolute pathnames.
|
# define FILES_H_
|
||||||
XPFILE1 and XPFILE2 normally come from config.h. */
|
|
||||||
|
|
||||||
/* File name specified with -o for the output file, or 0 if no -o. */
|
/* File name specified with -o for the output file, or 0 if no -o. */
|
||||||
extern char *spec_outfile;
|
extern char *spec_outfile;
|
||||||
|
|
||||||
|
/* File name for the parser (i.e., the one above, or its default.) */
|
||||||
|
extern char *parser_file_name;
|
||||||
|
|
||||||
/* For -a. */
|
/* For -a. */
|
||||||
extern const char *spec_name_prefix;
|
extern const char *spec_name_prefix;
|
||||||
|
|
||||||
@@ -49,10 +49,6 @@ extern FILE *finput;
|
|||||||
/* Output all the action code; precise form depends on which parser. */
|
/* Output all the action code; precise form depends on which parser. */
|
||||||
extern struct obstack action_obstack;
|
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. */
|
/* optionally output #define's for token numbers. */
|
||||||
extern struct obstack defines_obstack;
|
extern struct obstack defines_obstack;
|
||||||
|
|
||||||
|
|||||||
39
src/output.c
39
src/output.c
@@ -515,25 +515,25 @@ token_actions (void)
|
|||||||
`-----------------------------*/
|
`-----------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
actions_output (struct obstack *oout)
|
actions_output (FILE *out)
|
||||||
{
|
{
|
||||||
int rule;
|
int rule;
|
||||||
for (rule = 1; rule < nrules + 1; ++rule)
|
for (rule = 1; rule < nrules + 1; ++rule)
|
||||||
if (rule_table[rule].action)
|
if (rule_table[rule].action)
|
||||||
{
|
{
|
||||||
obstack_fgrow1 (oout, " case %d:\n", rule);
|
fprintf (out, " case %d:\n", rule);
|
||||||
|
|
||||||
if (!no_lines_flag)
|
if (!no_lines_flag)
|
||||||
obstack_fgrow2 (oout, muscle_find ("linef"),
|
fprintf (out, muscle_find ("linef"),
|
||||||
rule_table[rule].action_line,
|
rule_table[rule].action_line,
|
||||||
quotearg_style (c_quoting_style,
|
quotearg_style (c_quoting_style,
|
||||||
muscle_find ("filename")));
|
muscle_find ("filename")));
|
||||||
obstack_1grow (oout, '{');
|
|
||||||
obstack_sgrow (oout, rule_table[rule].action);
|
|
||||||
/* As a Bison extension, add the ending semicolon. Since some
|
/* As a Bison extension, add the ending semicolon. Since some
|
||||||
Yacc don't do that, help people using bison as a Yacc
|
Yacc don't do that, help people using bison as a Yacc
|
||||||
finding their missing semicolons. */
|
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
|
static void
|
||||||
output_parser (const char *skel_filename, struct obstack *oout)
|
output_parser (const char *skel_filename, FILE *out)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
FILE *fskel;
|
FILE *fskel;
|
||||||
@@ -941,7 +941,7 @@ output_parser (const char *skel_filename, struct obstack *oout)
|
|||||||
{
|
{
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
++line;
|
++line;
|
||||||
obstack_1grow (oout, c);
|
putc (c, out);
|
||||||
c = getc (fskel);
|
c = getc (fskel);
|
||||||
}
|
}
|
||||||
else if ((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_key = obstack_finish (&muscle_obstack);
|
||||||
muscle_value = muscle_find (muscle_key);
|
muscle_value = muscle_find (muscle_key);
|
||||||
if (!strcmp (muscle_key, "actions"))
|
if (!strcmp (muscle_key, "actions"))
|
||||||
actions_output (oout);
|
actions_output (out);
|
||||||
else if (!strcmp (muscle_key, "line"))
|
else if (!strcmp (muscle_key, "line"))
|
||||||
obstack_fgrow1 (oout, "%d", line + 1);
|
fprintf (out, "%d", line + 1);
|
||||||
else if (muscle_value)
|
else if (muscle_value)
|
||||||
obstack_sgrow (oout, muscle_value);
|
fputs (muscle_value, out);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
obstack_sgrow (oout, "%%");
|
fputs ("%%", out);
|
||||||
obstack_sgrow (oout, muscle_key);
|
fputs (muscle_key, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
obstack_1grow (oout, '%');
|
putc ('%', out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End. */
|
/* End. */
|
||||||
@@ -984,6 +984,7 @@ output_parser (const char *skel_filename, struct obstack *oout)
|
|||||||
static void
|
static void
|
||||||
output_master_parser (void)
|
output_master_parser (void)
|
||||||
{
|
{
|
||||||
|
FILE *parser = xfopen (parser_file_name, "w");
|
||||||
if (!skeleton)
|
if (!skeleton)
|
||||||
{
|
{
|
||||||
if (semantic_parser)
|
if (semantic_parser)
|
||||||
@@ -992,7 +993,9 @@ output_master_parser (void)
|
|||||||
skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
|
skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
|
||||||
}
|
}
|
||||||
muscle_insert ("skeleton", skeleton);
|
muscle_insert ("skeleton", skeleton);
|
||||||
output_parser (skeleton, &table_obstack);
|
|
||||||
|
output_parser (skeleton, parser);
|
||||||
|
xfclose (parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user