bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: glr: include the created header


From: Joel E. Denny
Subject: Re: glr: include the created header
Date: Wed, 14 Jun 2006 20:27:43 -0400 (EDT)

On Sun, 11 Jun 2006, Joel E. Denny wrote:

> On Tue, 3 Jan 2006, Joel E. Denny wrote:
> 
> > On Tue, 3 Jan 2006, Akim Demaille wrote:
> > 
> > > >>> "Joel" == Joel E Denny <address@hidden> writes:
> > > 
> > >  > To accommodate YYSTYPE dependencies, YYLTYPE dependencies, a 
> > > non-%union 
> > >  > YYSTYPE definition, a user YYLTYPE definition, or anything else the 
> > > user 
> > >  > might wish to place in the header, perhaps there should be some sort 
> > > of 
> > >  > general `header' qualifier for any literal block:
> > > 
> > >  >   %header{
> > >  >     /* C code */
> > >  >   %}
>
> [...]
>
> Are we ready to address this now?

In order to explore the above idea and clarify the details, I wrote the 
following patch.  Of course, this needs some discussion before I commit 
anything.

I put a detailed description of the user-visible effects of the changes in 
the NEWS file.  (Some of that would probably move to the manual, which I 
haven't updated yet, but that's not important right now.)

There are some potential backward compatibility issues as I explain in the 
first new NEWS entry.  If they're significant, I'm thinking this might be 
a job for %require.

Joel

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1504
diff -p -u -r1.1504 ChangeLog
--- ChangeLog   11 Jun 2006 18:27:44 -0000      1.1504
+++ ChangeLog   14 Jun 2006 23:44:57 -0000
@@ -1,3 +1,67 @@
+2006-??-??  Joel E. Denny  <address@hidden>
+
+       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 a new `%header{...}' declaration in order
+       to declare a header pre-prologue and a header post-prologue.
+       * NEWS (2.3+): Describe these changes.
+       * doc/bison.texinfo: NEEDS TO BE UPDATED
+       (Calc++ Parser): Forward declare driver in header pre-prologue rather
+       than non-header pre-prologue so that make check succeeds.
+       * data/glr.c (b4_pre_prologue): Move from within to before...
+       (b4_shared_declarations): this.
+       Add new b4_header_pre_prologue before b4_token_enums.
+       Add new b4_header_post_prologue at the end.
+       * data/glr.cc (b4_pre_prologue): Replace with...
+       (b4_header_pre_prologue): this in the header file.
+       (b4_header_post_prologue): 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_header_pre_prologue): New in the previous position of
+       b4_pre_prologue in the header file.
+       (b4_header_post_prologue): 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_header_pre_prologue): New right before b4_token_enums_defines in
+       both the header and code file.
+       (b4_header_post_prologue): New right after YYLTYPE and yylloc in both
+       the header and code file.
+       * src/files.c (header_pre_prologue_obstack,
+       header_post_prologue_obstack): New obstacks.
+       * src/files.h (header_pre_prologue_obstack,
+       header_post_prologue_obstack): New extern's.
+       * src/output.c (prepare): Insert b4_header_pre_prologue and
+       b4_header_post_prologue from the obstacks.
+       (output): Free header_pre_prologue_obstack and
+       header_post_prologue_obstack.
+       * src/parse-gram.y (enum header_position): New.  Used to track whether
+       non-header prologue blocks divide header prologue and %union
+       declarations.
+       (HEADER_PROLOGUE): New token for `%header{...%}' declaration.
+       (declaration): Add HEADER_PROLOGUE as a RHS.  For that and the PROLOGUE
+       RHS, track header_position.
+       (grammar_declaration): For "%union {...}" RHS, track header_position.
+       * src/reader.c (prologue_augment): Add parameter bool header, which
+       specifies whether to grow a header or to grow a non-header prologue
+       obstack.
+       (reader): Initialize header_pre_prologue_obstack and
+       header_post_prologue_obstack.
+       * src/reader.h (prologue_augment): Add parameter bool header.
+       * src/scan-gram.l: (HEADER_PROLOGUE): New token for `%header{...%}'
+       declarations.  It's similar to the PROLOGUE token.
+       (SC_HEADER_PROLOGUE): New start condition similar to SC_PROLOGUE.
+       * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Using the new
+       `%header{...}' declaration, consistently place PROLOGUE blocks in the
+       header pre-prologue regardless of whether `%union {...}' is declared.
+       Previously, adding the `%union {...}' moved the second PROLOGUE block
+       from the header (at the previous pre-prologue position) to the code
+       file (at the post-prologue position).
+       * 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-11  Joel E. Denny  <address@hidden>
 
        For associating token numbers with token names for "yacc.c", don't use
Index: NEWS
===================================================================
RCS file: /sources/bison/bison/NEWS,v
retrieving revision 1.151
diff -p -u -r1.151 NEWS
--- NEWS        11 Jun 2006 18:27:44 -0000      1.151
+++ NEWS        14 Jun 2006 23:44:57 -0000
@@ -9,6 +9,74 @@ 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.
+
+  Prologue blocks that you declare with the `%{...%}' syntax are now called
+  *non-header* prologue blocks.  To generate the non-header pre-prologue, Bison
+  concatenates all non-header prologue blocks that you declared before any
+  %union declaration.  If you declared a %union, Bison concatenates all
+  non-header prologue blocks that you declared after it to generate the
+  non-header post-prologue.
+
+  Previously, Bison inserted the non-header pre-prologue (previously just 
called
+  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 non-header pre-prologue into the header file.
+  In the code file, it always inserts it before the token definitions.
+
+* Handling of prologue blocks is now more flexible.
+
+  Bison now provides a *header* prologue declaration.  It is similar to the
+  existing non-header prologue declaration, but it starts with `%header{' (no
+  spaces) instead of `%{'.  Both end with `%}'.  To generate the header
+  pre-prologue, Bison concatenates together all header prologue blocks that you
+  declared before any %union declaration.  If you declared a %union, Bison
+  concatenates all header prologue blocks that you declared after it to
+  generate the header post-prologue.
+
+  Bison inserts the header pre-prologue into both the header file and the code
+  file before any Bison-generated token, semantic type, location type, and
+  class definitions.  It inserts the header post-prologue into both files after
+  all these definitions.  Finally, in the code file only, it inserts the
+  non-header pre-prologue and the non-header post-prologue before the header
+  pre-prologue and after the header post-prologue, respectively.
+
+  To clarify the ordering, Bison reports an error if you declare a non-header
+  prologue block between one %union or header prologue block and another %union
+  or header prologue block.  Here's an example of the correct ordering:
+
+    %{
+      /* A block for the non-header pre-prologue.  */
+      /* For Yacc portability, Bison doesn't put this in the header file.  */
+    %}
+    %header{
+      /* A block for the header pre-prologue.  */
+      /* This is the right place to declare %union dependencies.  */
+    %}
+    %union {
+      /* If you don't declare a %union, Bison will not generate any
+         post-prologues.  */
+    }
+    %header{
+      /* A block for the header post-prologue.  */
+      /* If you want something in the header file and it depends on
+         Bison-generated definitions, put it here.  */
+    %}
+    %{
+      /* A block for the non-header post-prologue.  */
+      /* If you want something in your code file but *not* in your header file
+         and it depends on Bison-generated definitions, put it here.  */
+    %}
+
+  Declaring a header prologue block does not imply that Bison should
+  necessarily generate a header file.  As before, use the `%defines'
+  declaration or the `-d' or `--defines' flag for that.
+
 * 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.
Index: data/glr.c
===================================================================
RCS file: /sources/bison/bison/data/glr.c,v
retrieving revision 1.179
diff -p -u -r1.179 glr.c
--- data/glr.c  10 Jun 2006 03:02:22 -0000      1.179
+++ data/glr.c  14 Jun 2006 23:44:58 -0000
@@ -159,19 +159,22 @@ 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)[
+[[/* Copy the first part of user header declarations.  */
+]b4_header_pre_prologue
 
-/* 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 m4_bregexp(b4_stype, [^{], [YYSTYPE ])
 b4_stype
@@ -198,7 +201,10 @@ typedef struct YYLTYPE
 # define YYLTYPE_IS_DECLARED 1
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
-]])
+
+/* Copy the second part of user header declarations.  */
+]b4_header_post_prologue
+])
 
 b4_defines_if([#include @address@hidden,
              [b4_shared_declarations])[
Index: data/glr.cc
===================================================================
RCS file: /sources/bison/bison/data/glr.cc,v
retrieving revision 1.19
diff -p -u -r1.19 glr.cc
--- data/glr.cc 14 May 2006 20:48:24 -0000      1.19
+++ data/glr.cc 14 Jun 2006 23:44:58 -0000
@@ -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,8 +235,8 @@ namespace ]b4_namespace[
   class location;
 }
 
-/* Copy the first part of user declarations.  */
-]b4_pre_prologue[
+/* Copy the first part of user header declarations.  */
+]b4_header_pre_prologue[
 
 ]/* Line __line__ of glr.cc.  */
 b4_syncline(address@hidden@], address@hidden@])[
@@ -386,4 +385,7 @@ m4_ifset([b4_global_tokens_and_yystype],
 
 }
 
+/* Copy the second part of user header declarations.  */
+]b4_header_post_prologue[
+
 #endif /* ! defined PARSER_HEADER_H */]
Index: data/lalr1.cc
===================================================================
RCS file: /sources/bison/bison/data/lalr1.cc,v
retrieving revision 1.132
diff -p -u -r1.132 lalr1.cc
--- data/lalr1.cc       10 Jun 2006 03:02:23 -0000      1.132
+++ data/lalr1.cc       14 Jun 2006 23:44:59 -0000
@@ -53,8 +53,8 @@ namespace ]b4_namespace[
   class location;
 }
 
-/* First part of user declarations.  */
-]b4_pre_prologue[
+/* First part of user header declarations.  */
+]b4_header_pre_prologue[
 
 ]/* Line __line__ of lalr1.cc.  */
 b4_syncline(address@hidden@], address@hidden@])[
@@ -299,6 +299,9 @@ b4_error_verbose_if([, int tok])[);
 # define YYSTYPE b4_namespace::b4_parser_class_name::semantic_type
 #endif
 ])[
+/* Second part of user header declarations.  */
+]b4_header_post_prologue[
+
 #endif /* ! defined PARSER_HEADER_H */]
 ])dnl
 @output @output_parser_name@
