Re: Using bison and C++ together --- compile with gcc or g++?? How??

pedwards@dmapub.dma.org (Phil Edwards)
28 Jan 2001 02:08:48 -0500

          From comp.compilers

Related articles
Using bison and C++ together --- compile with gcc or g++?? How?? tlofft@golden.net (Timothy Lofft) (2001-01-26)
Re: Using bison and C++ together --- compile with gcc or g++?? How?? pedwards@dmapub.dma.org (2001-01-28)
| List of all articles for this month |

From: pedwards@dmapub.dma.org (Phil Edwards)
Newsgroups: comp.compilers
Date: 28 Jan 2001 02:08:48 -0500
Organization: $home is where the core is
References: 01-01-149
Keywords: yacc, C++
Posted-Date: 28 Jan 2001 02:08:48 EST

Timothy Lofft <tlofft@golden.net> wrote:
> We are trying to compile a bison file with g++, but it gives all sorts
> of errors about implicit function declarations. We also want to be
> able to use our own C++ class inside bison to store various symbols.
> If we include the header for the class definition, it gets worse. I
> can eliminate some of the errors by adding "extern" declarations of
> the function headers in the *.y file but this seems to be a silly
> solution, as I'm creating declarations for such functions as free,
> malloc and strcat.... there must be a better way.


Just including the necessary system headers will take care of things
like malloc and strcat. (Although you oughta be using std::string
instead of strcat, but that's for a different newsgroup. :-)


Do make certain that you are doing all of these includes in the first
part of your input file, not down in the rules section.


The system headers should be written to Do The Right Thing in a C++
environment, like using 'extern "C"' and the like. If they aren't,
then you should report that as a bug to the vendor.




> Is there some standard way to use bison generated code with C++
> classes? Or do we need to create a C-interface to the C++ classes and
> compile the generate bison file using gcc?


I use C++ code inside yacc/bison rules with no problem. Just compile
the resulting code with a C++ compiler.


There are parser generators that will actually create C++ classes as
the parser, so that you call "MyParser.parse();" instead of
"yyparse();" but that's probably overkill for what you want. (Or
maybe it isn't.)


> I've done a fairly complete search of the Internet with seemingly no
> success but if anyone has any pointers, they too would be appreciated.


> [See the compilers archives for info on C++-ized versions of bison. -John]


Like the moderator says, if you've managed to miss the comp.compilers
archive, it couldn't have been a fairly complete search. :-)


Luck++;
Phil


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.