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>
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
requires them. Bison still generates an enum for token names in all cases.
* Handling of prologue blocks is now more consistent but potentially backward
incompatible.
* Handling of traditional Yacc prologue blocks is now more consistent but
potentially incompatible with previous releases of Bison.
As before, you declare prologue blocks in your grammar file with the
`%{ ... %}' syntax. To generate the pre-prologue, Bison concatenates all
prologue blocks that you've declared before any %union. If you've declared a
%union, Bison concatenates all prologue blocks that you've declared after it
to generate the post-prologue. (The new %before-definitions and
%after-definitions have a similar effect as %union on the prologues. See
below.)
prologue blocks that you've declared before the first %union. To generate
the post-prologue, Bison concatenates all prologue blocks that you've
declared after the first %union.
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
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
@@ -30,38 +28,50 @@ Changes in version 2.3+:
Now, Bison never inserts the pre-prologue into the header file. In the code
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:
%{
/* A pre-prologue block. For Yacc portability, Bison no longer puts this
* in the header file. In the code file, Bison inserts it before any
* %before-definitions blocks. */
%}
%before-definitions {
/* Bison inserts this into both the header file and code file. 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. */
%before-header {
/* Bison treats this block like a pre-prologue block: it inserts it into
* the code file before the contents of the header file. It 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 common
* example is `#include "system.h"'. */
}
%start-header {
/* Bison inserts this block into both the header file and the code file.
* 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 {
/* With previous versions of Bison, the first %union in your grammar file
* separated the pre-prologue blocks from the post-prologue blocks. Now,
* the first %union, %before-definitions, or %after-definitions does
* that. */
/* Unlike the traditional Yacc prologue blocks, the output order for the
* new %*-header blocks is not affected by their declaration position
* relative to any %union in the grammar file. */
}
%after-definitions {
/* If you want something in the header file and in the code file and it
* depends on any of the Bison-generated definitions in the header file,
* put it here. */
%end-header {
/* Bison inserts this block into both the header file and the code file.
* In both files, the point of insertion is after the Bison-generated
* definitions. This is a good place to declare or define public
* 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. */
%}
%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. */
}
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 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 # or open coded in the parser body.
m4_define([b4_shared_declarations],
[m4_ifdef([b4_before_definitions],
[[/* Copy the %before-definitions blocks. */
]b4_before_definitions])[]dnl
[m4_ifdef([b4_start_header],
[[/* Copy the %start-header blocks. */
]b4_start_header])[]dnl
b4_token_enums(b4_tokens)
@@ -203,9 +203,9 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1
#endif
]m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
]m4_ifdef([b4_end_header],
[[/* Copy the %end-header blocks. */
]b4_end_header])[]dnl
])
b4_defines_if([#include @output_header_name@],

View File

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

View File

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

View File

@@ -181,9 +181,9 @@ b4_locations_if([#define yylloc b4_prefix[]lloc])])[
# define YYTOKEN_TABLE ]b4_token_table[
#endif
]m4_ifdef([b4_before_definitions],
[[/* Copy the %before-definitions blocks. */
]b4_before_definitions])[]dnl
]m4_ifdef([b4_start_header],
[[/* Copy the %start-header blocks. */
]b4_start_header])[]dnl
b4_token_enums_defines(b4_tokens)[
@@ -213,9 +213,9 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1
#endif])
m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
m4_ifdef([b4_end_header],
[[/* Copy the %end-header blocks. */
]b4_end_header])[]dnl
[/* Copy the second part of user declarations. */
]b4_post_prologue
@@ -1498,9 +1498,9 @@ b4_defines_if(
b4_copyright([Skeleton interface for Bison's Yacc-like parsers in C],dnl '
[1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006])
m4_ifdef([b4_before_definitions],
[[/* Copy the %before-definitions blocks. */
]b4_before_definitions])[]dnl
m4_ifdef([b4_start_header],
[[/* Copy the %start-header blocks. */
]b4_start_header])[]dnl
b4_token_enums_defines(b4_tokens)
@@ -1538,7 +1538,7 @@ typedef struct YYLTYPE
[extern YYLTYPE b4_prefix[]lloc;])
)dnl b4_locations_if
m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
m4_ifdef([b4_end_header],
[[/* Copy the %end-header blocks. */
]b4_end_header])[]dnl
])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{}
@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,
,%defines}), you probably want @code{#include "ptypes.h"} to appear
in that header file as well.
In that case, use @code{%before-definitions} instead of a @var{Prologue}
section (@pxref{Table of Symbols, ,%before-definitions}):
In that case, use @code{%before-header}, @code{%start-header}, and
@code{%after-header} instead of @var{Prologue} sections
(@pxref{Table of Symbols, ,%start-header}):
@smallexample
%@{
%before-header @{
#include <stdio.h>
%@}
@}
%before-definitions @{
%start-header @{
#include "ptypes.h"
@}
%union @{
@@ -2684,10 +2687,10 @@ section (@pxref{Table of Symbols, ,%before-definitions}):
tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */
@}
%@{
%after-header @{
static void print_token_value (FILE *, int, YYSTYPE);
#define YYPRINT(F, N, L) print_token_value (F, N, L)
%@}
@}
@dots{}
@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
Tokens}.
@findex %before-definitions
@findex %after-definitions
If you have declared @code{%before-definitions} or @code{%after-definitions},
the output header also contains their code.
@xref{Table of Symbols, ,%before-definitions}.
@findex %start-header
@findex %end-header
If you have declared @code{%start-header} or @code{%end-header}, the output
header also contains their code.
@xref{Table of Symbols, ,%start-header}.
@end deffn
@deffn {Directive} %destructor
@@ -7462,18 +7465,18 @@ the grammar for.
@end example
@noindent
@findex %before-definitions
@findex %start-header
Then come the declarations/inclusions needed to define the
@code{%union}. Because the parser uses the parsing driver and
reciprocally, both cannot include the header of the other. Because the
driver's header needs detailed knowledge about the parser class (in
particular its inner types), it is the parser's header which will simply
use a forward declaration of the driver.
@xref{Table of Symbols, ,%before-definitions}.
@xref{Table of Symbols, ,%start-header}.
@comment file: calc++-parser.yy
@example
%before-definitions @{
%start-header @{
# include <string>
class calcxx_driver;
@}
@@ -7532,15 +7535,15 @@ them.
@end example
@noindent
The code between @samp{%@{} and @samp{%@}} after the introduction of the
@samp{%union} is output in the @file{*.cc} file; it needs detailed
knowledge about the driver.
@findex %after-header
The code between @samp{%after-header @{} and @samp{@}} is output in the
@file{*.cc} file; it needs detailed knowledge about the driver.
@comment file: calc++-parser.yy
@example
%@{
%after-header @{
# include "calc++-driver.hh"
%@}
@}
@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.
@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;
@pxref{Table of Symbols, ,%defines}) and into the code file after any
Bison-generated definitions.
For details, @xref{Table of Symbols, ,%before-definitions}.
@xref{Table of Symbols, ,%start-header}.
@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;
@pxref{Table of Symbols, ,%defines}) and into the code file before any
Bison-generated definitions.
@cindex Prologue
@findex %after-definitions
@findex %before-header
@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
%@{
/* A pre-prologue block. For Yacc portability, Bison does not put
* this in the header file. In the code file, Bison inserts it
* before any %before-definitions blocks. */
%@}
%before-definitions @{
/* Bison inserts this into both the header file and code file. 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. */
%before-header @{
/* Bison treats this block like a pre-prologue block: it inserts it
* into the code file before the contents of the header file. It
* 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
* common example is `#include "system.h"'. */
@}
%start-header @{
/* Bison inserts this block into both the header file and the code
* file. 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 @{
/* The first %union, %before-definitions, or %after-definitions
* in your grammar file separates the pre-prologue blocks from the
* post-prologue blocks. */
/* Unlike the traditional Yacc prologue blocks, the output order
* for the %*-header blocks is not affected by their declaration
* position relative to any %union in the grammar file. */
@}
%after-definitions @{
/* If you want something in the header file and in the code file
* and it depends on any of the Bison-generated definitions in the
* header file, put it here. */
%end-header @{
/* Bison inserts this block into both the header file and the code
* file. In both files, the point of insertion is after the
* 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
If you have multiple occurrences of any one of the above declarations, Bison
will concatenate the contents in declaration order.
@xref{Prologue, ,The Prologue}.
@end deffn

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@@ -43,7 +43,7 @@ char const *token_name (int type);
/* From reader.c. */
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_end (location loc);
void grammar_midrule_action (void);
@@ -58,10 +58,8 @@ void free_merger_functions (void);
extern merger_list *merge_functions;
/* Was %union, %before-definitions, or %after-definitions seen? */
/* Was %union seen? */
extern bool typed;
extern bool before_definitions;
extern bool after_definitions;
/* Should rules have a default precedence? */
extern bool default_prec;

View File

@@ -164,8 +164,8 @@ splice (\\[ \f\t\v]*\n)*
`----------------------------*/
<INITIAL>
{
"%after-definitions" return PERCENT_AFTER_DEFINITIONS;
"%before-definitions" return PERCENT_BEFORE_DEFINITIONS;
"%after-header" return PERCENT_AFTER_HEADER;
"%before-header" return PERCENT_BEFORE_HEADER;
"%binary" return PERCENT_NONASSOC;
"%debug" return PERCENT_DEBUG;
"%default"[-_]"prec" return PERCENT_DEFAULT_PREC;
@@ -173,6 +173,7 @@ splice (\\[ \f\t\v]*\n)*
"%defines" return PERCENT_DEFINES;
"%destructor" return PERCENT_DESTRUCTOR;
"%dprec" return PERCENT_DPREC;
"%end-header" return PERCENT_END_HEADER;
"%error"[-_]"verbose" return PERCENT_ERROR_VERBOSE;
"%expect" return PERCENT_EXPECT;
"%expect"[-_]"rr" return PERCENT_EXPECT_RR;
@@ -199,6 +200,7 @@ splice (\\[ \f\t\v]*\n)*
"%right" return PERCENT_RIGHT;
"%skeleton" return PERCENT_SKELETON;
"%start" return PERCENT_START;
"%start-header" return PERCENT_START_HEADER;
"%term" return PERCENT_TOKEN;
"%token" return PERCENT_TOKEN;
"%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.
AT_BISON_OPTION_PUSHDEFS([$5])
AT_DATA_GRAMMAR([[input.y]],
[[%before-definitions {
[[%start-header {
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -190,7 +190,7 @@ m4_ifval([$6], [%union
int ival;
}])
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;
m4_ifval([$6], , [#define YYSTYPE int])])
[static int yylex (]AT_LEX_FORMALS[);