@@ -307,7 +310,11 @@ b4_copyright([Skeleton implementation fo
 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 @address@hidden)[
 
Index: data/yacc.c
===================================================================
RCS file: /sources/bison/bison/data/yacc.c,v
retrieving revision 1.143
diff -p -u -r1.143 yacc.c
--- data/yacc.c 10 Jun 2006 03:02:23 -0000      1.143
+++ data/yacc.c 14 Jun 2006 23:44:59 -0000
@@ -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,6 +181,11 @@ b4_locations_if([#define yylloc b4_prefi
 # define YYTOKEN_TABLE ]b4_token_table[
 #endif
 
+/* Copy the first part of user header declarations.  */
+]b4_header_pre_prologue
+
+b4_token_enums_defines(b4_tokens)[
+
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 ]m4_ifdef([b4_stype],
 [typedef union[]m4_bregexp(b4_stype, [^{], [ YYSTYPE])
@@ -207,14 +210,16 @@ 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 header declarations.  */
+]b4_header_post_prologue[
 
 /* Copy the second part of user declarations.  */
-]b4_post_prologue
+]b4_post_prologue[
 
 /* Line __line__ of yacc.c.  */
-b4_syncline(address@hidden@], address@hidden@])[
+]b4_syncline(address@hidden@], address@hidden@])[
 
 #ifdef short
 # undef short
@@ -1489,24 +1494,27 @@ b4_epilogue
 b4_defines_if(
 address@hidden @output_header_name@
 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])[
+
+/* Copy the first part of user header declarations.  */
+]b4_header_pre_prologue
 
 b4_token_enums_defines(b4_tokens)
 
-#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
-m4_ifdef([b4_stype],
+[#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+]m4_ifdef([b4_stype],
 [typedef union[]m4_bregexp(b4_stype, [^{], [ YYSTYPE])
 b4_stype
 /* Line __line__ of yacc.c.  */
 b4_syncline(address@hidden@], address@hidden@])
        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 +1531,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
+)[
+
+/* Copy the second part of user header declarations.  */
+]b4_header_post_prologue
+dnl b4_locations_if
 ])dnl b4_defines_if
Index: doc/bison.texinfo
===================================================================
RCS file: /sources/bison/bison/doc/bison.texinfo,v
retrieving revision 1.193
diff -p -u -r1.193 bison.texinfo
--- doc/bison.texinfo   11 Jun 2006 18:27:44 -0000      1.193
+++ doc/bison.texinfo   14 Jun 2006 23:45:03 -0000
@@ -7437,7 +7437,7 @@ use a forward declaration of the driver.
 
 @comment file: calc++-parser.yy
 @example
address@hidden
address@hidden
 # include <string>
 class calcxx_driver;
 address@hidden
Index: src/files.c
===================================================================
RCS file: /sources/bison/bison/src/files.c,v
retrieving revision 1.95
diff -p -u -r1.95 files.c
--- src/files.c 14 Jan 2006 06:36:04 -0000      1.95
+++ src/files.c 14 Jun 2006 23:45:03 -0000
@@ -37,6 +37,8 @@
 
 struct obstack pre_prologue_obstack;
 struct obstack post_prologue_obstack;
+struct obstack header_pre_prologue_obstack;
+struct obstack header_post_prologue_obstack;
 
 /* Initializing some values below (such SPEC_NAME_PREFIX to `yy') is
    tempting, but don't do that: for the time being our handling of the
Index: src/files.h
===================================================================
RCS file: /sources/bison/bison/src/files.h,v
retrieving revision 1.40
diff -p -u -r1.40 files.h
--- src/files.h 2 Oct 2005 17:44:49 -0000       1.40
+++ src/files.h 14 Jun 2006 23:45:03 -0000
@@ -51,6 +51,8 @@ extern char const *dir_prefix;
 /* If semantic parser, output a .h file that defines YYSTYPE... */
 extern struct obstack pre_prologue_obstack;
 extern struct obstack post_prologue_obstack;
+extern struct obstack header_pre_prologue_obstack;
+extern struct obstack header_post_prologue_obstack;
 
 /* The file name as given on the command line.
    Not named "input_file" because Flex uses this name for an argument,
Index: src/output.c
===================================================================
RCS file: /sources/bison/bison/src/output.c,v
retrieving revision 1.250
diff -p -u -r1.250 output.c
--- src/output.c        11 Jun 2006 18:27:44 -0000      1.250
+++ src/output.c        14 Jun 2006 23:45:03 -0000
@@ -610,6 +610,12 @@ prepare (void)
   obstack_1grow (&post_prologue_obstack, 0);
   muscle_insert ("pre_prologue", obstack_finish (&pre_prologue_obstack));
   muscle_insert ("post_prologue", obstack_finish (&post_prologue_obstack));
+  obstack_1grow (&header_pre_prologue_obstack, 0);
+  obstack_1grow (&header_post_prologue_obstack, 0);
+  muscle_insert ("header_pre_prologue",
+                obstack_finish (&header_pre_prologue_obstack));
+  muscle_insert ("header_post_prologue",
+                obstack_finish (&header_post_prologue_obstack));
 
   /* Find the right skeleton file.  */
   if (!skeleton)
@@ -651,4 +657,6 @@ output (void)
   obstack_free (&format_obstack, NULL);
   obstack_free (&pre_prologue_obstack, NULL);
   obstack_free (&post_prologue_obstack, NULL);
+  obstack_free (&header_pre_prologue_obstack, NULL);
+  obstack_free (&header_post_prologue_obstack, NULL);
 }
Index: src/parse-gram.y
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.y,v
retrieving revision 1.75
diff -p -u -r1.75 parse-gram.y
--- src/parse-gram.y    6 Jun 2006 16:40:06 -0000       1.75
+++ src/parse-gram.y    14 Jun 2006 23:45:04 -0000
@@ -58,6 +58,7 @@ static uniqstr current_type = 0;
 static symbol *current_lhs;
 static location current_lhs_location;
 static int current_prec = 0;
+static enum { BEFORE_HEADER, DURING_HEADER, AFTER_HEADER } header_position;
 
 #ifdef UINT_FAST8_MAX
 # define YYTYPE_UINT8 uint_fast8_t
@@ -165,19 +166,20 @@ static int current_prec = 0;
 %token ID_COLON        "identifier:"
 %token PERCENT_PERCENT "%%"
 %token PROLOGUE        "%{...%}"
+%token HEADER_PROLOGUE "%header{...%}"
 %token EPILOGUE        "epilogue"
 %token BRACED_CODE     "{...}"
 
 %type <chars> STRING string_content
              "{...}"
              "%union {...}"
-             PROLOGUE EPILOGUE
+             PROLOGUE HEADER_PROLOGUE EPILOGUE
 %printer { fprintf (stderr, "\"%s\"", $$); }
              STRING string_content
 %printer { fprintf (stderr, "{\n%s\n}", $$); }
              "{...}"
              "%union {...}"
-             PROLOGUE EPILOGUE
+             PROLOGUE HEADER_PROLOGUE EPILOGUE
 %type <uniqstr> TYPE
 %printer { fprintf (stderr, "<%s>", $$); } TYPE
 %type <integer> INT
@@ -206,8 +208,36 @@ declarations:
 
 declaration:
   grammar_declaration
