[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2005-04-29
8
Medium Priority
?
638 Views
Last Modified: 2013-11-18
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
0
Comment
Question by:boycy
8 Comments
 
LVL 1

Expert Comment

by:stuartdehaan
ID: 13892951
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
0
 
LVL 6

Author Comment

by:boycy
ID: 13892994
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.
0
 
LVL 3

Expert Comment

by:joju
ID: 13893128
before generating x.tab.h put the following in Bison file

%{
#include "header.h"
}%


Thanxs,
Joju.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Author Comment

by:boycy
ID: 13894396
Joju, that will put 'include "header.h" into x.tab.c, not x.tab.h which is what I need.
0
 
LVL 3

Expert Comment

by:joju
ID: 13895158
hope you are using [-d] --defines option with bison for generating .h file
0
 
LVL 6

Author Comment

by:boycy
ID: 13895199
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?
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 450 total points
ID: 13946342

Bison doesn't provide that capability.  And when you stop and think about it, that makes a lot of sense.  The generated header file is the controls necessary to bulid the parser.

Put your definitions in a another header file.  Then use the standard Bison protocol to include your header file in the source.

%{
#include "MyHeader.h"
}%


Good Luck,
Kent
0
 
LVL 6

Author Comment

by:boycy
ID: 13946489
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question