Don't put the pre-prologue in the header file. For the yacc.c code

file and the glr.c header and code files, move the pre-prologue before
the token definitions.  Add new %before-definitions and
%after-definitions to declare code that will go in both the header file
and code file.  Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2005-12/msg00000.html>,
<http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00016.html>,
and
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00055.html>.
* NEWS (2.3+): Describe these changes.
* data/glr.c (b4_pre_prologue): Move from within to before...
(b4_shared_declarations): ... this.
Add new b4_before_definitions before b4_token_enums.
Add new b4_after_definitions at the end.
* data/glr.cc (b4_pre_prologue): Replace with...
(b4_before_definitions): ... this in the header file.
(b4_after_definitions): New near the end of the header file.
* data/lalr1.cc (b4_pre_prologue): Move from the header file to the
code file right before including the header file.
(b4_before_definitions): New in the previous position of
b4_pre_prologue in the header file.
(b4_after_definitions): New near the end of the header file.
* data/yacc.c: Clean up some m4 quoting especially in the header file.
(b4_token_enums_defines): In the code file, move to right before
YYSTYPE for consistency with the header file.
(b4_before_definitions): New right before b4_token_enums_defines in
both the header and code file.
(b4_after_definitions): New right after YYLTYPE and yylloc in both the
header and code file.
* doc/bison.texinfo (Prologue): Show use of %before-definitions instead
of prologues for %union dependencies.
(Bison Declaration Summary): In %defines description, mention the
effect of %before-definitions and %after-definitions on the header
file.
(Calc++ Parser): Forward declare driver in a %before-definitions rather
than in the pre-prologue so that make check succeeds.
(Bison Symbols): Add entries for %before-definitions and
%after-definitions.
* src/parse-gram.y (PERCENT_BEFORE_DEFINITIONS): New token for
%before-definitions.
(PERCENT_AFTER_DEFINITIONS): New token for %after-definitions.
(declaration): Parse those declarations and append to
b4_before_definitions and b4_after_definitions, respectively.
* src/reader.c (before_definitions, after_definitions): New bools to
track whether those declarations have been seen.
(prologue_augment): Add to the post-prologue if %union,
%before-definitions, or %after-definitions has been seen.
* src/reader.h (before_definitions, after_definitions): New extern's.
* src/scan-gram.l: Scan the new declarations.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Place the second
prologue block in a %before-definitions or a %after-definitions based
on whether the %union is declared.
* tests/regression.at (Early token definitions with --yacc, Early token
definitions without --yacc): Move tests for token definitions into the
post-prologue since token names are no longer defined in the
pre-prologue.
This commit is contained in:
Joel E. Denny
2006-06-21 01:37:01 +00:00
parent 203b927414
commit 9bc0dd679f
15 changed files with 903 additions and 590 deletions

View File

@@ -1,3 +1,62 @@
2006-06-20 Joel E. Denny <jdenny@ces.clemson.edu>
Don't put the pre-prologue in the header file. For the yacc.c code
file and the glr.c header and code files, move the pre-prologue before
the token definitions. Add new %before-definitions and
%after-definitions to declare code that will go in both the header file
and code file. Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2005-12/msg00000.html>,
<http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00016.html>,
and
<http://lists.gnu.org/archive/html/bison-patches/2006-06/msg00055.html>.
* NEWS (2.3+): Describe these changes.
* data/glr.c (b4_pre_prologue): Move from within to before...
(b4_shared_declarations): ... this.
Add new b4_before_definitions before b4_token_enums.
Add new b4_after_definitions at the end.
* data/glr.cc (b4_pre_prologue): Replace with...
(b4_before_definitions): ... this in the header file.
(b4_after_definitions): New near the end of the header file.
* data/lalr1.cc (b4_pre_prologue): Move from the header file to the
code file right before including the header file.
(b4_before_definitions): New in the previous position of
b4_pre_prologue in the header file.
(b4_after_definitions): New near the end of the header file.
* data/yacc.c: Clean up some m4 quoting especially in the header file.
(b4_token_enums_defines): In the code file, move to right before
YYSTYPE for consistency with the header file.
(b4_before_definitions): New right before b4_token_enums_defines in
both the header and code file.
(b4_after_definitions): New right after YYLTYPE and yylloc in both the
header and code file.
* doc/bison.texinfo (Prologue): Show use of %before-definitions instead
of prologues for %union dependencies.
(Bison Declaration Summary): In %defines description, mention the
effect of %before-definitions and %after-definitions on the header
file.
(Calc++ Parser): Forward declare driver in a %before-definitions rather
than in the pre-prologue so that make check succeeds.
(Bison Symbols): Add entries for %before-definitions and
%after-definitions.
* src/parse-gram.y (PERCENT_BEFORE_DEFINITIONS): New token for
%before-definitions.
(PERCENT_AFTER_DEFINITIONS): New token for %after-definitions.
(declaration): Parse those declarations and append to
b4_before_definitions and b4_after_definitions, respectively.
* src/reader.c (before_definitions, after_definitions): New bools to
track whether those declarations have been seen.
(prologue_augment): Add to the post-prologue if %union,
%before-definitions, or %after-definitions has been seen.
* src/reader.h (before_definitions, after_definitions): New extern's.
* src/scan-gram.l: Scan the new declarations.
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Place the second
prologue block in a %before-definitions or a %after-definitions based
on whether the %union is declared.
* tests/regression.at (Early token definitions with --yacc, Early token
definitions without --yacc): Move tests for token definitions into the
post-prologue since token names are no longer defined in the
pre-prologue.
2006-06-20 Akim Demaille <akim@epita.fr>
* src/symtab.h, src/symtab.c (symbol_from_uniqstr): New.