-| PROLOGUE                         { prologue_augment (translate_code ($1, @1),
-                                                      @1); }
+| PROLOGUE
+    {
+      switch (header_position)
+       {
+         case DURING_HEADER:
+           header_position = AFTER_HEADER;
+           break;
+          default:
+            break;
+       }
+      prologue_augment (translate_code ($1, @1), @1, false);
+  
+    }
+| HEADER_PROLOGUE
+    {
+      switch (header_position)
+       {
+         case BEFORE_HEADER:
+           header_position = DURING_HEADER;
+           break;
+         case AFTER_HEADER:
+           complain_at (@1, _("a `%%{...%%}' appears between here and the"
+                              " previous `%%union {...}' or `%%header{...%%}'"
+                              " declaration"));
+           break;
+          default:
+            break;
+       }
+      prologue_augment (translate_code ($1, @1), @1, true);
+    }
 | "%debug"                                 { debug_flag = true; }
 | "%define" string_content
     {
@@ -256,6 +286,20 @@ grammar_declaration:
     {
       char const *body = $1;
 
+      switch (header_position)
+       {
+         case BEFORE_HEADER:
+           header_position = DURING_HEADER;
+           break;
+         case AFTER_HEADER:
+           complain_at (@1, _("a `%%{...%%}' appears between here and the"
+                              " previous `%%union {...}' or `%%header{...%%}'"
+                              " declaration"));
+           break;
+          default:
+            break;
+       }
+
       if (typed)
        {
          /* Concatenate the union bodies, turning the first one's
Index: src/reader.c
===================================================================
RCS file: /sources/bison/bison/src/reader.c,v
retrieving revision 1.255
diff -p -u -r1.255 reader.c
--- src/reader.c        6 Jun 2006 16:40:06 -0000       1.255
+++ src/reader.c        14 Jun 2006 23:45:04 -0000
@@ -68,16 +68,25 @@ grammar_start_symbol_set (symbol *sym, l
 }
 
 
-/*----------------------------------------------------------------.
-| There are two prologues: one before %union, one after.  Augment |
-| the current one.                                                |
-`----------------------------------------------------------------*/
+/*-----------------------------------------------------------------.
+| There are four prologues: two before %union, two after.  In each |
+| pair, there is a header and a non-header prologue.  Augment the  |
+| current one.                                                     |
+`-----------------------------------------------------------------*/
 
 void
-prologue_augment (const char *prologue, location loc)
+prologue_augment (const char *prologue, location loc, bool header)
 {
-  struct obstack *oout =
-    !typed ? &pre_prologue_obstack : &post_prologue_obstack;
+  struct obstack *oout;
+  if (header)
+    {
+      oout =
+       !typed ? &header_pre_prologue_obstack : &header_post_prologue_obstack;
+    }
+  else
+    {
+      oout = !typed ? &pre_prologue_obstack : &post_prologue_obstack;
+    }
 
   obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line);
   /* FIXME: Protection of M4 characters missing here.  See
@@ -517,6 +526,8 @@ reader (void)
   /* Initialize the obstacks. */
   obstack_init (&pre_prologue_obstack);
   obstack_init (&post_prologue_obstack);
+  obstack_init (&header_pre_prologue_obstack);
+  obstack_init (&header_post_prologue_obstack);
 
   gram_in = xfopen (grammar_file, "r");
 
Index: src/reader.h
===================================================================
RCS file: /sources/bison/bison/src/reader.h,v
retrieving revision 1.50
diff -p -u -r1.50 reader.h
--- src/reader.h        6 Jun 2006 16:40:06 -0000       1.50
+++ src/reader.h        14 Jun 2006 23:45:04 -0000
@@ -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 header);
 void grammar_current_rule_begin (symbol *lhs, location loc);
 void grammar_current_rule_end (location loc);
 void grammar_midrule_action (void);
Index: src/scan-gram.l
===================================================================
RCS file: /sources/bison/bison/src/scan-gram.l,v
retrieving revision 1.90
diff -p -u -r1.90 scan-gram.l
--- src/scan-gram.l     7 Jun 2006 21:17:35 -0000       1.90
+++ src/scan-gram.l     14 Jun 2006 23:45:05 -0000
@@ -92,11 +92,12 @@ static void unexpected_newline (boundary
     %printer). */
 %x SC_PRE_CODE
 
- /* Three types of user code:
+ /* Four types of user code:
     - prologue (code between `%{' `%}' in the first section, before %%);
+    - header prologue (same as prologue but starts with `%header{');
     - actions, printers, union, etc, (between braced in the middle section);
     - epilogue (everything after the second %%). */
-%x SC_PROLOGUE SC_BRACED_CODE SC_EPILOGUE
+%x SC_PROLOGUE SC_HEADER_PROLOGUE SC_BRACED_CODE SC_EPILOGUE
  /* C and C++ comments in code. */
 %x SC_COMMENT SC_LINE_COMMENT
  /* Strings and characters in code. */
@@ -243,6 +244,9 @@ splice       (\\[ \f\t\v]*\n)*
   /* Prologue. */
   "%{"        code_start = loc->start; BEGIN SC_PROLOGUE;
 
+  /* Header prologue. */
+  "%header{"  code_start = loc->start; BEGIN SC_HEADER_PROLOGUE;
+
   /* Code in between braces.  */
   "{" {
     if (current_rule && current_rule->action)
@@ -473,7 +477,7 @@ splice       (\\[ \f\t\v]*\n)*
   | Strings, comments etc. can be found in user code.  |
   `---------------------------------------------------*/
 
-<SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE>
+<SC_BRACED_CODE,SC_PROLOGUE,SC_HEADER_PROLOGUE,SC_EPILOGUE>
 {
   "'" {
     STRING_GROW;
@@ -568,9 +572,9 @@ splice       (\\[ \f\t\v]*\n)*
 }
 
 
-  /*--------------------------------------------------------------.
-  | Scanning some prologue: from "%{" (already scanned) to "%}".  |
-  `--------------------------------------------------------------*/
+  
/*---------------------------------------------------------------------------.
+  | Scanning some prologue: from "%{" or "%header{" (already scanned) to "%}". 
|
+  
`---------------------------------------------------------------------------*/
 
 <SC_PROLOGUE>
 {
@@ -582,6 +586,21 @@ splice      (\\[ \f\t\v]*\n)*
     return PROLOGUE;
   }
 
+}
+
+<SC_HEADER_PROLOGUE>
+{
+  "%}" {
+    STRING_FINISH;
+    loc->start = code_start;
+    val->chars = last_string;
+    BEGIN INITIAL;
+    return HEADER_PROLOGUE;
+  }
+}
+
+<SC_PROLOGUE,SC_HEADER_PROLOGUE>
+{
   <<EOF>>  unexpected_eof (code_start, "%}"); BEGIN INITIAL;
 }
 
@@ -607,8 +626,8 @@ splice       (\\[ \f\t\v]*\n)*
   | By default, grow the string obstack with the input.  |
   `-----------------------------------------------------*/
 
-<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>.
     |
-<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PROLOGUE,SC_EPILOGUE>\n  
STRING_GROW;
+<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PROLOGUE,SC_HEADER_PROLOGUE,SC_EPILOGUE,SC_STRING,SC_CHARACTER,SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>.
  |
+<SC_COMMENT,SC_LINE_COMMENT,SC_BRACED_CODE,SC_PROLOGUE,SC_HEADER_PROLOGUE,SC_EPILOGUE>\n
       STRING_GROW;
 
 %%
 
Index: tests/actions.at
===================================================================
RCS file: /sources/bison/bison/tests/actions.at,v
retrieving revision 1.58
diff -p -u -r1.58 actions.at
--- tests/actions.at    4 Jan 2006 09:18:37 -0000       1.58
+++ tests/actions.at    14 Jun 2006 23:45:05 -0000
@@ -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]],
-[[%{
+[[%header{
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
@@ -191,7 +191,7 @@ m4_ifval([$6], [%union
 }])
 AT_LALR1_CC_IF([%define "global_tokens_and_yystype"])
 [
-%{
+%header{
 ]AT_LALR1_CC_IF([typedef yy::location YYLTYPE;
                 m4_ifval([$6], , [#define YYSTYPE int])])
 [static int yylex (]AT_LEX_FORMALS[);
Index: tests/regression.at
===================================================================
RCS file: /sources/bison/bison/tests/regression.at,v
retrieving revision 1.100
diff -p -u -r1.100 regression.at
--- tests/regression.at 11 Jun 2006 18:27:44 -0000      1.100
+++ tests/regression.at 14 Jun 2006 23:45:05 -0000
@@ -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;
Index: src/parse-gram.c
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.c,v
retrieving revision 1.115
diff -p -u -r1.115 parse-gram.c
--- src/parse-gram.c    10 Jun 2006 03:02:23 -0000      1.115
+++ src/parse-gram.c    14 Jun 2006 23:45:04 -0000
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.1b.  */
+/* A Bison parser, made by GNU Bison 2.3+.  */
 
 /* Skeleton implementation for Bison's Yacc-like parsers in C
 
@@ -47,7 +47,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.1b"
+#define YYBISON_VERSION "2.3+"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -68,6 +68,105 @@
 #define yynerrs gram_nerrs
 #define yylloc gram_lloc
 
+/* Copy the first part of user declarations.  */
+#line 1 "parse-gram.y"
+/* Bison Grammar Parser                             -*- C -*-
+
+   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+
+   This file is part of Bison, the GNU Compiler Compiler.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301  USA
+*/
+
+#include <config.h>
+#include "system.h"
+
+#include "complain.h"
+#include "conflicts.h"
+#include "files.h"
+#include "getargs.h"
+#include "gram.h"
+#include "muscle_tab.h"
+#include "quotearg.h"
+#include "reader.h"
+#include "symlist.h"
+#include "scan-gram.h"
+#include "scan-code.h"
+#include "strverscmp.h"
+
+#define YYLLOC_DEFAULT(Current, Rhs, N)  (Current) = lloc_default (Rhs, N)
+static YYLTYPE lloc_default (YYLTYPE const *, int);
+
+#define YY_LOCATION_PRINT(File, Loc) \
+         location_print (File, Loc)
+
+static void version_check (location const *loc, char const *version);
+
+/* Request detailed syntax error messages, and pass them to GRAM_ERROR.
+   FIXME: depends on the undocumented availability of YYLLOC.  */
+#undef  yyerror
+#define yyerror(Msg) \
+       gram_error (&yylloc, Msg)
+static void gram_error (location const *, char const *);
+
+static void add_param (char const *, char *, location);
+
+static symbol_class current_class = unknown_sym;
+static uniqstr current_type = 0;
+static symbol *current_lhs;
+static location current_lhs_location;
+static int current_prec = 0;
+static enum { BEFORE_HEADER, DURING_HEADER, AFTER_HEADER } header_position;
+
+#ifdef UINT_FAST8_MAX
+# define YYTYPE_UINT8 uint_fast8_t
+#endif
+#ifdef INT_FAST8_MAX
+# define YYTYPE_INT8 int_fast8_t
+#endif
+#ifdef UINT_FAST16_MAX
+# define YYTYPE_UINT16 uint_fast16_t
+#endif
+#ifdef INT_FAST16_MAX
+# define YYTYPE_INT16 int_fast16_t
+#endif
+
+
+/* Enabling traces.  */
+#ifndef YYDEBUG
+# define YYDEBUG 1
+#endif
+
+/* Enabling verbose error messages.  */
+#ifdef YYERROR_VERBOSE
+# undef YYERROR_VERBOSE
+# define YYERROR_VERBOSE 1
+#else
+# define YYERROR_VERBOSE 1
+#endif
+
+/* Enabling the token table.  */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE 0
+#endif
+
+/* Copy the first part of user header declarations.  */
+
+
 /* Tokens.  */
 #ifndef YYTOKENTYPE
 # define YYTOKENTYPE
@@ -122,8 +221,9 @@
      ID_COLON = 302,
      PERCENT_PERCENT = 303,
      PROLOGUE = 304,
-     EPILOGUE = 305,
-     BRACED_CODE = 306
+     HEADER_PROLOGUE = 305,
+     EPILOGUE = 306,
+     BRACED_CODE = 307
    };
 #endif
 /* Tokens.  */
@@ -175,110 +275,16 @@
 #define ID_COLON 302
 #define PERCENT_PERCENT 303
 #define PROLOGUE 304
-#define EPILOGUE 305
-#define BRACED_CODE 306
-
-
+#define HEADER_PROLOGUE 305
+#define EPILOGUE 306
+#define BRACED_CODE 307
 
 
-/* Copy the first part of user declarations.  */
-#line 1 "../../src/parse-gram.y"
-/* Bison Grammar Parser                             -*- C -*-
 
-   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
-
-   This file is part of Bison, the GNU Compiler Compiler.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301  USA
-*/
-
-#include <config.h>
-#include "system.h"
-
-#include "complain.h"
-#include "conflicts.h"
-#include "files.h"
-#include "getargs.h"
-#include "gram.h"
-#include "muscle_tab.h"
-#include "quotearg.h"
-#include "reader.h"
-#include "symlist.h"
-#include "scan-gram.h"
-#include "scan-code.h"
-#include "strverscmp.h"
-
-#define YYLLOC_DEFAULT(Current, Rhs, N)  (Current) = lloc_default (Rhs, N)
-static YYLTYPE lloc_default (YYLTYPE const *, int);
-
-#define YY_LOCATION_PRINT(File, Loc) \
-         location_print (File, Loc)
-
-static void version_check (location const *loc, char const *version);
-
-/* Request detailed syntax error messages, and pass them to GRAM_ERROR.
-   FIXME: depends on the undocumented availability of YYLLOC.  */
-#undef  yyerror
-#define yyerror(Msg) \
-       gram_error (&yylloc, Msg)
-static void gram_error (location const *, char const *);
-
-static void add_param (char const *, char *, location);
-
-static symbol_class current_class = unknown_sym;
-static uniqstr current_type = 0;
-static symbol *current_lhs;
-static location current_lhs_location;
-static int current_prec = 0;
-
-#ifdef UINT_FAST8_MAX
-# define YYTYPE_UINT8 uint_fast8_t
-#endif
-#ifdef INT_FAST8_MAX
-# define YYTYPE_INT8 int_fast8_t
-#endif
-#ifdef UINT_FAST16_MAX
-# define YYTYPE_UINT16 uint_fast16_t
-#endif
-#ifdef INT_FAST16_MAX
-# define YYTYPE_INT16 int_fast16_t
-#endif
-
-
-/* Enabling traces.  */
-#ifndef YYDEBUG
-# define YYDEBUG 1
-#endif
-
-/* Enabling verbose error messages.  */
-#ifdef YYERROR_VERBOSE
-# undef YYERROR_VERBOSE
-# define YYERROR_VERBOSE 1
-#else
-# define YYERROR_VERBOSE 1
-#endif
-
-/* Enabling the token table.  */
-#ifndef YYTOKEN_TABLE
-# define YYTOKEN_TABLE 0
-#endif
 
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 95 "../../src/parse-gram.y"
+#line 96 "parse-gram.y"
 {
   symbol *symbol;
   symbol_list *list;
@@ -287,8 +293,8 @@ typedef union YYSTYPE
   assoc assoc;
   uniqstr uniqstr;
 }
-/* Line 193 of yacc.c.  */
-#line 292 "../../src/parse-gram.c"
+/* Line 196 of yacc.c.  */
+#line 298 "parse-gram.c"
        YYSTYPE;
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
@@ -308,12 +314,14 @@ typedef struct YYLTYPE
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
 
+/* Copy the second part of user header declarations.  */
+
 
 /* Copy the second part of user declarations.  */
 
 
-/* Line 216 of yacc.c.  */
-#line 317 "../../src/parse-gram.c"
+/* Line __line__ of yacc.c.  */
+#line 325 "parse-gram.c"
 
 #ifdef short
 # undef short
@@ -530,20 +538,20 @@ union yyalloc
 /* YYFINAL -- State number of the termination state.  */
 #define YYFINAL  3
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   164
+#define YYLAST   166
 
 /* YYNTOKENS -- Number of terminals.  */
-#define YYNTOKENS  52
+#define YYNTOKENS  53
 /* YYNNTS -- Number of nonterminals.  */
 #define YYNNTS  24
 /* YYNRULES -- Number of rules.  */
-#define YYNRULES  80
+#define YYNRULES  81
 /* YYNRULES -- Number of states.  */
-#define YYNSTATES  114
+#define YYNSTATES  115
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
 #define YYUNDEFTOK  2
-#define YYMAXUTOK   306
+#define YYMAXUTOK   307
 
 #define YYTRANSLATE(YYX)                                               \
   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -581,7 +589,7 @@ static const yytype_uint8 yytranslate[] 
       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
-      45,    46,    47,    48,    49,    50,    51
+      45,    46,    47,    48,    49,    50,    51,    52
 };
 
 #if YYDEBUG
@@ -589,55 +597,56 @@ static const yytype_uint8 yytranslate[] 
    YYRHS.  */
 static const yytype_uint8 yyprhs[] =
 {
-       0,     0,     3,     8,     9,    12,    14,    16,    18,    21,
-      25,    27,    29,    32,    35,    39,    41,    44,    47,    49,
-      53,    55,    57,    61,    64,    66,    69,    72,    74,    76,
-      78,    80,    82,    84,    87,    89,    93,    97,    99,   101,
-     102,   106,   107,   111,   115,   119,   121,   123,   125,   126,
-     128,   130,   133,   135,   137,   140,   143,   147,   149,   152,
-     154,   157,   159,   162,   165,   166,   170,   172,   176,   179,
-     180,   183,   186,   190,   194,   198,   200,   202,   204,   206,
-     207
+       0,     0,     3,     8,     9,    12,    14,    16,    18,    20,
+      23,    27,    29,    31,    34,    37,    41,    43,    46,    49,
+      51,    55,    57,    59,    63,    66,    68,    71,    74,    76,
+      78,    80,    82,    84,    86,    89,    91,    95,    99,   101,
+     103,   104,   108,   109,   113,   117,   121,   123,   125,   127,
+     128,   130,   132,   135,   137,   139,   142,   145,   149,   151,
+     154,   156,   159,   161,   164,   167,   168,   172,   174,   178,
+     181,   182,   185,   188,   192,   196,   200,   202,   204,   206,
+     208,   209
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
 static const yytype_int8 yyrhs[] =
 {
-      53,     0,    -1,    54,    48,    66,    75,    -1,    -1,    54,
-      55,    -1,    56,    -1,    49,    -1,    17,    -1,    19,    74,
-      -1,    19,    74,    74,    -1,    20,    -1,    21,    -1,    22,
-       4,    -1,    23,     4,    -1,    24,    43,    74,    -1,    25,
-      -1,    26,    51,    -1,    27,    51,    -1,    28,    -1,    29,
-      43,    74,    -1,    31,    -1,    32,    -1,    33,    43,    74,
-      -1,    34,    51,    -1,    35,    -1,    36,    74,    -1,    37,
-      74,    -1,    39,    -1,    40,    -1,    41,    -1,    44,    -1,
-      60,    -1,    57,    -1,    38,    72,    -1,    10,    -1,     8,
-      51,    63,    -1,     9,    51,    63,    -1,    18,    -1,    30,
-      -1,    -1,     6,    58,    65,    -1,    -1,     5,    59,    65,
-      -1,     7,    42,    63,    -1,    61,    62,    63,    -1,    11,
-      -1,    12,    -1,    13,    -1,    -1,    42,    -1,    72,    -1,
-      63,    72,    -1,    42,    -1,    46,    -1,    46,     4,    -1,
-      46,    73,    -1,    46,     4,    73,    -1,    64,    -1,    65,
-      64,    -1,    67,    -1,    66,    67,    -1,    68,    -1,    56,
-      44,    -1,     1,    44,    -1,    -1,    47,    69,    70,    -1,
-      71,    -1,    70,    45,    71,    -1,    70,    44,    -1,    -1,
-      71,    72,    -1,    71,    51,    -1,    71,    14,    72,    -1,
-      71,    15,     4,    -1,    71,    16,    42,    -1,    46,    -1,
-      73,    -1,     3,    -1,     3,    -1,    -1,    48,    50,    -1
+      54,     0,    -1,    55,    48,    67,    76,    -1,    -1,    55,
+      56,    -1,    57,    -1,    49,    -1,    50,    -1,    17,    -1,
+      19,    75,    -1,    19,    75,    75,    -1,    20,    -1,    21,
+      -1,    22,     4,    -1,    23,     4,    -1,    24,    43,    75,
+      -1,    25,    -1,    26,    52,    -1,    27,    52,    -1,    28,
+      -1,    29,    43,    75,    -1,    31,    -1,    32,    -1,    33,
+      43,    75,    -1,    34,    52,    -1,    35,    -1,    36,    75,
+      -1,    37,    75,    -1,    39,    -1,    40,    -1,    41,    -1,
+      44,    -1,    61,    -1,    58,    -1,    38,    73,    -1,    10,
+      -1,     8,    52,    64,    -1,     9,    52,    64,    -1,    18,
+      -1,    30,    -1,    -1,     6,    59,    66,    -1,    -1,     5,
+      60,    66,    -1,     7,    42,    64,    -1,    62,    63,    64,
+      -1,    11,    -1,    12,    -1,    13,    -1,    -1,    42,    -1,
+      73,    -1,    64,    73,    -1,    42,    -1,    46,    -1,    46,
+       4,    -1,    46,    74,    -1,    46,     4,    74,    -1,    65,
+      -1,    66,    65,    -1,    68,    -1,    67,    68,    -1,    69,
+      -1,    57,    44,    -1,     1,    44,    -1,    -1,    47,    70,
+      71,    -1,    72,    -1,    71,    45,    72,    -1,    71,    44,
+      -1,    -1,    72,    73,    -1,    72,    52,    -1,    72,    14,
+      73,    -1,    72,    15,     4,    -1,    72,    16,    42,    -1,
+      46,    -1,    74,    -1,     3,    -1,     3,    -1,    -1,    48,
+      51,    -1
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
-       0,   194,   194,   202,   204,   208,   209,   211,   212,   217,
-     218,   219,   220,   221,   222,   223,   228,   232,   233,   234,
-     235,   236,   237,   238,   239,   240,   241,   242,   243,   244,
-     245,   249,   250,   251,   255,   271,   279,   287,   291,   298,
-     298,   303,   303,   308,   318,   333,   334,   335,   339,   340,
-     345,   346,   351,   355,   360,   366,   372,   383,   384,   393,
-     394,   400,   401,   402,   409,   409,   413,   414,   415,   420,
-     421,   423,   426,   428,   430,   435,   436,   441,   450,   455,
-     457
+       0,   196,   196,   204,   206,   210,   211,   224,   241,   242,
+     247,   248,   249,   250,   251,   252,   253,   258,   262,   263,
+     264,   265,   266,   267,   268,   269,   270,   271,   272,   273,
+     274,   275,   279,   280,   281,   285,   315,   323,   331,   335,
+     342,   342,   347,   347,   352,   362,   377,   378,   379,   383,
+     384,   389,   390,   395,   399,   404,   410,   416,   427,   428,
+     437,   438,   444,   445,   446,   453,   453,   457,   458,   459,
+     464,   465,   467,   470,   472,   474,   479,   480,   485,   494,
+     499,   501
 };
 #endif
 
@@ -658,8 +667,8 @@ static const char *const yytname[] =
   "\"%pure-parser\"", "\"%require\"", "\"%skeleton\"", "\"%start\"",
   "\"%token-table\"", "\"%verbose\"", "\"%yacc\"", "\"type\"", "\"=\"",
   "\";\"", "\"|\"", "\"identifier\"", "\"identifier:\"", "\"%%\"",
-  "\"%{...%}\"", "\"epilogue\"", "\"{...}\"", "$accept", "input",
-  "declarations", "declaration", "grammar_declaration",
+  "\"%{...%}\"", "\"%header{...%}\"", "\"epilogue\"", "\"{...}\"",
+  "$accept", "input", "declarations", "declaration", "grammar_declaration",
   "symbol_declaration", "@1", "@2", "precedence_declaration",
   "precedence_declarator", "type.opt", "symbols.1", "symbol_def",
   "symbol_defs.1", "grammar", "rules_or_grammar_declaration", "rules",
@@ -678,36 +687,36 @@ static const yytype_uint16 yytoknum[] =
      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
      295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
-     305,   306
+     305,   306,   307
 };
 # endif
 
 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
 static const yytype_uint8 yyr1[] =
 {
-       0,    52,    53,    54,    54,    55,    55,    55,    55,    55,
-      55,    55,    55,    55,    55,    55,    55,    55,    55,    55,
-      55,    55,    55,    55,    55,    55,    55,    55,    55,    55,
-      55,    56,    56,    56,    56,    56,    56,    56,    56,    58,
-      57,    59,    57,    57,    60,    61,    61,    61,    62,    62,
-      63,    63,    64,    64,    64,    64,    64,    65,    65,    66,
-      66,    67,    67,    67,    69,    68,    70,    70,    70,    71,
-      71,    71,    71,    71,    71,    72,    72,    73,    74,    75,
-      75
+       0,    53,    54,    55,    55,    56,    56,    56,    56,    56,
+      56,    56,    56,    56,    56,    56,    56,    56,    56,    56,
+      56,    56,    56,    56,    56,    56,    56,    56,    56,    56,
+      56,    56,    57,    57,    57,    57,    57,    57,    57,    57,
+      59,    58,    60,    58,    58,    61,    62,    62,    62,    63,
+      63,    64,    64,    65,    65,    65,    65,    65,    66,    66,
+      67,    67,    68,    68,    68,    70,    69,    71,    71,    71,
+      72,    72,    72,    72,    72,    72,    73,    73,    74,    75,
+      76,    76
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
 static const yytype_uint8 yyr2[] =
 {
-       0,     2,     4,     0,     2,     1,     1,     1,     2,     3,
-       1,     1,     2,     2,     3,     1,     2,     2,     1,     3,
-       1,     1,     3,     2,     1,     2,     2,     1,     1,     1,
-       1,     1,     1,     2,     1,     3,     3,     1,     1,     0,
-       3,     0,     3,     3,     3,     1,     1,     1,     0,     1,
-       1,     2,     1,     1,     2,     2,     3,     1,     2,     1,
-       2,     1,     2,     2,     0,     3,     1,     3,     2,     0,
-       2,     2,     3,     3,     3,     1,     1,     1,     1,     0,
-       2
+       0,     2,     4,     0,     2,     1,     1,     1,     1,     2,
+       3,     1,     1,     2,     2,     3,     1,     2,     2,     1,
+       3,     1,     1,     3,     2,     1,     2,     2,     1,     1,
+       1,     1,     1,     1,     2,     1,     3,     3,     1,     1,
+       0,     3,     0,     3,     3,     3,     1,     1,     1,     0,
+       1,     1,     2,     1,     1,     2,     2,     3,     1,     2,
+       1,     2,     1,     2,     2,     0,     3,     1,     3,     2,
+       0,     2,     2,     3,     3,     3,     1,     1,     1,     1,
+       0,     2
 };
 
 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
@@ -715,118 +724,118 @@ static const yytype_uint8 yyr2[] =
    means the default is an error.  */
 static const yytype_uint8 yydefact[] =
 {
-       3,     0,     0,     1,    41,    39,     0,     0,     0,    34,
-      45,    46,    47,     7,    37,     0,    10,    11,     0,     0,
-       0,    15,     0,     0,    18,     0,    38,    20,    21,     0,
-       0,    24,     0,     0,     0,    27,    28,    29,    30,     0,
-       6,     4,     5,    32,    31,    48,     0,     0,     0,     0,
-       0,    78,     8,    12,    13,     0,    16,    17,     0,     0,
-      23,    25,    26,    77,    75,    33,    76,     0,    64,     0,
-       0,    59,    61,    49,     0,    52,    53,    57,    42,    40,
-      43,    50,    35,    36,     9,    14,    19,    22,    63,    69,
-      62,     0,    60,     2,    44,    54,    55,    58,    51,    65,
-      66,    80,    56,    68,    69,     0,     0,     0,    71,    70,
-      67,    72,    73,    74
+       3,     0,     0,     1,    42,    40,     0,     0,     0,    35,
+      46,    47,    48,     8,    38,     0,    11,    12,     0,     0,
+       0,    16,     0,     0,    19,     0,    39,    21,    22,     0,
+       0,    25,     0,     0,     0,    28,    29,    30,    31,     0,
+       6,     7,     4,     5,    33,    32,    49,     0,     0,     0,
+       0,     0,    79,     9,    13,    14,     0,    17,    18,     0,
+       0,    24,    26,    27,    78,    76,    34,    77,     0,    65,
+       0,     0,    60,    62,    50,     0,    53,    54,    58,    43,
+      41,    44,    51,    36,    37,    10,    15,    20,    23,    64,
+      70,    63,     0,    61,     2,    45,    55,    56,    59,    52,
+      66,    67,    81,    57,    69,    70,     0,     0,     0,    72,
+      71,    68,    73,    74,    75
 };
 
 /* YYDEFGOTO[NTERM-NUM].  */
 static const yytype_int8 yydefgoto[] =
 {
-      -1,     1,     2,    41,    69,    43,    47,    46,    44,    45,
-      74,    80,    77,    78,    70,    71,    72,    89,    99,   100,
-      81,    66,    52,    93
+      -1,     1,     2,    42,    70,    44,    48,    47,    45,    46,
+      75,    81,    78,    79,    71,    72,    73,    90,   100,   101,
+      82,    67,    53,    94
 };
 
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-#define YYPACT_NINF -72
+#define YYPACT_NINF -59
 static const yytype_int8 yypact[] =
 {
-     -72,     7,   115,   -72,   -72,   -72,   -22,   -17,   -16,   -72,
-     -72,   -72,   -72,   -72,   -72,    26,   -72,   -72,    32,    33,
-      -3,   -72,    -8,    -6,   -72,     4,   -72,   -72,   -72,     9,
-       2,   -72,    26,    26,    -2,   -72,   -72,   -72,   -72,    72,
-     -72,   -72,   -72,   -72,   -72,    12,   -40,   -40,    -2,    -2,
-      -2,   -72,    26,   -72,   -72,    26,   -72,   -72,    26,    26,
-     -72,   -72,   -72,   -72,   -72,   -72,   -72,    11,   -72,    13,
-       3,   -72,   -72,   -72,    -2,   -72,    19,   -72,   -40,   -40,
-      -2,   -72,    -2,    -2,   -72,   -72,   -72,   -72,   -72,   -72,
-     -72,    18,   -72,   -72,    -2,    53,   -72,   -72,   -72,   -19,
-      16,   -72,   -72,   -72,   -72,    -2,    55,    21,   -72,   -72,
-      16,   -72,   -72,   -72
+     -59,     3,   116,   -59,   -59,   -59,   -24,   -47,   -32,   -59,
+     -59,   -59,   -59,   -59,   -59,    29,   -59,   -59,    31,    37,
+       5,   -59,     0,     1,   -59,    12,   -59,   -59,   -59,    13,
+       6,   -59,    29,    29,    -2,   -59,   -59,   -59,   -59,    73,
+     -59,   -59,   -59,   -59,   -59,   -59,    15,   -38,   -38,    -2,
+      -2,    -2,   -59,    29,   -59,   -59,    29,   -59,   -59,    29,
+      29,   -59,   -59,   -59,   -59,   -59,   -59,   -59,    18,   -59,
+      21,    16,   -59,   -59,   -59,    -2,   -59,     8,   -59,   -38,
+     -38,    -2,   -59,    -2,    -2,   -59,   -59,   -59,   -59,   -59,
+     -59,   -59,     9,   -59,   -59,    -2,    56,   -59,   -59,   -59,
+      -5,    -1,   -59,   -59,   -59,   -59,    -2,    62,    26,   -59,
+     -59,    -1,   -59,   -59,   -59
 };
 
 /* YYPGOTO[NTERM-NUM].  */
 static const yytype_int8 yypgoto[] =
 {
-     -72,   -72,   -72,   -72,    67,   -72,   -72,   -72,   -72,   -72,
-     -72,   -32,   -51,    23,   -72,     5,   -72,   -72,   -72,   -30,
-     -34,   -71,     6,   -72
+     -59,   -59,   -59,   -59,    67,   -59,   -59,   -59,   -59,   -59,
+     -59,   -44,   -37,    22,   -59,     2,   -59,   -59,   -59,   -30,
+     -34,   -58,   -23,   -59
 };
 
 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
    positive, shift that token.  If negative, reduce the rule which
    number is the opposite.  If zero, do what YYDEFACT says.
    If YYTABLE_NINF, syntax error.  */
-#define YYTABLE_NINF -80
+#define YYTABLE_NINF -81
 static const yytype_int8 yytable[] =
 {
-      65,    63,    75,   -79,    67,    96,    76,     3,     4,     5,
-       6,     7,     8,     9,    10,    11,    12,    82,    83,    63,
-      48,    14,    63,    95,   102,   103,   104,    97,    97,    51,
-     105,   106,   107,    26,    49,    50,    53,    54,    61,    62,
-      55,    34,    94,    56,    64,    57,    98,    58,    98,    98,
-      68,    91,    59,    60,    73,    88,    63,    90,    84,   112,
-      98,    85,    64,   113,    86,    87,   109,   108,   101,    42,
-      79,   111,     0,    67,   110,    92,   109,     4,     5,     6,
-       7,     8,     9,    10,    11,    12,     0,     0,     0,     0,
-      14,     0,     0,     0,     0,     0,     0,     0,     0,     0,
-       0,     0,    26,     0,     0,     0,     0,     0,     0,     0,
-      34,     0,     0,     0,     0,     0,     0,     0,     0,    68,
-       4,     5,     6,     7,     8,     9,    10,    11,    12,     0,
-       0,     0,    13,    14,    15,    16,    17,    18,    19,    20,
-      21,    22,    23,    24,    25,    26,    27,    28,    29,    30,
-      31,    32,    33,    34,    35,    36,    37,     0,     0,    38,
-       0,     0,     0,    39,    40
+      66,    64,    64,     3,    76,    50,    83,    84,    77,    62,
+      63,    64,    96,   106,   107,   108,   -80,    68,    49,    97,
+      51,     4,     5,     6,     7,     8,     9,    10,    11,    12,
+      85,    95,    52,    86,    14,    54,    87,    88,   103,   104,
+     105,    55,    98,    98,    65,    65,    26,    99,    56,    99,
+      99,   109,    57,    58,    34,    59,    60,    74,    61,    64,
+     102,    99,    89,    69,    92,    91,   113,   110,   114,    43,
+      80,     0,   112,    93,    68,   111,     0,   110,     4,     5,
+       6,     7,     8,     9,    10,    11,    12,     0,     0,     0,
+       0,    14,     0,     0,     0,     0,     0,     0,     0,     0,
+       0,     0,     0,    26,     0,     0,     0,     0,     0,     0,
+       0,    34,     0,     0,     0,     0,     0,     0,     0,     0,
+      69,     4,     5,     6,     7,     8,     9,    10,    11,    12,
+       0,     0,     0,    13,    14,    15,    16,    17,    18,    19,
+      20,    21,    22,    23,    24,    25,    26,    27,    28,    29,
+      30,    31,    32,    33,    34,    35,    36,    37,     0,     0,
+      38,     0,     0,     0,    39,    40,    41
 };
 
 static const yytype_int8 yycheck[] =
 {
-      34,     3,    42,     0,     1,    76,    46,     0,     5,     6,
-       7,     8,     9,    10,    11,    12,    13,    49,    50,     3,
-      42,    18,     3,     4,    95,    44,    45,    78,    79,     3,
-      14,    15,    16,    30,    51,    51,     4,     4,    32,    33,
-      43,    38,    74,    51,    46,    51,    80,    43,    82,    83,
-      47,    48,    43,    51,    42,    44,     3,    44,    52,     4,
-      94,    55,    46,    42,    58,    59,   100,    51,    50,     2,
-      47,   105,    -1,     1,   104,    70,   110,     5,     6,     7,
-       8,     9,    10,    11,    12,    13,    -1,    -1,    -1,    -1,
-      18,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      -1,    -1,    30,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
-      38,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    47,
-       5,     6,     7,     8,     9,    10,    11,    12,    13,    -1,
-      -1,    -1,    17,    18,    19,    20,    21,    22,    23,    24,
-      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
-      35,    36,    37,    38,    39,    40,    41,    -1,    -1,    44,
-      -1,    -1,    -1,    48,    49
+      34,     3,     3,     0,    42,    52,    50,    51,    46,    32,
+      33,     3,     4,    14,    15,    16,     0,     1,    42,    77,
+      52,     5,     6,     7,     8,     9,    10,    11,    12,    13,
+      53,    75,     3,    56,    18,     4,    59,    60,    96,    44,
+      45,     4,    79,    80,    46,    46,    30,    81,    43,    83,
+      84,    52,    52,    52,    38,    43,    43,    42,    52,     3,
+      51,    95,    44,    47,    48,    44,     4,   101,    42,     2,
+      48,    -1,   106,    71,     1,   105,    -1,   111,     5,     6,
+       7,     8,     9,    10,    11,    12,    13,    -1,    -1,    -1,
+      -1,    18,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    -1,    -1,    30,    -1,    -1,    -1,    -1,    -1,    -1,
+      -1,    38,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
+      47,     5,     6,     7,     8,     9,    10,    11,    12,    13,
+      -1,    -1,    -1,    17,    18,    19,    20,    21,    22,    23,
+      24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
+      34,    35,    36,    37,    38,    39,    40,    41,    -1,    -1,
+      44,    -1,    -1,    -1,    48,    49,    50
 };
 
 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
    symbol of state STATE-NUM.  */
 static const yytype_uint8 yystos[] =
 {
-       0,    53,    54,     0,     5,     6,     7,     8,     9,    10,
+       0,    54,    55,     0,     5,     6,     7,     8,     9,    10,
       11,    12,    13,    17,    18,    19,    20,    21,    22,    23,
       24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
       34,    35,    36,    37,    38,    39,    40,    41,    44,    48,
-      49,    55,    56,    57,    60,    61,    59,    58,    42,    51,
-      51,     3,    74,     4,     4,    43,    51,    51,    43,    43,
-      51,    74,    74,     3,    46,    72,    73,     1,    47,    56,
-      66,    67,    68,    42,    62,    42,    46,    64,    65,    65,
-      63,    72,    63,    63,    74,    74,    74,    74,    44,    69,
-      44,    48,    67,    75,    63,     4,    73,    64,    72,    70,
-      71,    50,    73,    44,    45,    14,    15,    16,    51,    72,
-      71,    72,     4,    42
+      49,    50,    56,    57,    58,    61,    62,    60,    59,    42,
+      52,    52,     3,    75,     4,     4,    43,    52,    52,    43,
+      43,    52,    75,    75,     3,    46,    73,    74,     1,    47,
+      57,    67,    68,    69,    42,    63,    42,    46,    65,    66,
+      66,    64,    73,    64,    64,    75,    75,    75,    75,    44,
+      70,    44,    48,    68,    76,    64,     4,    74,    65,    73,
+      71,    72,    51,    74,    44,    45,    14,    15,    16,    52,
+      73,    72,    73,     4,    42
 };
 
 #define yyerrok                (yyerrstatus = 0)
@@ -975,64 +984,69 @@ yy_symbol_value_print (yyoutput, yytype,
   switch (yytype)
     {
       case 3: /* "\"string\"" */
-#line 175 "../../src/parse-gram.y"
+#line 177 "parse-gram.y"
        { fprintf (stderr, "\"%s\"", (yyvaluep->chars)); };
-#line 981 "../../src/parse-gram.c"
+#line 990 "parse-gram.c"
        break;
       case 4: /* "\"integer\"" */
-#line 184 "../../src/parse-gram.y"
+#line 186 "parse-gram.y"
        { fprintf (stderr, "%d", (yyvaluep->integer)); };
-#line 986 "../../src/parse-gram.c"
+#line 995 "parse-gram.c"
        break;
       case 10: /* "\"%union {...}\"" */
-#line 177 "../../src/parse-gram.y"
+#line 179 "parse-gram.y"
        { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); };
-#line 991 "../../src/parse-gram.c"
+#line 1000 "parse-gram.c"
        break;
       case 42: /* "\"type\"" */
-#line 182 "../../src/parse-gram.y"
+#line 184 "parse-gram.y"
        { fprintf (stderr, "<%s>", (yyvaluep->uniqstr)); };
-#line 996 "../../src/parse-gram.c"
+#line 1005 "parse-gram.c"
        break;
       case 46: /* "\"identifier\"" */
-#line 186 "../../src/parse-gram.y"
+#line 188 "parse-gram.y"
        { fprintf (stderr, "%s", (yyvaluep->symbol)->tag); };
-#line 1001 "../../src/parse-gram.c"
+#line 1010 "parse-gram.c"
        break;
       case 47: /* "\"identifier:\"" */
-#line 188 "../../src/parse-gram.y"
+#line 190 "parse-gram.y"
        { fprintf (stderr, "%s:", (yyvaluep->symbol)->tag); };
-#line 1006 "../../src/parse-gram.c"
+#line 1015 "parse-gram.c"
        break;
       case 49: /* "\"%{...%}\"" */
-#line 177 "../../src/parse-gram.y"
+#line 179 "parse-gram.y"
+       { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); };
+#line 1020 "parse-gram.c"
+       break;
+      case 50: /* "\"%header{...%}\"" */
+#line 179 "parse-gram.y"
        { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); };
-#line 1011 "../../src/parse-gram.c"
+#line 1025 "parse-gram.c"
        break;
-      case 50: /* "\"epilogue\"" */
-#line 177 "../../src/parse-gram.y"
+      case 51: /* "\"epilogue\"" */
+#line 179 "parse-gram.y"
        { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); };
-#line 1016 "../../src/parse-gram.c"
+#line 1030 "parse-gram.c"
        break;
-      case 51: /* "\"{...}\"" */
-#line 177 "../../src/parse-gram.y"
+      case 52: /* "\"{...}\"" */
+#line 179 "parse-gram.y"
        { fprintf (stderr, "{\n%s\n}", (yyvaluep->chars)); };
-#line 1021 "../../src/parse-gram.c"
+#line 1035 "parse-gram.c"
        break;
-      case 72: /* "symbol" */
-#line 186 "../../src/parse-gram.y"
+      case 73: /* "symbol" */
+#line 188 "parse-gram.y"
        { fprintf (stderr, "%s", (yyvaluep->symbol)->tag); };
-#line 1026 "../../src/parse-gram.c"
+#line 1040 "parse-gram.c"
        break;
-      case 73: /* "string_as_id" */
-#line 186 "../../src/parse-gram.y"
+      case 74: /* "string_as_id" */
+#line 188 "parse-gram.y"
        { fprintf (stderr, "%s", (yyvaluep->symbol)->tag); };
-#line 1031 "../../src/parse-gram.c"
+#line 1045 "parse-gram.c"
        break;
-      case 74: /* "string_content" */
-#line 175 "../../src/parse-gram.y"
+      case 75: /* "string_content" */
+#line 177 "parse-gram.y"
        { fprintf (stderr, "\"%s\"", (yyvaluep->chars)); };
-#line 1036 "../../src/parse-gram.c"
+#line 1050 "parse-gram.c"
        break;
       default:
        break;
@@ -1542,15 +1556,15 @@ YYLTYPE yylloc;
 
 
   /* User initialization code.  */
-#line 86 "../../src/parse-gram.y"
+#line 87 "parse-gram.y"
 {
   /* Bison's grammar can initial empty locations, hence a default
      location is needed. */
   boundary_set (&yylloc.start, current_file, 1, 0);
   boundary_set (&yylloc.end, current_file, 1, 0);
 }
-/* Line 1078 of yacc.c.  */
-#line 1554 "../../src/parse-gram.c"
+/* Line 1083 of yacc.c.  */
+#line 1568 "parse-gram.c"
   yylsp[0] = yylloc;
   goto yysetstate;
 
@@ -1735,146 +1749,190 @@ yyreduce:
   switch (yyn)
     {
         case 6:
-#line 209 "../../src/parse-gram.y"
-    { prologue_augment (translate_code ((yyvsp[(1) - (1)].chars), (yylsp[(1) - 
(1)])),
-                                                      (yylsp[(1) - (1)])); }
+#line 212 "parse-gram.y"
+    {
+      switch (header_position)
+       {
+         case DURING_HEADER:
+           header_position = AFTER_HEADER;
+           break;
+          default:
+            break;
+       }
+      prologue_augment (translate_code ((yyvsp[(1) - (1)].chars), (yylsp[(1) - 
(1)])), (yylsp[(1) - (1)]), false);
+  
+    }
     break;
 
   case 7:
-#line 211 "../../src/parse-gram.y"
-    { debug_flag = true; }
+#line 225 "parse-gram.y"
+    {
+      switch (header_position)
+       {
+         case BEFORE_HEADER:
+           header_position = DURING_HEADER;
+           break;
+         case AFTER_HEADER:
+           complain_at ((yylsp[(1) - (1)]), _("a `%%{...%%}' appears between 
here and the"
+                              " previous `%%union {...}' or `%%header{...%%}'"
+                              " declaration"));
+           break;
+          default:
+            break;
+       }
+      prologue_augment (translate_code ((yyvsp[(1) - (1)].chars), (yylsp[(1) - 
(1)])), (yylsp[(1) - (1)]), true);
+    }
     break;
 
   case 8:
