Re: Including bison parser into C++

Tim Van Holder <>
21 Jun 2001 03:11:39 -0400

          From comp.compilers

Related articles
Including bison parser into C++ (2001-06-14)
Re: Including bison parser into C++ (jacob navia) (2001-06-21)
Re: Including bison parser into C++ (Tim Van Holder) (2001-06-21)
| List of all articles for this month |

From: Tim Van Holder <>
Newsgroups: comp.compilers
Date: 21 Jun 2001 03:11:39 -0400
Organization: Anubex N.V.
References: 01-06-038
Keywords: yacc, C++
Posted-Date: 21 Jun 2001 03:11:39 EDT

Joshua Earl Donahue wrote:
> What I am trying to do is include my bison parser into C++ I currently
> have the parser so that it will compile fine with the CC compiler and
> to include the parser into my program I just #include "". This
> works fine if I am just including it into an executable, i.e. the main
> program. but when I try to include it into a class that is included
> by the main program it says that all of the functions in are
> multiply defined. Any Ideas? Thanks

I'm surprised it's even working that well; the last time I tried
something similar, the C++ compiler choked on much of bison's output.

You're not #include'ing the .c file in more than one place, right?
Besides, #including the .c file will probably only work at the top
level (as it contains several #includes for standard headers, which
you don't want to appear withing a namespace/class/function), so
what's the gain of doing so (as opposed to simply linking in the
compiled source). Just compile, and link with the rest of
your program; include for token declarations and provide a
declaration like

    extern "C" int yyparse(void);

wherever you need to call the parser.

Using multiple parsers is trickier, but thanks to bison's renaming
should be easy enough, provided you don't need to use multiple
grammars with %union statements in a single source file (as bison does
NOT rename the YYSTYPE macro).

Hope this helps.

Tim Van Holder - Anubex N.V.

Post a followup to this message

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