Rename %before-definitions to %start-header and %after-definitions to

%end-header.  Don't use these declarations to separate pre-prologue
blocks from post-prologue blocks.  Add new order-independent
declarations %before-header and %after-header as alternatives to the
traditional Yacc pre-prologue and post-prologue blocks.  Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00110.html>.
* NEWS (2.3+): Update for these changes.
* data/glr.c (b4_before_definitions): Update to...
(b4_start_header): ... this.
(b4_after_definitions): Update to...
(b4_end_header): ... this.
* data/glr.cc: Likewise.
* data/lalr1.cc: Likewise.
* data/yacc.c: Likewise.
* doc/bison.texinfo (The prologue): Update names, and replace remaining
prologue blocks with %*-header declarations.
(Calc++ Parser): Likewise.
(Bison Declaration Summary): Update names.
(Bison Symbols): Update description.
* src/parse-gram.y (PERCENT_AFTER_DEFINITIONS): Update to...
(PERCENT_END_HEADER): ... this.
(PERCENT_BEFORE_DEFINITIONS): Update to...
(PERCENT_START_HEADER): ... this.
(PERCENT_AFTER_HEADER, PERCENT_BEFORE_HEADER): New tokens.
(declaration): Update token names and m4 macro names.
When parsing %end-header and %start-header, invoke translate_code
before muscle_code_grow, and no longer set global booleans to remember
whether these declarations have been seen.
Parse new %after-header and %before-header.
* src/reader.c (before_definitions, after_definitions): Remove.
(prologue_augment): Accept a new bool argument to specify whether to
augment the pre-prologue or post-prologue.
* src/reader.h (before_definitions, after_definitions): Remove these
extern's.
(prologue_augment): Add new bool argument.
* src/scan-gram.l (PERCENT_AFTER_DEFINITIONS): Update to...
(PERCENT_END_HEADER): ... this.
(PERCENT_BEFORE_DEFINITIONS): Update to...
(PERCENT_START_HEADER): ... this.
(PERCENT_AFTER_HEADER, PERCENT_BEFORE_HEADER): New tokens.
* tests/actions.at (Printers and Destructors): Update names.
This commit is contained in:
Joel E. Denny
2006-06-23 20:17:28 +00:00
parent 31b2b07ef7
commit 34f98f46ee
14 changed files with 737 additions and 617 deletions

View File

@@ -1,3 +1,47 @@
2006-06-23 Joel E. Denny <jdenny@ces.clemson.edu>
Rename %before-definitions to %start-header and %after-definitions to
%end-header. Don't use these declarations to separate pre-prologue
blocks from post-prologue blocks. Add new order-independent
declarations %before-header and %after-header as alternatives to the
traditional Yacc pre-prologue and post-prologue blocks. Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00110.html>.
* NEWS (2.3+): Update for these changes.
* data/glr.c (b4_before_definitions): Update to...
(b4_start_header): ... this.
(b4_after_definitions): Update to...
(b4_end_header): ... this.
* data/glr.cc: Likewise.
* data/lalr1.cc: Likewise.
* data/yacc.c: Likewise.
* doc/bison.texinfo (The prologue): Update names, and replace remaining
prologue blocks with %*-header declarations.
(Calc++ Parser): Likewise.
(Bison Declaration Summary): Update names.
(Bison Symbols): Update description.
* src/parse-gram.y (PERCENT_AFTER_DEFINITIONS): Update to...
(PERCENT_END_HEADER): ... this.
(PERCENT_BEFORE_DEFINITIONS): Update to...
(PERCENT_START_HEADER): ... this.
(PERCENT_AFTER_HEADER, PERCENT_BEFORE_HEADER): New tokens.
(declaration): Update token names and m4 macro names.
When parsing %end-header and %start-header, invoke translate_code
before muscle_code_grow, and no longer set global booleans to remember
whether these declarations have been seen.
Parse new %after-header and %before-header.
* src/reader.c (before_definitions, after_definitions): Remove.
(prologue_augment): Accept a new bool argument to specify whether to
augment the pre-prologue or post-prologue.
* src/reader.h (before_definitions, after_definitions): Remove these
extern's.
(prologue_augment): Add new bool argument.
* src/scan-gram.l (PERCENT_AFTER_DEFINITIONS): Update to...
(PERCENT_END_HEADER): ... this.
(PERCENT_BEFORE_DEFINITIONS): Update to...
(PERCENT_START_HEADER): ... this.
(PERCENT_AFTER_HEADER, PERCENT_BEFORE_HEADER): New tokens.
* tests/actions.at (Printers and Destructors): Update names.
2006-06-22 Joel E. Denny <jdenny@ces.clemson.edu> 2006-06-22 Joel E. Denny <jdenny@ces.clemson.edu>
Add comparison operators for C++ location classes. Discussed at Add comparison operators for C++ location classes. Discussed at

78
NEWS
View File