-#line 213 "../../src/parse-gram.y"
+#line 241 "parse-gram.y"
+    { debug_flag = true; }
+    break;
+
+  case 9:
+#line 243 "parse-gram.y"
     {
       static char one[] = "1";
       muscle_insert ((yyvsp[(2) - (2)].chars), one);
     }
     break;
 
-  case 9:
-#line 217 "../../src/parse-gram.y"
+  case 10:
+#line 247 "parse-gram.y"
     { muscle_insert ((yyvsp[(2) - (3)].chars), (yyvsp[(3) - (3)].chars)); }
     break;
 
-  case 10:
-#line 218 "../../src/parse-gram.y"
+  case 11:
+#line 248 "parse-gram.y"
     { defines_flag = true; }
     break;
 
-  case 11:
-#line 219 "../../src/parse-gram.y"
+  case 12:
+#line 249 "parse-gram.y"
     { error_verbose = true; }
     break;
 
-  case 12:
-#line 220 "../../src/parse-gram.y"
+  case 13:
+#line 250 "parse-gram.y"
     { expected_sr_conflicts = (yyvsp[(2) - (2)].integer); }
     break;
 
-  case 13:
-#line 221 "../../src/parse-gram.y"
+  case 14:
+#line 251 "parse-gram.y"
     { expected_rr_conflicts = (yyvsp[(2) - (2)].integer); }
     break;
 
