help-bison
[Top][All Lists]
Advanced

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

Re: sharing grammar rules across grammars?


From: Frank Heckenbach
Subject: Re: sharing grammar rules across grammars?
Date: Thu, 19 Feb 2004 22:16:03 +0100
User-agent: semail 20030730

Jeremy Elson wrote:

> I have two languages that have several features in common.  Is there
> an easy way to share rules across grammars?  (Both grammars use the
> same lexer; the token values are the same.)
> 
> Right now, I'm just doing cut-and-paste of the rules, which of course
> is not a very good solution.  Is there a way to do an "#include" from
> within the rules section of a bison input, so that I can put the
> common rules into a separate file that is included by both .y files?

If there's no other way, you could preprocess your sources before
passing them to bison. Depending on your circumstances, a simple
`cat' may do, or a general preprocessor such as m4, or something
else (e.g., the GNU awk documentation contains an example for an
include processor; look for `igawk', though it does more than needed
here).

> By the way, I'm also using the evil cut-and-paste method to make sure
> that both of my grammars have the same "%token" declarations, in the
> same order, so that both grammars use the same token values and
> therefore can share a lexer.  Is there a better way to keep the token
> values in sync across grammars?  In reading the past year of mailing
> list archives, I've seen similar questions, but never a definitive
> answer.

Same answer as above.

(In previous discussions AFAIR there was only a way to make sure
that tokens are identical when synced manually.)

Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)




reply via email to

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