[Top][All Lists]

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

prologue alternatives (was: Re: [GNU Bison 2.3] testsuite: 103 104 faile

From: Joel E. Denny
Subject: prologue alternatives (was: Re: [GNU Bison 2.3] testsuite: 103 104 failed)
Date: Mon, 11 Sep 2006 19:28:14 -0400 (EDT)

On Mon, 11 Sep 2006, Paul Eggert wrote:

> This before-header and after-header business is wayyyy too
> complicated!  Someone really ought to fix the underlying problem

If only we knew what the underlying problem were...

> since
> I hardly even understand the current rules myself, and I don't expect
> users to understand it.  (Sheesh!  what a mess....)

My last proposal went something like this, but the thread died:

1. Remove the %*-header directives from Bison.

2. Keep the `%{...%}' behavior the same throughout all skeletons and in 
yacc mode.  Discourage its usage, and encourage the usage of the following 
more flexible and more explicit alternatives.

3. Add `%semantic-type-code {...}' to contain code that's required by the 
semantic type.  For example, the user might do:

  %semantic-type-code { #include "type1.h" }
  %union { type1 field1; }
  %destructor { type1_destroy ($$); } <type1>

  %semantic-type-code { #include "type2.h" }
  %union { type2 field2; }
  %destructor { type2_destroy ($$); } <type2>

4. Deprecate `#define YYSTYPE'.  If the user needs a semantic type other 
than a union (or just needs to define the union in an include file), the 
user would do something like this:

  %semantic-type-code { #include "my_stype.h" }
  %semantic-type { my_stype * }

That is, the `%semantic-type {...}' would tell Bison what the semantic 
type is.  The `%semantic-type-code {...}' would, as in #3, define code 
needed by the semantic type.

5. Add %location-type-code and %location-type as well.

6. Add `%header {...}' and `%code {...}' to place other arbitrary code in 
the header file and code file, respectively.  This code can depend on the 
Bison-generated types.

7. In most cases, the above is all the user needs to know.  The 
implementation should be straight-forward.  The layout of the code file 

  enum yytokentype
  %location-type-code blocks
  YYLTYPE definition
  %semantic-type-code blocks
  YYSTYPE definition
  %header blocks
  %code blocks

where everything between the lines is the header file.  If the user 
declares `%semantic-type { my_stype * }', Bison generates the YYSTYPE 
definition as something like `typedef my_stype *YYSTYPE;'.  Otherwise, it 
generates the union or the default int.

Any better?


reply via email to

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