-  case 14:
-#line 222 "../../src/parse-gram.y"
+  case 15:
+#line 252 "parse-gram.y"
     { spec_file_prefix = (yyvsp[(3) - (3)].chars); }
     break;
 
-  case 15:
-#line 224 "../../src/parse-gram.y"
+  case 16:
+#line 254 "parse-gram.y"
     {
       nondeterministic_parser = true;
       glr_parser = true;
     }
     break;
 
-  case 16:
-#line 229 "../../src/parse-gram.y"
+  case 17:
+#line 259 "parse-gram.y"
     {
       muscle_code_grow ("initial_action", translate_symbol_action ((yyvsp[(2) 
- (2)].chars), (yylsp[(2) - (2)])), (yylsp[(2) - (2)]));
     }
     break;
 
-  case 17:
-#line 232 "../../src/parse-gram.y"
+  case 18:
+#line 262 "parse-gram.y"
     { add_param ("lex_param", (yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)])); }
     break;
 
-  case 18:
-#line 233 "../../src/parse-gram.y"
+  case 19:
+#line 263 "parse-gram.y"
     { locations_flag = true; }
     break;
 
-  case 19:
-#line 234 "../../src/parse-gram.y"
+  case 20:
+#line 264 "parse-gram.y"
     { spec_name_prefix = (yyvsp[(3) - (3)].chars); }
     break;
 
