Since we now use obstacks, more % directives can be enabled.

* src/lex.c (percent_table): Also accept `%yacc',
`%fixed_output_files', `%defines', `%no_parser', `%verbose', and
`%debug'.
Handle the actions for `%semantic_parser' and `%pure_parser' here,
instead of returning a token.
* src/lex.h (SEMANTIC_PARSER, PURE_PARSER): Remove, unused.
* src/reader.c (read_declarations): Adjust.
* src/files.c (open_files): Don't call `compute_base_names', don't
compute `attrsfile' since they depend upon data which might be
*in* the input file now.
(output_files): Do it here.
* src/output.c (output_headers): Document the fact that this patch
introduces a guaranteed SEGV for semantic parsers.
* doc/bison.texinfo: Document them.
* tests/suite.at: Exercise these %options.
This commit is contained in:
Akim Demaille
2001-01-18 14:47:09 +00:00
parent dde188fc64
commit 6deb44470e
14 changed files with 496 additions and 388 deletions

View File

@@ -245,12 +245,8 @@ compute_base_names (void)
void
open_files (void)
{
compute_base_names ();
finput = xfopen (infile, "r");
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
/* Initialize the obstacks. */
obstack_init (&action_obstack);
obstack_init (&attrs_obstack);
@@ -271,6 +267,9 @@ output_files (void)
{
xfclose (finput);
compute_base_names ();
attrsfile = stringappend (short_base_name, EXT_STYPE_H);
/* Output the main file. */
if (spec_outfile)
obstack_save (&table_obstack, spec_outfile);

View File

@@ -538,48 +538,47 @@ struct percent_table_struct
const char *name;
void *set_flag;
int retval;
}
percent_table[] =
};
struct percent_table_struct percent_table[] =
{
{ "token", NULL, TOKEN },
{ "term", NULL, TOKEN },
{ "nterm", NULL, NTERM },
{ "type", NULL, TYPE },
{ "guard", NULL, GUARD },
{ "union", NULL, UNION },
{ "expect", NULL, EXPECT },
{ "thong", NULL, THONG },
{ "start", NULL, START },
{ "left", NULL, LEFT },
{ "right", NULL, RIGHT },
{ "nonassoc", NULL, NONASSOC },
{ "binary", NULL, NONASSOC },
{ "semantic_parser", NULL, SEMANTIC_PARSER },
{ "pure_parser", NULL, PURE_PARSER },
{ "prec", NULL, PREC },
{ "locations", &locations_flag, NOOP}, /* -l */
{ "no_lines", &no_lines_flag, NOOP}, /* -l */
{ "raw", &raw_flag, NOOP }, /* -r */
{ "token_table", &token_table_flag, NOOP}, /* -k */
{ "token", NULL, TOKEN },
{ "term", NULL, TOKEN },
{ "nterm", NULL, NTERM },
{ "type", NULL, TYPE },
{ "guard", NULL, GUARD },
{ "union", NULL, UNION },
{ "expect", NULL, EXPECT },
{ "thong", NULL, THONG },
{ "start", NULL, START },
{ "left", NULL, LEFT },
{ "right", NULL, RIGHT },
{ "nonassoc", NULL, NONASSOC },
{ "binary", NULL, NONASSOC },
{ "prec", NULL, PREC },
{ "locations", &locations_flag, NOOP }, /* -l */
{ "no_lines", &no_lines_flag, NOOP }, /* -l */
{ "raw", &raw_flag, NOOP }, /* -r */
{ "token_table", &token_table_flag, NOOP }, /* -k */
{ "yacc", &yacc_flag, NOOP }, /* -y */
{ "fixed_output_files",&yacc_flag, NOOP }, /* -y */
{ "defines", &defines_flag, NOOP }, /* -d */
{ "no_parser", &no_parser_flag, NOOP }, /* -n */
#if 0
/* These can be utilized after main is reoganized so
open_files() is deferred 'til after read_declarations().
But %{ and %union both put information into files
that have to be opened before read_declarations().
*/
{ "yacc", &yacc_flag, NOOP}, /* -y */
{ "fixed_output_files", &yacc_flag, NOOP}, /* -y */
{ "defines", &defines_flag, NOOP}, /* -d */
{ "no_parser", &no_parser_flag, NOOP}, /* -n */
{ "output_file", &spec_outfile, SETOPT}, /* -o */
{ "file_prefix", &spec_file_prefix, SETOPT}, /* -b */
{ "name_prefix", &spec_name_prefix, SETOPT}, /* -p */
/* These would be acceptable, but they do not affect processing */
{ "verbose", &verbose_flag, NOOP}, /* -v */
{ "debug", &debug_flag, NOOP}, /* -t */
/* For the time being, this is not enabled yet, while it's possible
though, since we use obstacks. The only risk is with semantic
parsers which will output an `include' of an output file: be sure
that the naem included is indeed the name of the output file. */
{ "output_file", &spec_outfile, SETOPT }, /* -o */
{ "file_prefix", &spec_file_prefix, SETOPT }, /* -b */
{ "name_prefix", &spec_name_prefix, SETOPT }, /* -p */
#endif
{ "verbose", &verbose_flag, NOOP }, /* -v */
{ "debug", &debug_flag, NOOP }, /* -t */
{ "semantic_parser", &semantic_parser, NOOP },
{ "pure_parser", &pure_parser, NOOP },
/* {"help", <print usage stmt>, NOOP}, *//* -h */
/* {"version", <print version number> , NOOP}, *//* -V */
#endif
{ NULL, NULL, ILLEGAL}
};
@@ -646,6 +645,7 @@ parse_percent_token (void)
for (tx = percent_table; tx->name; tx++)
if (strcmp (token_buffer + 1, tx->name) == 0)
break;
if (tx->retval == SETOPT)
{
*((char **) (tx->set_flag)) = optarg;

View File

@@ -41,8 +41,6 @@
# define RIGHT 16
# define NONASSOC 17
# define PREC 18
# define SEMANTIC_PARSER 19
# define PURE_PARSER 20
# define TYPENAME 21
# define NUMBER 22
# define EXPECT 23

View File

@@ -223,10 +223,18 @@ register YYLTYPE *yylsp;\n\
void
output_headers (void)
{
char *attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile);
char *attrsfile_quoted = 0;
if (semantic_parser)
obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted);
{
/* FIXME: This is *buggy*. ATTRSFILE is not computed yet, since
we are waiting for the full input file to have been read to
be sure of the output file name. So basically, here, a SEGV
is guaranteed. OTOH, currently semantic parsers are not
supported. */
attrsfile_quoted = quotearg_style (c_quoting_style, attrsfile);
obstack_fgrow1 (&guard_obstack, GUARDSTR, attrsfile_quoted);
}
if (no_parser_flag)
return;

View File

@@ -931,6 +931,7 @@ read_declarations (void)
case EXPECT:
parse_expect_decl ();
break;
case THONG:
parse_thong_decl ();
break;
@@ -947,14 +948,6 @@ read_declarations (void)
parse_assoc_decl (non_assoc);
break;
case SEMANTIC_PARSER:
semantic_parser = 1;
break;
case PURE_PARSER:
pure_parser = 1;
break;
case NOOP:
break;