mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-15 07:13:02 +00:00
* src/files.c, src/files.h (output_infix): New.
(tab_extension): Remove. (compute_base_names): Compute the former, drop the latter. * src/output.c (prepare): Insert the muscles `output-infix', and `output-suffix'. * src/parse-skel.y (string, string.1): New. (section.header): Use it. (section.yacc): Remove. (prefix): Remove too. * src/scan-skel.l: Adjust. * src/bison.simple, src/bison.hairy: Adjust.
This commit is contained in:
14
ChangeLog
14
ChangeLog
@@ -1,3 +1,17 @@
|
|||||||
|
2002-01-09 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/files.c, src/files.h (output_infix): New.
|
||||||
|
(tab_extension): Remove.
|
||||||
|
(compute_base_names): Compute the former, drop the latter.
|
||||||
|
* src/output.c (prepare): Insert the muscles `output-infix', and
|
||||||
|
`output-suffix'.
|
||||||
|
* src/parse-skel.y (string, string.1): New.
|
||||||
|
(section.header): Use it.
|
||||||
|
(section.yacc): Remove.
|
||||||
|
(prefix): Remove too.
|
||||||
|
* src/scan-skel.l: Adjust.
|
||||||
|
* src/bison.simple, src/bison.hairy: Adjust.
|
||||||
|
|
||||||
2002-01-09 Akim Demaille <akim@epita.fr>
|
2002-01-09 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* configure.in (WERROR_CFLAGS): Compute it.
|
* configure.in (WERROR_CFLAGS): Compute it.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
%%{section} %%{body} %%".c" %%{yacc}
|
%%{section} %%{output-prefix} %%{output-infix} %%".c"
|
||||||
/* -*- C -*- */
|
/* -*- C -*- */
|
||||||
|
|
||||||
/* YYERROR and YYCOST are set by guards. If yyerror is set to a
|
/* YYERROR and YYCOST are set by guards. If yyerror is set to a
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
%%{section} %%{body} %%".c" %%{yacc}
|
%%{section} %%{output-prefix} %%{output-infix} %%".c"
|
||||||
/* -*- C -*- */
|
/* -*- C -*- */
|
||||||
|
|
||||||
/* A Bison parser, made from %%{filename}
|
/* A Bison parser, made from %%{filename}
|
||||||
by GNU bison %%{version}. */
|
by GNU bison %%{version}. */
|
||||||
|
|
||||||
/* Skeleton output parser for bison,
|
/* Skeleton output parser for bison,
|
||||||
Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc.
|
Copyright 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|||||||
21
src/files.c
21
src/files.c
@@ -1,5 +1,6 @@
|
|||||||
/* Open and close files for bison,
|
/* Open and close files for bison,
|
||||||
Copyright 1984, 1986, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.
|
Copyright 1984, 1986, 1989, 1992, 2000, 2001, 2002
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -54,15 +55,18 @@ char *infile = NULL;
|
|||||||
char *attrsfile = NULL;
|
char *attrsfile = NULL;
|
||||||
|
|
||||||
static char *full_base_name = NULL;
|
static char *full_base_name = NULL;
|
||||||
|
|
||||||
|
/* Prefix used to generate output file names. */
|
||||||
char *short_base_name = NULL;
|
char *short_base_name = NULL;
|
||||||
|
|
||||||
|
/* Infix used to generate output file names (i.e., `.tab', or `_tab',
|
||||||
|
or `'). */
|
||||||
|
char *output_infix = NULL;
|
||||||
|
|
||||||
/* C source file extension (the parser source). */
|
/* C source file extension (the parser source). */
|
||||||
const char *src_extension = NULL;
|
const char *src_extension = NULL;
|
||||||
/* Header file extension (if option ``-d'' is specified). */
|
/* Header file extension (if option ``-d'' is specified). */
|
||||||
const char *header_extension = NULL;
|
const char *header_extension = NULL;
|
||||||
|
|
||||||
/* Should we insert '.tab' in yacc-compatible parsers? */
|
|
||||||
int tab_extension = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------.
|
/*--------------------------.
|
||||||
@@ -347,14 +351,16 @@ compute_base_names (void)
|
|||||||
full_base_name =
|
full_base_name =
|
||||||
xstrndup (spec_outfile,
|
xstrndup (spec_outfile,
|
||||||
(strlen (spec_outfile) - (ext ? strlen (ext) : 0)));
|
(strlen (spec_outfile) - (ext ? strlen (ext) : 0)));
|
||||||
|
|
||||||
/* The short base name goes up to TAB, excluding it. */
|
/* The short base name goes up to TAB, excluding it. */
|
||||||
short_base_name =
|
short_base_name =
|
||||||
xstrndup (spec_outfile,
|
xstrndup (spec_outfile,
|
||||||
(strlen (spec_outfile)
|
(strlen (spec_outfile)
|
||||||
- (tab ? strlen (tab) : (ext ? strlen (ext) : 0))));
|
- (tab ? strlen (tab) : (ext ? strlen (ext) : 0))));
|
||||||
|
|
||||||
/* Do we have a tab part? */
|
if (tab)
|
||||||
tab_extension = !!tab;
|
output_infix = xstrndup (tab,
|
||||||
|
(strlen (tab) - (ext ? strlen (ext) : 0)));
|
||||||
|
|
||||||
if (ext)
|
if (ext)
|
||||||
compute_exts_from_src (ext);
|
compute_exts_from_src (ext);
|
||||||
@@ -388,7 +394,8 @@ compute_base_names (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* In these cases, always append `.tab'. */
|
/* In these cases, always append `.tab'. */
|
||||||
tab_extension = 1;
|
output_infix = xstrdup (EXT_TAB);
|
||||||
|
|
||||||
full_base_name = XMALLOC (char,
|
full_base_name = XMALLOC (char,
|
||||||
strlen (short_base_name)
|
strlen (short_base_name)
|
||||||
+ strlen (EXT_TAB) + 1);
|
+ strlen (EXT_TAB) + 1);
|
||||||
|
|||||||
11
src/files.h
11
src/files.h
@@ -1,5 +1,5 @@
|
|||||||
/* File names and variables for bison,
|
/* File names and variables for bison,
|
||||||
Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
|
Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -76,10 +76,11 @@ int strsuffix (const char* string, const char* suffix);
|
|||||||
STRING1, and STRING2. */
|
STRING1, and STRING2. */
|
||||||
char* stringappend (const char* string1, const char* string2);
|
char* stringappend (const char* string1, const char* string2);
|
||||||
|
|
||||||
/* Should we insert '.tab' in yacc-compatible parsers? */
|
/* Prefix used to generate output file names. */
|
||||||
extern int tab_extension;
|
extern char *short_base_name;
|
||||||
|
|
||||||
/* Prefix used to generate output files names. */
|
/* Infix used to generate output file names (i.e., `.tab', or `_tab',
|
||||||
extern char* short_base_name;
|
or `'). */
|
||||||
|
extern char *output_infix;
|
||||||
|
|
||||||
#endif /* !FILES_H_ */
|
#endif /* !FILES_H_ */
|
||||||
|
|||||||
@@ -995,6 +995,11 @@ prepare (void)
|
|||||||
MUSCLE_INSERT_INT ("error-verbose", error_verbose);
|
MUSCLE_INSERT_INT ("error-verbose", error_verbose);
|
||||||
MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy");
|
MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy");
|
||||||
|
|
||||||
|
/* FIXME: This is wrong: the muscles should decide whether they hold
|
||||||
|
a copy or not, but the situation is too obscure currently. */
|
||||||
|
MUSCLE_INSERT_STRING ("output-infix", output_infix ? output_infix : "");
|
||||||
|
MUSCLE_INSERT_STRING ("output-prefix", short_base_name);
|
||||||
|
|
||||||
MUSCLE_INSERT_INT ("nnts", nvars);
|
MUSCLE_INSERT_INT ("nnts", nvars);
|
||||||
MUSCLE_INSERT_INT ("nrules", nrules);
|
MUSCLE_INSERT_INT ("nrules", nrules);
|
||||||
MUSCLE_INSERT_INT ("nstates", nstates);
|
MUSCLE_INSERT_INT ("nstates", nstates);
|
||||||
|
|||||||
@@ -44,7 +44,6 @@
|
|||||||
typed access to it. */
|
typed access to it. */
|
||||||
#define yycontrol ((skel_control_t *) skel_control)
|
#define yycontrol ((skel_control_t *) skel_control)
|
||||||
|
|
||||||
char* prefix = NULL;
|
|
||||||
FILE* parser = NULL;
|
FILE* parser = NULL;
|
||||||
|
|
||||||
size_t output_line;
|
size_t output_line;
|
||||||
@@ -87,14 +86,13 @@ static void yyprint (FILE *file, const yyltype *loc,
|
|||||||
%token LINE
|
%token LINE
|
||||||
%token SLINE
|
%token SLINE
|
||||||
|
|
||||||
%token YACC
|
|
||||||
%token SECTION
|
%token SECTION
|
||||||
|
|
||||||
%token GUARDS
|
%token GUARDS
|
||||||
%token TOKENS
|
%token TOKENS
|
||||||
%token ACTIONS
|
%token ACTIONS
|
||||||
|
|
||||||
%type <boolean> section.yacc
|
%type <string> string.1 string
|
||||||
|
|
||||||
%start input
|
%start input
|
||||||
|
|
||||||
@@ -110,43 +108,14 @@ skeleton : /* Empty. */ { }
|
|||||||
section : section.header section.body { }
|
section : section.header section.body { }
|
||||||
;
|
;
|
||||||
|
|
||||||
section.header : SECTION BLANKS MUSCLE BLANKS STRING BLANKS section.yacc '\n'
|
section.header : SECTION BLANKS string '\n'
|
||||||
{
|
{
|
||||||
char *name = 0;
|
char *name = $3;
|
||||||
char *limit = 0;
|
|
||||||
char *suffix = $5;
|
|
||||||
|
|
||||||
/* Close the previous parser. */
|
/* Close the previous parser. */
|
||||||
if (parser)
|
if (parser)
|
||||||
parser = (xfclose (parser), NULL);
|
parser = (xfclose (parser), NULL);
|
||||||
|
|
||||||
/* If the following section should be named with the yacc-style, and it's
|
|
||||||
suffix is of the form 'something.h' or 'something.c', then add '.tab' in
|
|
||||||
the middle of the suffix. */
|
|
||||||
if (tab_extension && $7 && (strsuffix (suffix, ".h") ||
|
|
||||||
strsuffix (suffix, ".c")))
|
|
||||||
{
|
|
||||||
size_t prefix_len = strlen (prefix);
|
|
||||||
size_t suffix_len = strlen (suffix);
|
|
||||||
|
|
||||||
/* Allocate enough space to insert '.tab'. */
|
|
||||||
name = XMALLOC (char, prefix_len + suffix_len + 5);
|
|
||||||
limit = strrchr (suffix, '.');
|
|
||||||
if (!limit)
|
|
||||||
limit = suffix;
|
|
||||||
|
|
||||||
/* Prefix is 'X', suffix is 'Y.Z'. Name will be 'XY.tab.Z'. */
|
|
||||||
{
|
|
||||||
char* cp = 0;
|
|
||||||
cp = stpcpy (name, prefix);
|
|
||||||
cp = stpncpy (cp, suffix, limit - suffix);
|
|
||||||
cp = stpcpy (cp, ".tab");
|
|
||||||
cp = stpcpy (cp, limit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
name = stringappend (prefix, suffix);
|
|
||||||
|
|
||||||
/* Prepare the next parser to be output. */
|
/* Prepare the next parser to be output. */
|
||||||
parser = xfopen (name, "w");
|
parser = xfopen (name, "w");
|
||||||
MUSCLE_INSERT_STRING ("parser-file-name", name);
|
MUSCLE_INSERT_STRING ("parser-file-name", name);
|
||||||
@@ -156,9 +125,20 @@ section.header : SECTION BLANKS MUSCLE BLANKS STRING BLANKS section.yacc '\n'
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
section.yacc : /* Empty. */ { $$ = 0; }
|
/* Either a literal string, or a muscle value. */
|
||||||
| YACC { $$ = 1; }
|
string.1:
|
||||||
;
|
STRING { $$ = $1; }
|
||||||
|
| MUSCLE { $$ = xstrdup (muscle_find ($1)); }
|
||||||
|
;
|
||||||
|
|
||||||
|
/* Either a literal string, or a muscle value, or the concatenation of
|
||||||
|
them. */
|
||||||
|
string:
|
||||||
|
string.1
|
||||||
|
{ $$ = $1; }
|
||||||
|
| string BLANKS string.1
|
||||||
|
{ $$ = stringappend ($1, $3); free ($1); free ($3); }
|
||||||
|
;
|
||||||
|
|
||||||
section.body
|
section.body
|
||||||
: /* Empty. */ { }
|
: /* Empty. */ { }
|
||||||
@@ -210,10 +190,6 @@ yyprint (FILE *file,
|
|||||||
case CHARACTER:
|
case CHARACTER:
|
||||||
fprintf (file, " = '%c'", value->character);
|
fprintf (file, " = '%c'", value->character);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case YACC:
|
|
||||||
fprintf (file, " = %s", value->boolean ? "true" : "false");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,10 +214,6 @@ skel_error (skel_control_t *control,
|
|||||||
void
|
void
|
||||||
process_skeleton (const char* skel)
|
process_skeleton (const char* skel)
|
||||||
{
|
{
|
||||||
/* Compute prefix. Actually, it seems that the processing I need here is
|
|
||||||
done in compute_base_names, and the result stored in short_base_name. */
|
|
||||||
prefix = short_base_name;
|
|
||||||
|
|
||||||
/* Prepare a few things. */
|
/* Prepare a few things. */
|
||||||
output_line = 1;
|
output_line = 1;
|
||||||
skeleton_line = 1;
|
skeleton_line = 1;
|
||||||
|
|||||||
@@ -50,7 +50,6 @@
|
|||||||
"%%{line}" { return LINE; }
|
"%%{line}" { return LINE; }
|
||||||
"%%{skeleton-line}" { return SLINE; }
|
"%%{skeleton-line}" { return SLINE; }
|
||||||
|
|
||||||
"%%{yacc}" { return YACC; }
|
|
||||||
"%%{section}" { return SECTION; }
|
"%%{section}" { return SECTION; }
|
||||||
|
|
||||||
"%%{guards}" { return GUARDS; }
|
"%%{guards}" { return GUARDS; }
|
||||||
|
|||||||
Reference in New Issue
Block a user