-  case 20:
-#line 235 "../../src/parse-gram.y"
+  case 21:
+#line 265 "parse-gram.y"
     { no_lines_flag = true; }
     break;
 
-  case 21:
-#line 236 "../../src/parse-gram.y"
+  case 22:
+#line 266 "parse-gram.y"
     { nondeterministic_parser = true; }
     break;
 
-  case 22:
-#line 237 "../../src/parse-gram.y"
+  case 23:
+#line 267 "parse-gram.y"
     { spec_outfile = (yyvsp[(3) - (3)].chars); }
     break;
 
-  case 23:
-#line 238 "../../src/parse-gram.y"
+  case 24:
+#line 268 "parse-gram.y"
     { add_param ("parse_param", (yyvsp[(2) - (2)].chars), (yylsp[(2) - (2)])); 
}
     break;
 
-  case 24:
-#line 239 "../../src/parse-gram.y"
+  case 25:
+#line 269 "parse-gram.y"
     { pure_parser = true; }
     break;
 
-  case 25:
-#line 240 "../../src/parse-gram.y"
+  case 26:
+#line 270 "parse-gram.y"
     { version_check (&(yylsp[(2) - (2)]), (yyvsp[(2) - (2)].chars)); }
     break;
 
-  case 26:
-#line 241 "../../src/parse-gram.y"
+  case 27:
+#line 271 "parse-gram.y"
     { skeleton = (yyvsp[(2) - (2)].chars); }
     break;
 
