boycy
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
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
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.
%{
#include "header.h"
}%
Thanxs,
Joju.
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
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
--Rob
Stuart