@@ -9,18 +9,16 @@ Changes in version 2.3+:
helps to sanitize the global namespace during preprocessing, but POSIX Yacc helps to sanitize the global namespace during preprocessing, but POSIX Yacc
requires them. Bison still generates an enum for token names in all cases. requires them. Bison still generates an enum for token names in all cases.
* Handling of prologue blocks is now more consistent but potentially backward * Handling of traditional Yacc prologue blocks is now more consistent but
incompatible. potentially incompatible with previous releases of Bison.
As before, you declare prologue blocks in your grammar file with the As before, you declare prologue blocks in your grammar file with the
`%{ ... %}' syntax. To generate the pre-prologue, Bison concatenates all `%{ ... %}' syntax. To generate the pre-prologue, Bison concatenates all
prologue blocks that you've declared before any %union. If you've declared a prologue blocks that you've declared before the first %union. To generate
%union, Bison concatenates all prologue blocks that you've declared after it the post-prologue, Bison concatenates all prologue blocks that you've
to generate the post-prologue. (The new %before-definitions and declared after the first %union.
%after-definitions have a similar effect as %union on the prologues. See
below.)
Previous versions of Bison inserted the pre-prologue into both the header Previous releases of Bison inserted the pre-prologue into both the header
file and the code file in all cases except for LALR(1) parsers in C. In the file and the code file in all cases except for LALR(1) parsers in C. In the
latter case, Bison inserted it only into the code file. For parsers in C++, latter case, Bison inserted it only into the code file. For parsers in C++,
the point of insertion was before any token definitions (which associate the point of insertion was before any token definitions (which associate
@@ -30,38 +28,50 @@ Changes in version 2.3+:
Now, Bison never inserts the pre-prologue into the header file. In the code Now, Bison never inserts the pre-prologue into the header file. In the code
file, it always inserts it before the token definitions. file, it always inserts it before the token definitions.
* Bison now provides the %before-definitions and %after-definitions directives. * Bison now provides a more flexible alternative to the traditional Yacc
prologue blocks: %before-header, %start-header, %end-header, and
%after-header.
For example, in your grammar file: For example, the following declaration order in the grammar file reflects the
order in which Bison will output these code blocks. However, you are free to
declare these code blocks in your grammar file in whatever order is most
convenient for you:
%{ %before-header {
/* A pre-prologue block. For Yacc portability, Bison no longer puts this /* Bison treats this block like a pre-prologue block: it inserts it into
* in the header file. In the code file, Bison inserts it before any * the code file before the contents of the header file. It does *not*
* %before-definitions blocks. */ * insert it into the header file. This is a good place to put
%} * #include's that you want at the top of your code file. A common
%before-definitions { * example is `#include "system.h"'. */
/* Bison inserts this into both the header file and code file. In both }
* files, the point of insertion is before any Bison-generated token, %start-header {
* semantic type, location type, and class definitions. This is a good /* Bison inserts this block into both the header file and the code file.
* place to define %union dependencies, for example. */ * In both files, the point of insertion is before any Bison-generated
* token, semantic type, location type, and class definitions. This is a
* good place to define %union dependencies, for example. */
} }
%union { %union {
/* With previous versions of Bison, the first %union in your grammar file /* Unlike the traditional Yacc prologue blocks, the output order for the
* separated the pre-prologue blocks from the post-prologue blocks. Now, * new %*-header blocks is not affected by their declaration position
* the first %union, %before-definitions, or %after-definitions does * relative to any %union in the grammar file. */
* that. */
} }
%after-definitions { %end-header {
/* If you want something in the header file and in the code file and it /* Bison inserts this block into both the header file and the code file.
* depends on any of the Bison-generated definitions in the header file, * In both files, the point of insertion is after the Bison-generated
* put it here. */ * definitions. This is a good place to declare or define public
* functions or data structures that depend on the Bison-generated
* definitions. */
} }
%{ %after-header {
/* A post-prologue block. If you want something in the code file but not /* Bison treats this block like a post-prologue block: it inserts it into
* in the header file and it depends on Bison-generated definitions, put * the code file after the contents of the header file. It does *not*
* it here. In the code file, Bison inserts it after any * insert it into the header file. This is a good place to declare or
* %after-definitions blocks. */ * define internal functions or data structures that depend on the
%} * Bison-generated definitions. */
}
If you have multiple occurrences of any one of the above declarations, Bison
will concatenate the contents in declaration order.
* The option `--report=look-ahead' has been changed to `--report=lookahead'. * The option `--report=look-ahead' has been changed to `--report=lookahead'.
The old spelling still works, but is not documented and may be removed The old spelling still works, but is not documented and may be removed

View File

@@ -169,9 +169,9 @@ dnl # ----------------------
dnl # Declaration that might either go into the header (if --defines) dnl # Declaration that might either go into the header (if --defines)
dnl # or open coded in the parser body. dnl # or open coded in the parser body.
m4_define([b4_shared_declarations], m4_define([b4_shared_declarations],
[m4_ifdef([b4_before_definitions], [m4_ifdef([b4_start_header],
[[/* Copy the %before-definitions blocks. */ [[/* Copy the %start-header blocks. */
]b4_before_definitions])[]dnl ]b4_start_header])[]dnl
b4_token_enums(b4_tokens) b4_token_enums(b4_tokens)
@@ -203,9 +203,9 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1 # define YYLTYPE_IS_TRIVIAL 1
#endif #endif
]m4_ifdef([b4_after_definitions], ]m4_ifdef([b4_end_header],
[[/* Copy the %after-definitions blocks. */ [[/* Copy the %end-header blocks. */
]b4_after_definitions])[]dnl ]b4_end_header])[]dnl
]) ])
b4_defines_if([#include @output_header_name@], b4_defines_if([#include @output_header_name@],

View File

@@ -235,9 +235,9 @@ namespace ]b4_namespace[
class location; class location;
} }
]m4_ifdef([b4_before_definitions], ]m4_ifdef([b4_start_header],
[[/* Copy the %before-definitions blocks. */ [[/* Copy the %start-header blocks. */
]b4_before_definitions])[]dnl ]b4_start_header])[]dnl
[/* Line __line__ of glr.cc. */ [/* Line __line__ of glr.cc. */
]b4_syncline([@oline@], [@ofile@])[ ]b4_syncline([@oline@], [@ofile@])[
@@ -386,8 +386,8 @@ m4_ifset([b4_global_tokens_and_yystype],
} }
]m4_ifdef([b4_after_definitions], ]m4_ifdef([b4_end_header],
[[/* Copy the %after-definitions blocks. */ [[/* Copy the %end-header blocks. */
]b4_after_definitions])[]dnl ]b4_end_header])[]dnl
[#endif /* ! defined PARSER_HEADER_H */] [#endif /* ! defined PARSER_HEADER_H */]

View File

@@ -53,9 +53,9 @@ namespace ]b4_namespace[
class location; class location;
} }
]m4_ifdef([b4_before_definitions], ]m4_ifdef([b4_start_header],
[[/* Copy the %before-definitions blocks. */ [[/* Copy the %start-header blocks. */
]b4_before_definitions])[]dnl ]b4_start_header])[]dnl
[/* Line __line__ of lalr1.cc. */ [/* Line __line__ of lalr1.cc. */
]b4_syncline([@oline@], [@ofile@])[ ]b4_syncline([@oline@], [@ofile@])[
@@ -300,9 +300,9 @@ b4_error_verbose_if([, int tok])[);
# define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type # define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
#endif #endif
]) ])
m4_ifdef([b4_after_definitions], m4_ifdef([b4_end_header],
[[/* Copy the %after-definitions blocks. */ [[/* Copy the %end-header blocks. */
]b4_after_definitions])[]dnl ]b4_end_header])[]dnl
[#endif /* ! defined PARSER_HEADER_H */] [#endif /* ! defined PARSER_HEADER_H */]
])dnl ])dnl