-  case 27:
-#line 242 "../../src/parse-gram.y"
+  case 28:
+#line 272 "parse-gram.y"
     { token_table_flag = true; }
     break;
 
-  case 28:
-#line 243 "../../src/parse-gram.y"
+  case 29:
+#line 273 "parse-gram.y"
     { report_flag = report_states; }
     break;
 
-  case 29:
-#line 244 "../../src/parse-gram.y"
+  case 30:
+#line 274 "parse-gram.y"
     { yacc_flag = true; }
     break;
 
-  case 33:
-#line 252 "../../src/parse-gram.y"
+  case 34:
+#line 282 "parse-gram.y"
     {
       grammar_start_symbol_set ((yyvsp[(2) - (2)].symbol), (yylsp[(2) - (2)]));
     }
     break;
 
-  case 34:
-#line 256 "../../src/parse-gram.y"
+  case 35:
+#line 286 "parse-gram.y"
     {
       char const *body = (yyvsp[(1) - (1)].chars);
 
+      switch (header_position)
+       {
+         case BEFORE_HEADER:
+           header_position = DURING_HEADER;
+           break;
+         case AFTER_HEADER:
+           complain_at ((yylsp[(1) - (1)]), _("a `%%{...%%}' appears between 
here and the"
+                              " previous `%%union {...}' or `%%header{...%%}'"
+                              " declaration"));
+           break;
+          default:
+            break;
+       }
+
       if (typed)
        {
          /* Concatenate the union bodies, turning the first one's
@@ -1889,8 +1947,8 @@ yyreduce:
     }
     break;
 
-  case 35:
-#line 272 "../../src/parse-gram.y"
+  case 36:
+#line 316 "parse-gram.y"
     {
       symbol_list *list;
       const char *action = translate_symbol_action ((yyvsp[(2) - (3)].chars), 
(yylsp[(2) - (3)]));
@@ -1900,8 +1958,8 @@ yyreduce:
     }
     break;
 
-  case 36:
-#line 280 "../../src/parse-gram.y"
+  case 37:
+#line 324 "parse-gram.y"
     {
       symbol_list *list;
       const char *action = translate_symbol_action ((yyvsp[(2) - (3)].chars), 
(yylsp[(2) - (3)]));
@@ -1911,48 +1969,48 @@ yyreduce:
     }
     break;
 
-  case 37:
-#line 288 "../../src/parse-gram.y"
+  case 38:
+#line 332 "parse-gram.y"
     {
       default_prec = true;
     }
     break;
 
-  case 38:
-#line 292 "../../src/parse-gram.y"
+  case 39:
+#line 336 "parse-gram.y"
     {
       default_prec = false;
     }
     break;
 
-  case 39:
-#line 298 "../../src/parse-gram.y"
+  case 40:
+#line 342 "parse-gram.y"
     { current_class = nterm_sym; }
     break;
 
-  case 40:
-#line 299 "../../src/parse-gram.y"
+  case 41:
+#line 343 "parse-gram.y"
     {
       current_class = unknown_sym;
       current_type = NULL;
     }
     break;
 
-  case 41:
-#line 303 "../../src/parse-gram.y"
+  case 42:
+#line 347 "parse-gram.y"
     { current_class = token_sym; }
     break;
 
-  case 42:
-#line 304 "../../src/parse-gram.y"
+  case 43:
+#line 348 "parse-gram.y"
     {
       current_class = unknown_sym;
       current_type = NULL;
     }
     break;
 
-  case 43:
-#line 309 "../../src/parse-gram.y"
+  case 44:
+#line 353 "parse-gram.y"
     {
       symbol_list *list;
       for (list = (yyvsp[(3) - (3)].list); list; list = list->next)
@@ -1961,8 +2019,8 @@ yyreduce:
     }
     break;
 
-  case 44:
-#line 319 "../../src/parse-gram.y"
+  case 45:
+#line 363 "parse-gram.y"
     {
       symbol_list *list;
       ++current_prec;
@@ -1976,58 +2034,58 @@ yyreduce:
     }
     break;
 
-  case 45:
-#line 333 "../../src/parse-gram.y"
+  case 46:
+#line 377 "parse-gram.y"
     { (yyval.assoc) = left_assoc; }
     break;
 
-  case 46:
-#line 334 "../../src/parse-gram.y"
+  case 47:
+#line 378 "parse-gram.y"
     { (yyval.assoc) = right_assoc; }
     break;
 
-  case 47:
-#line 335 "../../src/parse-gram.y"
+  case 48:
+#line 379 "parse-gram.y"
     { (yyval.assoc) = non_assoc; }
     break;
 
-  case 48:
-#line 339 "../../src/parse-gram.y"
+  case 49:
+#line 383 "parse-gram.y"
     { current_type = NULL; }
     break;
 
-  case 49:
-#line 340 "../../src/parse-gram.y"
+  case 50:
+#line 384 "parse-gram.y"
     { current_type = (yyvsp[(1) - (1)].uniqstr); }
     break;
 
-  case 50:
-#line 345 "../../src/parse-gram.y"
+  case 51:
+#line 389 "parse-gram.y"
     { (yyval.list) = symbol_list_new ((yyvsp[(1) - (1)].symbol), (yylsp[(1) - 
(1)])); }
     break;
 
-  case 51:
-#line 346 "../../src/parse-gram.y"
+  case 52:
+#line 390 "parse-gram.y"
     { (yyval.list) = symbol_list_prepend ((yyvsp[(1) - (2)].list), (yyvsp[(2) 
- (2)].symbol), (yylsp[(2) - (2)])); }
     break;
 
-  case 52:
-#line 352 "../../src/parse-gram.y"
+  case 53:
+#line 396 "parse-gram.y"
     {
        current_type = (yyvsp[(1) - (1)].uniqstr);
      }
     break;
 
-  case 53:
-#line 356 "../../src/parse-gram.y"
+  case 54:
+#line 400 "parse-gram.y"
     {
        symbol_class_set ((yyvsp[(1) - (1)].symbol), current_class, (yylsp[(1) 
- (1)]), true);
        symbol_type_set ((yyvsp[(1) - (1)].symbol), current_type, (yylsp[(1) - 
(1)]));
      }
     break;
 
-  case 54:
-#line 361 "../../src/parse-gram.y"
+  case 55:
+#line 405 "parse-gram.y"
     {
       symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - 
(2)]), true);
       symbol_type_set ((yyvsp[(1) - (2)].symbol), current_type, (yylsp[(1) - 
(2)]));
@@ -2035,8 +2093,8 @@ yyreduce:
     }
     break;
 
-  case 55:
-#line 367 "../../src/parse-gram.y"
+  case 56:
+#line 411 "parse-gram.y"
     {
       symbol_class_set ((yyvsp[(1) - (2)].symbol), current_class, (yylsp[(1) - 
(2)]), true);
       symbol_type_set ((yyvsp[(1) - (2)].symbol), current_type, (yylsp[(1) - 
(2)]));
@@ -2044,8 +2102,8 @@ yyreduce:
     }
     break;
 
-  case 56:
-#line 373 "../../src/parse-gram.y"
+  case 57:
+#line 417 "parse-gram.y"
     {
       symbol_class_set ((yyvsp[(1) - (3)].symbol), current_class, (yylsp[(1) - 
(3)]), true);
       symbol_type_set ((yyvsp[(1) - (3)].symbol), current_type, (yylsp[(1) - 
(3)]));
@@ -2054,84 +2112,84 @@ yyreduce:
     }
     break;
 
-  case 63:
-#line 403 "../../src/parse-gram.y"
+  case 64:
+#line 447 "parse-gram.y"
     {
       yyerrok;
     }
     break;
 
-  case 64:
-#line 409 "../../src/parse-gram.y"
+  case 65:
+#line 453 "parse-gram.y"
     { current_lhs = (yyvsp[(1) - (1)].symbol); current_lhs_location = 
(yylsp[(1) - (1)]); }
     break;
 
-  case 66:
-#line 413 "../../src/parse-gram.y"
+  case 67:
+#line 457 "parse-gram.y"
     { grammar_current_rule_end ((yylsp[(1) - (1)])); }
     break;
 
-  case 67:
-#line 414 "../../src/parse-gram.y"
+  case 68:
+#line 458 "parse-gram.y"
     { grammar_current_rule_end ((yylsp[(3) - (3)])); }
     break;
 
-  case 69:
-#line 420 "../../src/parse-gram.y"
+  case 70:
+#line 464 "parse-gram.y"
     { grammar_current_rule_begin (current_lhs, current_lhs_location); }
     break;
 
-  case 70:
-#line 422 "../../src/parse-gram.y"
+  case 71:
+#line 466 "parse-gram.y"
     { grammar_current_rule_symbol_append ((yyvsp[(2) - (2)].symbol), 
(yylsp[(2) - (2)])); }
     break;
 
-  case 71:
-#line 424 "../../src/parse-gram.y"
+  case 72:
+#line 468 "parse-gram.y"
     { grammar_current_rule_action_append (gram_last_string,
                                          gram_last_braced_code_loc); }
     break;
 
-  case 72:
-#line 427 "../../src/parse-gram.y"
+  case 73:
+#line 471 "parse-gram.y"
     { grammar_current_rule_prec_set ((yyvsp[(3) - (3)].symbol), (yylsp[(3) - 
(3)])); }
     break;
 
-  case 73:
-#line 429 "../../src/parse-gram.y"
+  case 74:
+#line 473 "parse-gram.y"
     { grammar_current_rule_dprec_set ((yyvsp[(3) - (3)].integer), (yylsp[(3) - 
(3)])); }
     break;
 
-  case 74:
-#line 431 "../../src/parse-gram.y"
+  case 75:
+#line 475 "parse-gram.y"
     { grammar_current_rule_merge_set ((yyvsp[(3) - (3)].uniqstr), (yylsp[(3) - 
(3)])); }
     break;
 
-  case 75:
-#line 435 "../../src/parse-gram.y"
+  case 76:
+#line 479 "parse-gram.y"
     { (yyval.symbol) = (yyvsp[(1) - (1)].symbol); }
     break;
 
-  case 76:
-#line 436 "../../src/parse-gram.y"
+  case 77:
+#line 480 "parse-gram.y"
     { (yyval.symbol) = (yyvsp[(1) - (1)].symbol); }
     break;
 
-  case 77:
-#line 442 "../../src/parse-gram.y"
+  case 78:
+#line 486 "parse-gram.y"
     {
       (yyval.symbol) = symbol_get (quotearg_style (c_quoting_style, (yyvsp[(1) 
- (1)].chars)), (yylsp[(1) - (1)]));
       symbol_class_set ((yyval.symbol), token_sym, (yylsp[(1) - (1)]), false);
     }
     break;
 
-  case 78:
-#line 451 "../../src/parse-gram.y"
+  case 79:
+#line 495 "parse-gram.y"
     { (yyval.chars) = (yyvsp[(1) - (1)].chars); }
     break;
 
-  case 80:
-#line 458 "../../src/parse-gram.y"
+  case 81:
+#line 502 "parse-gram.y"
     {
       muscle_code_grow ("epilogue", translate_code ((yyvsp[(2) - (2)].chars), 
(yylsp[(2) - (2)])), (yylsp[(2) - (2)]));
       gram_scanner_last_string_free ();
@@ -2139,8 +2197,8 @@ yyreduce:
     break;
 
 
-/* Line 1267 of yacc.c.  */
-#line 2144 "../../src/parse-gram.c"
+/* Line 1272 of yacc.c.  */
+#line 2202 "parse-gram.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -2360,7 +2418,7 @@ yyreturn:
 }
 
 
-#line 464 "../../src/parse-gram.y"
+#line 508 "parse-gram.y"
 
 
 
Index: src/parse-gram.h
===================================================================
RCS file: /sources/bison/bison/src/parse-gram.h,v
retrieving revision 1.96
diff -p -u -r1.96 parse-gram.h
--- src/parse-gram.h    6 Jun 2006 16:40:06 -0000       1.96
+++ src/parse-gram.h    14 Jun 2006 23:45:04 -0000
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.1b.  */
+/* A Bison parser, made by GNU Bison 2.3+.  */
 
 /* Skeleton interface for Bison's Yacc-like parsers in C
 
@@ -33,6 +33,9 @@
    This special exception was added by the Free Software Foundation in
    version 2.2 of Bison.  */
 
+/* Copy the first part of user header declarations.  */
+
+
 /* Tokens.  */
 #ifndef YYTOKENTYPE
 # define YYTOKENTYPE
@@ -87,8 +90,9 @@
      ID_COLON = 302,
      PERCENT_PERCENT = 303,
      PROLOGUE = 304,
-     EPILOGUE = 305,
-     BRACED_CODE = 306
+     HEADER_PROLOGUE = 305,
+     EPILOGUE = 306,
+     BRACED_CODE = 307
    };
 #endif
 /* Tokens.  */
@@ -140,15 +144,16 @@
 #define ID_COLON 302
 #define PERCENT_PERCENT 303
 #define PROLOGUE 304
-#define EPILOGUE 305
-#define BRACED_CODE 306
+#define HEADER_PROLOGUE 305
+#define EPILOGUE 306
+#define BRACED_CODE 307
 
 
 
 
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 typedef union YYSTYPE
-#line 95 "../../src/parse-gram.y"
+#line 96 "parse-gram.y"
 {
   symbol *symbol;
   symbol_list *list;
@@ -157,8 +162,8 @@ typedef union YYSTYPE
   assoc assoc;
   uniqstr uniqstr;
 }
-/* Line 1529 of yacc.c.  */
-#line 162 "../../src/parse-gram.h"
+/* Line 1541 of yacc.c.  */
+#line 167 "parse-gram.h"
        YYSTYPE;
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
 # define YYSTYPE_IS_DECLARED 1
@@ -181,3 +186,7 @@ typedef struct YYLTYPE
 #endif
 
 
+
+
+/* Copy the second part of user header declarations.  */
+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]