| Author |
Problem using Bison & g++
|
|
| Shahbaz 2004-11-22, 8:57 pm |
| I'm having a problem compiling my parser's C code generated by Bison.
The problem occurs when I use g++ but not when I use gcc. Whats
really odd is that I have other parsers that I compile with g++ and
they work fine. I cant seem to figure out what causes this
compilation error.
>bison -v -d parser.y
>flex tkn.lex
>g++ -c -o lex.o lex.yy.c
>g++ -c -o parser.tab.o parser.tab.c
/usr/share/bison/bison.simple: In function 'int yyparse()':
/usr/share/bison/bison.simple:573: 'yylex' undeclared(first use this
function)
/usr/share/bison/bison.simple:573: (Each undeclared identifier is
reported only once for each function it appears in.)
make: *** [parser.tab.o] Error 1
Again, this only occurs when I use g++ and not gcc. Has anyone
encountered this problem with Bison/g++ before? Thanks in advance
your help.
| |
| Pascal Bourguignon 2004-11-23, 3:57 am |
| bshahbaz@gmail.com (Shahbaz) writes:
> I'm having a problem compiling my parser's C code generated by Bison.
> The problem occurs when I use g++ but not when I use gcc. Whats
> really odd is that I have other parsers that I compile with g++ and
> they work fine. I cant seem to figure out what causes this
> compilation error.
>
> /usr/share/bison/bison.simple: In function 'int yyparse()':
> /usr/share/bison/bison.simple:573: 'yylex' undeclared(first use this
> function)
> /usr/share/bison/bison.simple:573: (Each undeclared identifier is
> reported only once for each function it appears in.)
> make: *** [parser.tab.o] Error 1
>
> Again, this only occurs when I use g++ and not gcc. Has anyone
> encountered this problem with Bison/g++ before? Thanks in advance
> your help.
Perhaps you miss some: extern "C"{ ... }. It could be inserted
automatically if you used the right options to flex and bison:
man flex | grep C++
man bison | grep C++
--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot; don't bother saving your artefacts.
| |
|
| Hi,
you have to declare yylex to keep g++ happy.
int yylex();
Johan
"Shahbaz" <bshahbaz@gmail.com> schreef in bericht
news:d4529c6e.0411221622.23f806ef@posting.google.com...
> I'm having a problem compiling my parser's C code generated by Bison.
> The problem occurs when I use g++ but not when I use gcc. Whats
> really odd is that I have other parsers that I compile with g++ and
> they work fine. I cant seem to figure out what causes this
> compilation error.
>
> /usr/share/bison/bison.simple: In function 'int yyparse()':
> /usr/share/bison/bison.simple:573: 'yylex' undeclared(first use this
> function)
> /usr/share/bison/bison.simple:573: (Each undeclared identifier is
> reported only once for each function it appears in.)
> make: *** [parser.tab.o] Error 1
>
> Again, this only occurs when I use g++ and not gcc. Has anyone
> encountered this problem with Bison/g++ before? Thanks in advance
> your help.
| |
| Shahbaz 2004-11-30, 4:02 pm |
| Thanks Johan,
That seemed to fix the problem. I thought I had tried that but I
guess in my many attempts to remedy the problem I had overlooked it.
For a temporary fix I included the following:
#ifdef __cplusplus
extern "C" { int yylex(void);
}
#endif
This only works if your lexer is going to use standard C types. In my
case I had my own ADTs i needed to use (as is typical when writing
compilers) and needed to get rid of the extern "C". Thanks again.
Bani
"Johan" <me@knoware.nl> wrote in message news:<10q6qcb1np4e63d@corp.supernews.com>...[color=darkred]
> Hi,
>
> you have to declare yylex to keep g++ happy.
>
> int yylex();
>
> Johan
>
> "Shahbaz" <bshahbaz@gmail.com> schreef in bericht
> news:d4529c6e.0411221622.23f806ef@posting.google.com...
|
|
|
|