bison-patches
[Top][All Lists]
Advanced

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

Re: prologue alternatives


From: Paul Eggert
Subject: Re: prologue alternatives
Date: Sat, 16 Sep 2006 13:32:53 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

"Joel E. Denny" <address@hidden> writes:

> That isn't equivalent yet because yours doesn't place those "header 
> definitions that depend on y.tab.h" in the Bison-generated code file.

It shouldn't be hard to come up with something that's equivalent,
without departing from the traditional "yacc -d" model.  Let me try to
derive it from my understanding of yacc -d.  It works by translating
this:

    %{ A %}
    %union { B }
    %{ C %}
    %%
    D
    %%
    E

to this:

    A
    [copy of y.tab.h]
    C
    [translation of grammar D into a parser]
    E

where y.tab.h is derived from all the input (including (D)) and
defines YYSTYPE and YYLTYPE if they're not defined already.

Given this model, users that don't know about %start-header can simply
prepend "#include <parser.h>" to (C), where parser.h looks like this:

      #include "y.tab.h"
      [other definitions]

Other source-code modules simply #include <parser.h>.

y.tab.h is idempotent; it doesn't hurt to include it if it (or a copy
of it) is already included, so other modules can simply include
parser.h.

This mechanism is fairly simple, and it doesn't require the
%start-header/%end-header business that I am having so much trouble
following.




reply via email to

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