View File

@@ -181,9 +181,9 @@ b4_locations_if([#define yylloc b4_prefix[]lloc])])[
# define YYTOKEN_TABLE ]b4_token_table[ # define YYTOKEN_TABLE ]b4_token_table[
#endif #endif
]m4_ifdef([b4_before_definitions], ]m4_ifdef([b4_start_header],
[[/* Copy the %before-definitions blocks. */ [[/* Copy the %start-header blocks. */
]b4_before_definitions])[]dnl ]b4_start_header])[]dnl
b4_token_enums_defines(b4_tokens)[ b4_token_enums_defines(b4_tokens)[
@@ -213,9 +213,9 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1 # define YYLTYPE_IS_TRIVIAL 1
#endif]) #endif])
m4_ifdef([b4_after_definitions], m4_ifdef([b4_end_header],
[[/* Copy the %after-definitions blocks. */ [[/* Copy the %end-header blocks. */
]b4_after_definitions])[]dnl ]b4_end_header])[]dnl
[/* Copy the second part of user declarations. */ [/* Copy the second part of user declarations. */
]b4_post_prologue ]b4_post_prologue
@@ -1498,9 +1498,9 @@ b4_defines_if(
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl ' b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006]) [1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
m4_ifdef([b4_before_definitions], m4_ifdef([b4_start_header],
[[/* Copy the %before-definitions blocks. */ [[/* Copy the %start-header blocks. */
]b4_before_definitions])[]dnl ]b4_start_header])[]dnl
b4_token_enums_defines(b4_tokens) b4_token_enums_defines(b4_tokens)
@@ -1538,7 +1538,7 @@ typedef struct YYLTYPE
[extern YYLTYPE b4_prefix[]lloc;]) [extern YYLTYPE b4_prefix[]lloc;])
)dnl b4_locations_if )dnl b4_locations_if
m4_ifdef([b4_after_definitions], m4_ifdef([b4_end_header],
[[/* Copy the %after-definitions blocks. */ [[/* Copy the %end-header blocks. */
]b4_after_definitions])[]dnl ]b4_end_header])[]dnl
])dnl b4_defines_if ])dnl b4_defines_if

View File