54
NEWS
View File

@@ -9,6 +9,60 @@ 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.
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.)
Previous versions 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
token numbers with names). For parsers in C, the point of insertion was
after the token definitions.
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.
For example, in your grammar file:
%{
/* 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. */
}
%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. */
}
%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. */
}
%{
/* 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. */
%}
* The option `--report=look-ahead' has been changed to `--report=lookahead'.
The old spelling still works, but is not documented and may be removed
in a future release.

View File

@@ -159,19 +159,23 @@ m4_if(b4_prefix, [yy], [],
#define yychar b4_prefix[]char
#define yydebug b4_prefix[]debug
#define yynerrs b4_prefix[]nerrs
#define yylloc b4_prefix[]lloc])
#define yylloc b4_prefix[]lloc])[
/* Copy the first part of user declarations. */
]b4_pre_prologue
dnl # b4_shared_declarations
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],
[b4_token_enums(b4_tokens)[
[m4_ifdef([b4_before_definitions],
[[/* Copy the %before-definitions blocks. */
]b4_before_definitions])[]dnl
/* Copy the first part of user declarations. */
]b4_pre_prologue[
b4_token_enums(b4_tokens)
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
]m4_ifdef([b4_stype],
[typedef union b4_union_name
b4_stype
@@ -198,7 +202,11 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
]])
]m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
])
b4_defines_if([#include @output_header_name@],
[b4_shared_declarations])[

View File

@@ -214,7 +214,6 @@ m4_defn([b4_parse_param])))],
m4_include(b4_pkgdatadir/[glr.c])
m4_popdef([b4_parse_param])
@output @output_header_name@
b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002, 2003, 2004, 2005, 2006])[
@@ -236,11 +235,12 @@ namespace ]b4_namespace[
class location;
}
/* Copy the first part of user declarations. */
]b4_pre_prologue[
]m4_ifdef([b4_before_definitions],
[[/* Copy the %before-definitions blocks. */
]b4_before_definitions])[]dnl
]/* Line __line__ of glr.cc. */
b4_syncline([@oline@], [@ofile@])[
[/* Line __line__ of glr.cc. */
]b4_syncline([@oline@], [@ofile@])[
#include "location.hh"
@@ -386,4 +386,8 @@ m4_ifset([b4_global_tokens_and_yystype],
}
#endif /* ! defined PARSER_HEADER_H */]
]m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
[#endif /* ! defined PARSER_HEADER_H */]

View File

@@ -53,11 +53,12 @@ namespace ]b4_namespace[
class location;
}
/* First part of user declarations. */
]b4_pre_prologue[
]m4_ifdef([b4_before_definitions],
[[/* Copy the %before-definitions blocks. */
]b4_before_definitions])[]dnl
]/* Line __line__ of lalr1.cc. */
b4_syncline([@oline@], [@ofile@])[
[/* Line __line__ of lalr1.cc. */
]b4_syncline([@oline@], [@ofile@])[
]dnl Include location.hh here: it might depend on headers included above.
[#include "location.hh"
@@ -298,8 +299,12 @@ b4_error_verbose_if([, int tok])[);
/* Redirection for backward compatibility. */
# define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
#endif
])[
#endif /* ! defined PARSER_HEADER_H */]
])
m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
[#endif /* ! defined PARSER_HEADER_H */]
])dnl
@output @output_parser_name@
b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
@@ -307,7 +312,11 @@ b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++],
m4_if(b4_prefix, [yy], [],
[
// Take the name prefix into account.
#define yylex b4_prefix[]lex])
#define yylex b4_prefix[]lex])[
/* First part of user declarations. */
]b4_pre_prologue
b4_defines_if([
#include @output_header_name@])[

View File

@@ -160,8 +160,6 @@ m4_if(b4_prefix, [yy], [],
#define yynerrs b4_prefix[]nerrs
b4_locations_if([#define yylloc b4_prefix[]lloc])])[
]b4_token_enums_defines(b4_tokens)[
/* Copy the first part of user declarations. */
]b4_pre_prologue[
@@ -183,9 +181,15 @@ 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
b4_token_enums_defines(b4_tokens)[
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
]m4_ifdef([b4_stype],
[typedef union b4_union_name
[[typedef union ]b4_union_name
b4_stype
/* Line __line__ of yacc.c. */
b4_syncline([@oline@], [@ofile@])
@@ -207,14 +211,17 @@ typedef struct YYLTYPE
# define yyltype YYLTYPE /* obsolescent; will be withdrawn */
# define YYLTYPE_IS_DECLARED 1
# define YYLTYPE_IS_TRIVIAL 1
#endif
])[
#endif])
/* Copy the second part of user declarations. */
m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
[/* Copy the second part of user declarations. */
]b4_post_prologue
/* Line __line__ of yacc.c. */
b4_syncline([@oline@], [@ofile@])[
[/* Line __line__ of yacc.c. */
]b4_syncline([@oline@], [@ofile@])[
#ifdef short
# undef short
@@ -1491,22 +1498,26 @@ 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
b4_token_enums_defines(b4_tokens)
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
m4_ifdef([b4_stype],
[typedef union b4_union_name
[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
]m4_ifdef([b4_stype],
[[typedef union ]b4_union_name
b4_stype
/* Line __line__ of yacc.c. */
b4_syncline([@oline@], [@ofile@])
YYSTYPE;],
[typedef int YYSTYPE;])
[typedef int YYSTYPE;])[
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
b4_pure_if([],
]b4_pure_if([],
[extern YYSTYPE b4_prefix[]lval;])
b4_locations_if(
@@ -1523,7 +1534,11 @@ typedef struct YYLTYPE
# define YYLTYPE_IS_TRIVIAL 1
#endif
b4_pure_if([],
]b4_pure_if([],
[extern YYLTYPE b4_prefix[]lloc;])
])dnl b4_locations_if
)dnl b4_locations_if
m4_ifdef([b4_after_definitions],
[[/* Copy the %after-definitions blocks. */
]b4_after_definitions])[]dnl
])dnl b4_defines_if

View File

@@ -2664,6 +2664,34 @@ can be done with two @var{Prologue} blocks, one before and one after the
@dots{}
@end smallexample
@findex %before-definitions
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}):
@smallexample
%@{
#include <stdio.h>
%@}
%before-definitions @{
#include "ptypes.h"
@}
%union @{
long int n;
tree t; /* @r{@code{tree} is defined in @file{ptypes.h}.} */
@}
%@{
static void print_token_value (FILE *, int, YYSTYPE);
#define YYPRINT(F, N, L) print_token_value (F, N, L)
%@}
@dots{}
@end smallexample
@node Bison Declarations
@subsection The Bison Declarations Section
@cindex Bison declarations (introduction)
@@ -4199,6 +4227,12 @@ of @code{yylex} in a separate source file, because @code{yylex}
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}.
@end deffn
@deffn {Directive} %destructor
@@ -7428,19 +7462,21 @@ the grammar for.
@end example
@noindent
@findex %before-definitions
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}.
@comment file: calc++-parser.yy
@example
%@{
%before-definitions @{
# include <string>
class calcxx_driver;
%@}
@}
@end example
@noindent
@@ -8172,6 +8208,61 @@ $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}@}
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}.
@end deffn
@deffn {Directive} %before-definitions @{@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 %union
For example, in your grammar file:
@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. */
@}
%union @{
/* The first %union, %before-definitions, or %after-definitions
* in your grammar file separates the pre-prologue blocks from the
* post-prologue blocks. */
@}
%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. */
@}
%@{
/* 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
@xref{Prologue, ,The Prologue}.
@end deffn
@deffn {Directive} %debug
Equip the parser for debugging. @xref{Decl Summary}.
@end deffn
@deffn {Directive} %debug
Equip the parser for debugging. @xref{Decl Summary}.
@end deffn

File diff suppressed because it is too large Load Diff

View File

@@ -33,6 +33,7 @@
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
@@ -53,43 +54,45 @@
PERCENT_PREC = 268,
PERCENT_DPREC = 269,
PERCENT_MERGE = 270,
PERCENT_DEBUG = 271,
PERCENT_DEFAULT_PREC = 272,
PERCENT_DEFINE = 273,
PERCENT_DEFINES = 274,
PERCENT_ERROR_VERBOSE = 275,
PERCENT_EXPECT = 276,
PERCENT_EXPECT_RR = 277,
PERCENT_FILE_PREFIX = 278,
PERCENT_GLR_PARSER = 279,
PERCENT_INITIAL_ACTION = 280,
PERCENT_LEX_PARAM = 281,
PERCENT_LOCATIONS = 282,
PERCENT_NAME_PREFIX = 283,
PERCENT_NO_DEFAULT_PREC = 284,
PERCENT_NO_LINES = 285,
PERCENT_NONDETERMINISTIC_PARSER = 286,
PERCENT_OUTPUT = 287,
PERCENT_PARSE_PARAM = 288,
PERCENT_PURE_PARSER = 289,
PERCENT_REQUIRE = 290,
PERCENT_SKELETON = 291,
PERCENT_START = 292,
PERCENT_TOKEN_TABLE = 293,
PERCENT_VERBOSE = 294,
PERCENT_YACC = 295,
BRACED_CODE = 296,
CHAR = 297,
EPILOGUE = 298,
EQUAL = 299,
ID = 300,
ID_COLON = 301,
PERCENT_PERCENT = 302,
PIPE = 303,
PROLOGUE = 304,
SEMICOLON = 305,
TYPE = 306,
PERCENT_UNION = 307
PERCENT_AFTER_DEFINITIONS = 271,
PERCENT_BEFORE_DEFINITIONS = 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
};
#endif
/* Tokens. */
@@ -107,50 +110,52 @@
#define PERCENT_PREC 268
#define PERCENT_DPREC 269
#define PERCENT_MERGE 270
#define PERCENT_DEBUG 271
#define PERCENT_DEFAULT_PREC 272
#define PERCENT_DEFINE 273
#define PERCENT_DEFINES 274
#define PERCENT_ERROR_VERBOSE 275
#define PERCENT_EXPECT 276
#define PERCENT_EXPECT_RR 277
#define PERCENT_FILE_PREFIX 278
#define PERCENT_GLR_PARSER 279
#define PERCENT_INITIAL_ACTION 280
#define PERCENT_LEX_PARAM 281
#define PERCENT_LOCATIONS 282
#define PERCENT_NAME_PREFIX 283
#define PERCENT_NO_DEFAULT_PREC 284
#define PERCENT_NO_LINES 285
#define PERCENT_NONDETERMINISTIC_PARSER 286
#define PERCENT_OUTPUT 287
#define PERCENT_PARSE_PARAM 288
#define PERCENT_PURE_PARSER 289
#define PERCENT_REQUIRE 290
#define PERCENT_SKELETON 291
#define PERCENT_START 292
#define PERCENT_TOKEN_TABLE 293
#define PERCENT_VERBOSE 294
#define PERCENT_YACC 295
#define BRACED_CODE 296
#define CHAR 297
#define EPILOGUE 298
#define EQUAL 299
#define ID 300
#define ID_COLON 301
#define PERCENT_PERCENT 302
#define PIPE 303
#define PROLOGUE 304
#define SEMICOLON 305
#define TYPE 306
#define PERCENT_UNION 307
#define PERCENT_AFTER_DEFINITIONS 271
#define PERCENT_BEFORE_DEFINITIONS 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
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 97 "../../src/parse-gram.y"
#line 97 "parse-gram.y"
{
symbol *symbol;
symbol_list *list;
@@ -160,8 +165,8 @@ typedef union YYSTYPE
uniqstr uniqstr;
unsigned char character;
}
/* Line 1529 of yacc.c. */
#line 165 "../../src/parse-gram.h"
/* Line 1544 of yacc.c. */
#line 170 "parse-gram.h"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
@@ -184,3 +189,4 @@ typedef struct YYLTYPE
#endif

View File

@@ -130,6 +130,10 @@ static int current_prec = 0;
`----------------------*/
%token
PERCENT_AFTER_DEFINITIONS
"%after-definitions"
PERCENT_BEFORE_DEFINITIONS
"%before-definitions"
PERCENT_DEBUG "%debug"
PERCENT_DEFAULT_PREC "%default-prec"
PERCENT_DEFINE "%define"
@@ -212,6 +216,20 @@ declaration:
grammar_declaration
| PROLOGUE { prologue_augment (translate_code ($1, @1),
@1); }
| "%after-definitions" "{...}"
{
after_definitions = true;
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("after_definitions", $2+1, @2);
}
| "%before-definitions" "{...}"
{
before_definitions = true;
/* Remove the '{', and replace the '}' with '\n'. */
$2[strlen ($2) - 1] = '\n';
muscle_code_grow ("before_definitions", $2+1, @2);
}
| "%debug" { debug_flag = true; }
| "%define" string_content
{

View File

@@ -44,8 +44,10 @@ static symbol_list *grammar = NULL;
static bool start_flag = false;
merger_list *merge_functions;
/* Was %union seen? */
/* Was %union, %before-definitions, or %after-definitions seen? */
bool typed = false;
bool before_definitions = false;
bool after_definitions = false;
/* Should rules have a default precedence? */
bool default_prec = true;
@@ -68,16 +70,17 @@ grammar_start_symbol_set (symbol *sym, location loc)
}
/*----------------------------------------------------------------.
| There are two prologues: one before %union, one after. Augment |
| the current one. |
`----------------------------------------------------------------*/
/*---------------------------------------------------------------------------.
| There are two prologues: one before the first %union, %before-definitions, |
| or %after-definitions; and one after. Augment the current one. |
`---------------------------------------------------------------------------*/
void
prologue_augment (const char *prologue, location loc)
{
struct obstack *oout =
!typed ? &pre_prologue_obstack : &post_prologue_obstack;
!(typed || before_definitions || after_definitions)
? &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

@@ -58,8 +58,10 @@ void free_merger_functions (void);
extern merger_list *merge_functions;
/* Was %union seen? */
/* Was %union, %before-definitions, or %after-definitions 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,6 +164,8 @@ splice (\\[ \f\t\v]*\n)*
`----------------------------*/
<INITIAL>
{
"%after-definitions" return PERCENT_AFTER_DEFINITIONS;
"%before-definitions" return PERCENT_BEFORE_DEFINITIONS;
"%binary" return PERCENT_NONASSOC;
"%debug" return PERCENT_DEBUG;
"%default"[-_]"prec" return PERCENT_DEFAULT_PREC;

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 {
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
@@ -182,7 +182,7 @@ AT_DATA_GRAMMAR([[input.y]],
]AT_LALR1_CC_IF(
[#define RANGE(Location) (Location).begin.line, (Location).end.line],
[#define RANGE(Location) (Location).first_line, (Location).last_line])
[%}
[}
$5]
m4_ifval([$6], [%union
@@ -190,13 +190,12 @@ m4_ifval([$6], [%union
int ival;
}])
AT_LALR1_CC_IF([%define "global_tokens_and_yystype"])
[
%{
]AT_LALR1_CC_IF([typedef yy::location YYLTYPE;
m4_ifval([$6], [[%after-definitions {]], [[%before-definitions {]])
AT_LALR1_CC_IF([typedef yy::location YYLTYPE;
m4_ifval([$6], , [#define YYSTYPE int])])
[static int yylex (]AT_LEX_FORMALS[);
]AT_LALR1_CC_IF([], [static void yyerror (const char *msg);])
[%}
[}
]m4_ifval([$6], [%type <ival> '(' 'x' 'y' ')' ';' thing line input])[

View File

@@ -63,15 +63,17 @@ AT_DATA_GRAMMAR([input.y],
[[%{
void yyerror (const char *s);
int yylex (void);
#ifndef MY_TOKEN
# error "MY_TOKEN not defined."
#endif
%}
%union
{
int val;
};
%{
#ifndef MY_TOKEN
# error "MY_TOKEN not defined."
#endif
%}
%token MY_TOKEN
%%
exp: MY_TOKEN;
@@ -101,6 +103,13 @@ AT_DATA_GRAMMAR([input.y],
void yyerror (const char *s);
int yylex (void);
void print_my_token (void);
%}
%union
{
int val;
};
%{
void
print_my_token (void)
{
@@ -108,11 +117,6 @@ print_my_token (void)
printf ("%d\n", my_token);
}
%}
%union
{
int val;
};
%token MY_TOKEN
%%
exp: MY_TOKEN;