Unix Programming - Problem using Bison & g++

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > November 2004 > Problem using Bison & g++





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Problem using Bison & g++
Shahbaz

2004-11-22, 5:51 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-22, 5:51 pm

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.
Johan

2004-11-23, 6:08 pm

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, 7:43 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>...[vbcol=seagreen]
> 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...
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com