@@ -2664,19 +2664,22 @@ can be done with two @var{Prologue} blocks, one before and one after the
@dots{} @dots{}
@end smallexample @end smallexample
@findex %before-definitions @findex %before-header
@findex %start-header
@findex %after-header
If you've instructed Bison to generate a header file (@pxref{Table of Symbols, If you've instructed Bison to generate a header file (@pxref{Table of Symbols,
,%defines}), you probably want @code{#include "ptypes.h"} to appear ,%defines}), you probably want @code{#include "ptypes.h"} to appear
in that header file as well. in that header file as well.
In that case, use @code{%before-definitions} instead of a @var{Prologue} In that case, use @code{%before-header}, @code{%start-header}, and
section (@pxref{Table of Symbols, ,%before-definitions}): @code{%after-header} instead of @var{Prologue} sections
(@pxref{Table of Symbols, ,%start-header}):
@smallexample @smallexample
%@{ %before-header @{
#include <stdio.h> #include <stdio.h>
%@} @}
%before-definitions @{ %start-header @{
#include "ptypes.h" #include "ptypes.h"
@} @}
%union @{ %union @{
@@ -2684,10 +2687,10 @@ section (@pxref{Table of Symbols, ,%before-definitions}):
tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */ tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */
@} @}
%@{ %after-header @{
static void print_token_value (FILE *, int, YYSTYPE); static void print_token_value (FILE *, int, YYSTYPE);
#define YYPRINT(F, N, L) print_token_value (F, N, L) #define YYPRINT(F, N, L) print_token_value (F, N, L)
%@} @}
@dots{} @dots{}
@end smallexample @end smallexample
@@ -4228,11 +4231,11 @@ typically needs to be able to refer to the above-mentioned declarations
and to the token type codes. @xref{Token Values, ,Semantic Values of and to the token type codes. @xref{Token Values, ,Semantic Values of
Tokens}. Tokens}.
@findex %before-definitions @findex %start-header
@findex %after-definitions @findex %end-header
If you have declared @code{%before-definitions} or @code{%after-definitions}, If you have declared @code{%start-header} or @code{%end-header}, the output
the output header also contains their code. header also contains their code.
@xref{Table of Symbols, ,%before-definitions}. @xref{Table of Symbols, ,%start-header}.
@end deffn @end deffn
@deffn {Directive} %destructor @deffn {Directive} %destructor
@@ -7462,18 +7465,18 @@ the grammar for.
@end example @end example
@noindent @noindent
@findex %before-definitions @findex %start-header
Then come the declarations/inclusions needed to define the Then come the declarations/inclusions needed to define the
@code{%union}. Because the parser uses the parsing driver and @code{%union}. Because the parser uses the parsing driver and
reciprocally, both cannot include the header of the other. Because the reciprocally, both cannot include the header of the other. Because the
driver's header needs detailed knowledge about the parser class (in driver's header needs detailed knowledge about the parser class (in
particular its inner types), it is the parser's header which will simply particular its inner types), it is the parser's header which will simply
use a forward declaration of the driver. use a forward declaration of the driver.
@xref{Table of Symbols, ,%before-definitions}. @xref{Table of Symbols, ,%start-header}.
@comment file: calc++-parser.yy @comment file: calc++-parser.yy
@example @example
%before-definitions @{ %start-header @{
# include <string> # include <string>
class calcxx_driver; class calcxx_driver;
@} @}
@@ -7532,15 +7535,15 @@ them.
@end example @end example
@noindent @noindent
The code between @samp{%@{} and @samp{%@}} after the introduction of the @findex %after-header
@samp{%union} is output in the @file{*.cc} file; it needs detailed The code between @samp{%after-header @{} and @samp{@}} is output in the
knowledge about the driver. @file{*.cc} file; it needs detailed knowledge about the driver.
@comment file: calc++-parser.yy @comment file: calc++-parser.yy
@example @example
%@{ %after-header @{
# include "calc++-driver.hh" # include "calc++-driver.hh"
%@} @}
@end example @end example
@@ -8208,54 +8211,79 @@ $end}, where @var{start} is the start symbol. @xref{Start Decl, , The
Start-Symbol}. It cannot be used in the grammar. Start-Symbol}. It cannot be used in the grammar.
@end deffn @end deffn
@deffn {Directive} %after-definitions @{@var{code}@} @deffn {Directive} %after-header @{@var{code}@}
Specifies code to be inserted into the code file after the contents of the
header file.
@xref{Table of Symbols, ,%start-header}.
@end deffn
@deffn {Directive} %before-header @{@var{code}@}
Specifies code to be inserted into the code file before the contents of the
header file.
@xref{Table of Symbols, ,%start-header}.
@end deffn
@deffn {Directive} %end-header @{@var{code}@}
Specifies code to be inserted both into the header file (if generated; Specifies code to be inserted both into the header file (if generated;
@pxref{Table of Symbols, ,%defines}) and into the code file after any @pxref{Table of Symbols, ,%defines}) and into the code file after any
Bison-generated definitions. Bison-generated definitions.
For details, @xref{Table of Symbols, ,%before-definitions}. @xref{Table of Symbols, ,%start-header}.
@end deffn @end deffn
@deffn {Directive} %before-definitions @{@var{code}@} @deffn {Directive} %start-header @{@var{code}@}
Specifies code to be inserted both into the header file (if generated; Specifies code to be inserted both into the header file (if generated;
@pxref{Table of Symbols, ,%defines}) and into the code file before any @pxref{Table of Symbols, ,%defines}) and into the code file before any
Bison-generated definitions. Bison-generated definitions.
@cindex Prologue @cindex Prologue
@findex %after-definitions @findex %before-header
@findex %union @findex %union
For example, in your grammar file: @findex %end-header
@findex %after-header
For example, the following declaration order in the grammar file reflects the
order in which Bison will output these code blocks. However, you are free to
declare these code blocks in your grammar file in whatever order is most
convenient for you:
@smallexample @smallexample
%@{ %before-header @{
/* A pre-prologue block. For Yacc portability, Bison does not put /* Bison treats this block like a pre-prologue block: it inserts it
* this in the header file. In the code file, Bison inserts it * into the code file before the contents of the header file. It
* before any %before-definitions blocks. */ * does *not* insert it into the header file. This is a good place
%@} * to put #include's that you want at the top of your code file. A
%before-definitions @{ * common example is `#include "system.h"'. */
/* Bison inserts this into both the header file and code file. In @}
* both files, the point of insertion is before any Bison-generated %start-header @{
* token, semantic type, location type, and class definitions. /* Bison inserts this block into both the header file and the code
* This is a good place to define %union dependencies, for * file. In both files, the point of insertion is before any
* example. */ * Bison-generated token, semantic type, location type, and class
* definitions. This is a good place to define %union
* dependencies, for example. */
@} @}
%union @{ %union @{
/* The first %union, %before-definitions, or %after-definitions /* Unlike the traditional Yacc prologue blocks, the output order
* in your grammar file separates the pre-prologue blocks from the * for the %*-header blocks is not affected by their declaration
* post-prologue blocks. */ * position relative to any %union in the grammar file. */
@} @}
%after-definitions @{ %end-header @{
/* If you want something in the header file and in the code file /* Bison inserts this block into both the header file and the code
* and it depends on any of the Bison-generated definitions in the * file. In both files, the point of insertion is after the
* header file, put it here. */ * Bison-generated definitions. This is a good place to declare or
* define public functions or data structures that depend on the
* Bison-generated definitions. */
@}
%after-header @{
/* Bison treats this block like a post-prologue block: it inserts
* it into the code file after the contents of the header file. It
* does *not* insert it into the header file. This is a good place
* to declare or define internal functions or data structures that
* depend on the Bison-generated definitions. */
@} @}
%@{
/* A post-prologue block. If you want something in the code file
* but not in the header file and it depends on Bison-generated
* definitions, put it here. In the code file, Bison inserts it
* after any %after-definitions blocks. */
%@}
@end smallexample @end smallexample
If you have multiple occurrences of any one of the above declarations, Bison
will concatenate the contents in declaration order.
@xref{Prologue, ,The Prologue}. @xref{Prologue, ,The Prologue}.
@end deffn @end deffn

File diff suppressed because it is too large Load Diff

View File

@@ -54,45 +54,47 @@
PERCENT_PREC = 268, PERCENT_PREC = 268,
PERCENT_DPREC = 269, PERCENT_DPREC = 269,
PERCENT_MERGE = 270, PERCENT_MERGE = 270,
PERCENT_AFTER_DEFINITIONS = 271, PERCENT_AFTER_HEADER = 271,
PERCENT_BEFORE_DEFINITIONS = 272, PERCENT_BEFORE_HEADER = 272,
PERCENT_DEBUG = 273, PERCENT_DEBUG = 273,
PERCENT_DEFAULT_PREC = 274, PERCENT_DEFAULT_PREC = 274,
PERCENT_DEFINE = 275, PERCENT_DEFINE = 275,
PERCENT_DEFINES = 276, PERCENT_DEFINES = 276,
PERCENT_ERROR_VERBOSE = 277, PERCENT_END_HEADER = 277,
PERCENT_EXPECT = 278, PERCENT_ERROR_VERBOSE = 278,
PERCENT_EXPECT_RR = 279, PERCENT_EXPECT = 279,
PERCENT_FILE_PREFIX = 280, PERCENT_EXPECT_RR = 280,
PERCENT_GLR_PARSER = 281, PERCENT_FILE_PREFIX = 281,
PERCENT_INITIAL_ACTION = 282, PERCENT_GLR_PARSER = 282,
PERCENT_LEX_PARAM = 283, PERCENT_INITIAL_ACTION = 283,
PERCENT_LOCATIONS = 284, PERCENT_LEX_PARAM = 284,
PERCENT_NAME_PREFIX = 285, PERCENT_LOCATIONS = 285,
PERCENT_NO_DEFAULT_PREC = 286, PERCENT_NAME_PREFIX = 286,
PERCENT_NO_LINES = 287, PERCENT_NO_DEFAULT_PREC = 287,
PERCENT_NONDETERMINISTIC_PARSER = 288, PERCENT_NO_LINES = 288,
PERCENT_OUTPUT = 289, PERCENT_NONDETERMINISTIC_PARSER = 289,
PERCENT_PARSE_PARAM = 290, PERCENT_OUTPUT = 290,
PERCENT_PURE_PARSER = 291, PERCENT_PARSE_PARAM = 291,
PERCENT_REQUIRE = 292, PERCENT_PURE_PARSER = 292,
PERCENT_SKELETON = 293, PERCENT_REQUIRE = 293,
PERCENT_START = 294, PERCENT_SKELETON = 294,
PERCENT_TOKEN_TABLE = 295, PERCENT_START = 295,
PERCENT_VERBOSE = 296, PERCENT_START_HEADER = 296,
PERCENT_YACC = 297, PERCENT_TOKEN_TABLE = 297,
BRACED_CODE = 298, PERCENT_VERBOSE = 298,
CHAR = 299, PERCENT_YACC = 299,
EPILOGUE = 300, BRACED_CODE = 300,
EQUAL = 301, CHAR = 301,
ID = 302, EPILOGUE = 302,
ID_COLON = 303, EQUAL = 303,
PERCENT_PERCENT = 304, ID = 304,
PIPE = 305, ID_COLON = 305,
PROLOGUE = 306, PERCENT_PERCENT = 306,
SEMICOLON = 307, PIPE = 307,
TYPE = 308, PROLOGUE = 308,
PERCENT_UNION = 309 SEMICOLON = 309,
TYPE = 310,
PERCENT_UNION = 311
}; };
#endif #endif
/* Tokens. */ /* Tokens. */
@@ -110,45 +112,47 @@
#define PERCENT_PREC 268 #define PERCENT_PREC 268
#define PERCENT_DPREC 269 #define PERCENT_DPREC 269
#define PERCENT_MERGE 270 #define PERCENT_MERGE 270
#define PERCENT_AFTER_DEFINITIONS 271 #define PERCENT_AFTER_HEADER 271
#define PERCENT_BEFORE_DEFINITIONS 272 #define PERCENT_BEFORE_HEADER 272
#define PERCENT_DEBUG 273 #define PERCENT_DEBUG 273
#define PERCENT_DEFAULT_PREC 274 #define PERCENT_DEFAULT_PREC 274
#define PERCENT_DEFINE 275 #define PERCENT_DEFINE 275
#define PERCENT_DEFINES 276 #define PERCENT_DEFINES 276
#define PERCENT_ERROR_VERBOSE 277 #define PERCENT_END_HEADER 277
#define PERCENT_EXPECT 278 #define PERCENT_ERROR_VERBOSE 278
#define PERCENT_EXPECT_RR 279 #define PERCENT_EXPECT 279
#define PERCENT_FILE_PREFIX 280 #define PERCENT_EXPECT_RR 280
#define PERCENT_GLR_PARSER 281 #define PERCENT_FILE_PREFIX 281
#define PERCENT_INITIAL_ACTION 282 #define PERCENT_GLR_PARSER 282
#define PERCENT_LEX_PARAM 283 #define PERCENT_INITIAL_ACTION 283
#define PERCENT_LOCATIONS 284 #define PERCENT_LEX_PARAM 284
#define PERCENT_NAME_PREFIX 285 #define PERCENT_LOCATIONS 285
#define PERCENT_NO_DEFAULT_PREC 286 #define PERCENT_NAME_PREFIX 286
#define PERCENT_NO_LINES 287 #define PERCENT_NO_DEFAULT_PREC 287
#define PERCENT_NONDETERMINISTIC_PARSER 288 #define PERCENT_NO_LINES 288
#define PERCENT_OUTPUT 289 #define PERCENT_NONDETERMINISTIC_PARSER 289
#define PERCENT_PARSE_PARAM 290 #define PERCENT_OUTPUT 290
#define PERCENT_PURE_PARSER 291 #define PERCENT_PARSE_PARAM 291
#define PERCENT_REQUIRE 292 #define PERCENT_PURE_PARSER 292
#define PERCENT_SKELETON 293 #define PERCENT_REQUIRE 293
#define PERCENT_START 294 #define PERCENT_SKELETON 294
#define PERCENT_TOKEN_TABLE 295 #define PERCENT_START 295
#define PERCENT_VERBOSE 296 #define PERCENT_START_HEADER 296
#define PERCENT_YACC 297 #define PERCENT_TOKEN_TABLE 297
#define BRACED_CODE 298 #define PERCENT_VERBOSE 298
#define CHAR 299 #define PERCENT_YACC 299
#define EPILOGUE 300 #define BRACED_CODE 300
#define EQUAL 301 #define CHAR 301
#define ID 302 #define EPILOGUE 302
#define ID_COLON 303 #define EQUAL 303
#define PERCENT_PERCENT 304 #define ID 304
#define PIPE 305 #define ID_COLON 305
#define PROLOGUE 306 #define PERCENT_PERCENT 306
#define SEMICOLON 307 #define PIPE 307
#define TYPE 308 #define PROLOGUE 308
#define PERCENT_UNION 309 #define SEMICOLON 309
#define TYPE 310
#define PERCENT_UNION 311
@@ -166,7 +170,7 @@ typedef union YYSTYPE
unsigned char character; unsigned char character;
} }
/* Line 1544 of yacc.c. */ /* Line 1544 of yacc.c. */
#line 170 "parse-gram.h" #line 174 "parse-gram.h"
YYSTYPE; YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1

View File

@@ -130,14 +130,13 @@ static int current_prec = 0;
`----------------------*/ `----------------------*/
%token %token
PERCENT_AFTER_DEFINITIONS PERCENT_AFTER_HEADER "%after-header"
"%after-definitions" PERCENT_BEFORE_HEADER "%before-header"
PERCENT_BEFORE_DEFINITIONS
"%before-definitions"
PERCENT_DEBUG "%debug" PERCENT_DEBUG "%debug"
PERCENT_DEFAULT_PREC "%default-prec" PERCENT_DEFAULT_PREC "%default-prec"
PERCENT_DEFINE "%define" PERCENT_DEFINE "%define"
PERCENT_DEFINES "%defines" PERCENT_DEFINES "%defines"
PERCENT_END_HEADER "%end-header"
PERCENT_ERROR_VERBOSE "%error-verbose" PERCENT_ERROR_VERBOSE "%error-verbose"
PERCENT_EXPECT "%expect" PERCENT_EXPECT "%expect"
PERCENT_EXPECT_RR "%expect-rr" PERCENT_EXPECT_RR "%expect-rr"
@@ -157,6 +156,7 @@ static int current_prec = 0;
PERCENT_REQUIRE "%require" PERCENT_REQUIRE "%require"
PERCENT_SKELETON "%skeleton" PERCENT_SKELETON "%skeleton"
PERCENT_START "%start" PERCENT_START "%start"
PERCENT_START_HEADER "%start-header"
PERCENT_TOKEN_TABLE "%token-table" PERCENT_TOKEN_TABLE "%token-table"
PERCENT_VERBOSE "%verbose" PERCENT_VERBOSE "%verbose"
PERCENT_YACC "%yacc" PERCENT_YACC "%yacc"
@@ -214,21 +214,21 @@ declarations:
declaration: declaration:
grammar_declaration grammar_declaration
| PROLOGUE { prologue_augment (translate_code ($1, @1), | PROLOGUE
@1); }
| "%after-definitions" "{...}"
{ {
after_definitions = true; prologue_augment (translate_code ($1, @1), @1, typed);
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("after_definitions", $2+1, @2);
} }
| "%before-definitions" "{...}" | "%after-header" "{...}"
{ {
before_definitions = true;
/* Remove the '{', and replace the '}' with '\n'. */ /* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n'; $2[strlen ($2) - 1] = '\n';
muscle_code_grow ("before_definitions", $2+1, @2); prologue_augment (translate_code ($2+1, @2), @2, true);
}
| "%before-header" "{...}"
{
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
prologue_augment (translate_code ($2+1, @2), @2, false);
} }
| "%debug" { debug_flag = true; } | "%debug" { debug_flag = true; }
| "%define" string_content | "%define" string_content
@@ -238,6 +238,12 @@ declaration:
} }
| "%define" string_content string_content { muscle_insert ($2, $3); } | "%define" string_content string_content { muscle_insert ($2, $3); }
| "%defines" { defines_flag = true; } | "%defines" { defines_flag = true; }
| "%end-header" "{...}"
{
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("end_header", translate_code ($2+1, @2), @2);
}
| "%error-verbose" { error_verbose = true; } | "%error-verbose" { error_verbose = true; }
| "%expect" INT { expected_sr_conflicts = $2; } | "%expect" INT { expected_sr_conflicts = $2; }
| "%expect-rr" INT { expected_rr_conflicts = $2; } | "%expect-rr" INT { expected_rr_conflicts = $2; }
@@ -261,6 +267,12 @@ declaration:
| "%pure-parser" { pure_parser = true; } | "%pure-parser" { pure_parser = true; }
| "%require" string_content { version_check (&@2, $2); } | "%require" string_content { version_check (&@2, $2); }
| "%skeleton" string_content { skeleton = $2; } | "%skeleton" string_content { skeleton = $2; }
| "%start-header" "{...}"
{
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("start_header", translate_code ($2+1, @2), @2);
}
| "%token-table" { token_table_flag = true; } | "%token-table" { token_table_flag = true; }
| "%verbose" { report_flag = report_states; } | "%verbose" { report_flag = report_states; }
| "%yacc" { yacc_flag = true; } | "%yacc" { yacc_flag = true; }

View File

@@ -44,10 +44,8 @@ static symbol_list *grammar = NULL;
static bool start_flag = false; static bool start_flag = false;
merger_list *merge_functions; merger_list *merge_functions;
/* Was %union, %before-definitions, or %after-definitions seen? */ /* Was %union seen? */
bool typed = false; bool typed = false;
bool before_definitions = false;
bool after_definitions = false;
/* Should rules have a default precedence? */ /* Should rules have a default precedence? */
bool default_prec = true; bool default_prec = true;
@@ -70,17 +68,16 @@ grammar_start_symbol_set (symbol *sym, location loc)
} }
/*---------------------------------------------------------------------------. /*---------------------------------------------------------------------.
| There are two prologues: one before the first %union, %before-definitions, | | There are two prologues: one before the first %union and one after. |
| or %after-definitions; and one after. Augment the current one. | | Augment the one specified by POST. |
`---------------------------------------------------------------------------*/ `---------------------------------------------------------------------*/
void void
prologue_augment (const char *prologue, location loc) prologue_augment (const char *prologue, location loc, bool post)
{ {
struct obstack *oout = struct obstack *oout =
!(typed || before_definitions || after_definitions) !post ? &pre_prologue_obstack : &post_prologue_obstack;
? &pre_prologue_obstack : &post_prologue_obstack;
obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line); obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line);
/* FIXME: Protection of M4 characters missing here. See /* FIXME: Protection of M4 characters missing here. See

View File

@@ -43,7 +43,7 @@ char const *token_name (int type);
/* From reader.c. */ /* From reader.c. */
void grammar_start_symbol_set (symbol *sym, location loc); void grammar_start_symbol_set (symbol *sym, location loc);
void prologue_augment (const char *prologue, location loc); void prologue_augment (const char *prologue, location loc, bool post);
void grammar_current_rule_begin (symbol *lhs, location loc); void grammar_current_rule_begin (symbol *lhs, location loc);
void grammar_current_rule_end (location loc); void grammar_current_rule_end (location loc);
void grammar_midrule_action (void); void grammar_midrule_action (void);
@@ -58,10 +58,8 @@ void free_merger_functions (void);
extern merger_list *merge_functions; extern merger_list *merge_functions;
/* Was %union, %before-definitions, or %after-definitions seen? */ /* Was %union seen? */
extern bool typed; extern bool typed;
extern bool before_definitions;
extern bool after_definitions;
/* Should rules have a default precedence? */ /* Should rules have a default precedence? */
extern bool default_prec; extern bool default_prec;

View File

@@ -164,8 +164,8 @@ splice (\\[ \f\t\v]*\n)*
`----------------------------*/ `----------------------------*/
<INITIAL> <INITIAL>
{ {
"%after-definitions" return PERCENT_AFTER_DEFINITIONS; "%after-header" return PERCENT_AFTER_HEADER;
"%before-definitions" return PERCENT_BEFORE_DEFINITIONS; "%before-header" return PERCENT_BEFORE_HEADER;
"%binary" return PERCENT_NONASSOC; "%binary" return PERCENT_NONASSOC;
"%debug" return PERCENT_DEBUG; "%debug" return PERCENT_DEBUG;
"%default"[-_]"prec" return PERCENT_DEFAULT_PREC; "%default"[-_]"prec" return PERCENT_DEFAULT_PREC;
@@ -173,6 +173,7 @@ splice (\\[ \f\t\v]*\n)*
"%defines" return PERCENT_DEFINES; "%defines" return PERCENT_DEFINES;
"%destructor" return PERCENT_DESTRUCTOR; "%destructor" return PERCENT_DESTRUCTOR;
"%dprec" return PERCENT_DPREC; "%dprec" return PERCENT_DPREC;
"%end-header" return PERCENT_END_HEADER;
"%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE; "%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE;
"%expect" return PERCENT_EXPECT; "%expect" return PERCENT_EXPECT;
"%expect"[-_]"rr" return PERCENT_EXPECT_RR; "%expect"[-_]"rr" return PERCENT_EXPECT_RR;
@@ -199,6 +200,7 @@ splice (\\[ \f\t\v]*\n)*
"%right" return PERCENT_RIGHT; "%right" return PERCENT_RIGHT;
"%skeleton" return PERCENT_SKELETON; "%skeleton" return PERCENT_SKELETON;
"%start" return PERCENT_START; "%start" return PERCENT_START;
"%start-header" return PERCENT_START_HEADER;
"%term" return PERCENT_TOKEN; "%term" return PERCENT_TOKEN;
"%token" return PERCENT_TOKEN; "%token" return PERCENT_TOKEN;
"%token"[-_]"table" return PERCENT_TOKEN_TABLE; "%token"[-_]"table" return PERCENT_TOKEN_TABLE;

View File

@@ -172,7 +172,7 @@ m4_if([$1$2$3], $[1]$[2]$[3], [],
# helping macros. So don't put any directly in the Bison file. # helping macros. So don't put any directly in the Bison file.
AT_BISON_OPTION_PUSHDEFS([$5]) AT_BISON_OPTION_PUSHDEFS([$5])
AT_DATA_GRAMMAR([[input.y]], AT_DATA_GRAMMAR([[input.y]],
[[%before-definitions { [[%start-header {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
@@ -190,7 +190,7 @@ m4_ifval([$6], [%union
int ival; int ival;
}]) }])
AT_LALR1_CC_IF([%define "global_tokens_and_yystype"]) AT_LALR1_CC_IF([%define "global_tokens_and_yystype"])
m4_ifval([$6], [[%after-definitions {]], [[%before-definitions {]]) m4_ifval([$6], [[%end-header {]], [[%start-header {]])
AT_LALR1_CC_IF([typedef yy::location YYLTYPE; AT_LALR1_CC_IF([typedef yy::location YYLTYPE;
m4_ifval([$6], , [#define YYSTYPE int])]) m4_ifval([$6], , [#define YYSTYPE int])])
[static int yylex (]AT_LEX_FORMALS[); [static int yylex (]AT_LEX_FORMALS[);