Link to home
Start Free TrialLog in
Avatar of boycy
boycyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Including files from Yacc/Bison definitions header (x.tab.h)

I'm generating a scanner-parser pair with Flex and Bison (similar to Lex and Yacc respectively). My YYSTYPE is a union which, as one of its members, has a struct*.
Bison generates its definitions file 'x.tab.h' containing all of the token definitions, etc. but I have the problem that when I include it from my Flex scanner (x.l) and try to compile the resulting file, the struct* is an undefined type. Is there a way I can get Bison to a #include into the header file it generates?
I can work around this problem by including the file in x.l *before* I include x.tab.h, but I would consider that a bad practice - the header file should be complete on its own.

Anybody know of how to do this?
--Rob
Avatar of Member_3480671
Member_3480671

You could move the struct definition to the header file, where type definitions belong. You can now first include the header, and then the other file. This should work.

Stuart
Avatar of boycy

ASKER

The struct definition is in a header file already, I need to include that in x.tab.h which is generated by Bison, so I need to know how to insert extra code into that.
before generating x.tab.h put the following in Bison file

%{
#include "header.h"
}%


Thanxs,
Joju.
Avatar of boycy

ASKER

Joju, that will put 'include "header.h" into x.tab.c, not x.tab.h which is what I need.
hope you are using [-d] --defines option with bison for generating .h file
Avatar of boycy

ASKER

Yes. Ok let me restate the question as everyone seems to be getting confused.
Bison is generating the header file x.tab.h there's no problem there.
I want to tell bison to insert some extra code into the header file. There is no problem getting it inserted into x.tab.c, but that isn't what I want.
Does anybody know how to tell Bison to insert a given line of code into the header, if it's possible?
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boycy

ASKER

Thank you Kent - that was the conclusion I had come to. The definitions file I thought was part of the bison-flex link, and was there to export Bison's token definitions for Flex to use?

--Rob