FlexLexer error

C

chiqui.p

hi all,
I'm compiling a c++ program of mine and I have a problem with flex:
the error is the following

/usr/include/FlexLexer.h:130: error: expected unqualified-id before
numeric constant

I search but I only found that this error has been fixed in the newer
version of flex.
I have Flex 2.5.35, I'm compiling with gcc/g++ 4.1 (because I need to)
I'm using Ubuntu 8.10. bison 1:2.3 and bisonc++ 2.4.2-1.

I can't find a way to make it through.

does any of you have an idea?

the line in the file is
virtual int yywrap();

i can't understand whether the problem is in my code or somewhere
else.

thank you
cisco
 
V

Victor Bazarov

I'm compiling a c++ program of mine and I have a problem with flex:
the error is the following

/usr/include/FlexLexer.h:130: error: expected unqualified-id before
numeric constant

I search but I only found that this error has been fixed in the newer
version of flex.
I have Flex 2.5.35, I'm compiling with gcc/g++ 4.1 (because I need to)
I'm using Ubuntu 8.10. bison 1:2.3 and bisonc++ 2.4.2-1.

I can't find a way to make it through.

does any of you have an idea?

the line in the file is
virtual int yywrap();

i can't understand whether the problem is in my code or somewhere
else.

The code you posted does not contain any errors AFA C++ is concerned.
It doesn't have any numeric constant either. See FAQ 5.8.

V
 
D

DerTopper

hi all,
I'm compiling a c++ program of mine and I have a problem with flex:
the error is the following

/usr/include/FlexLexer.h:130: error: expected unqualified-id before
numeric constant

I search but I only found that this error has been fixed in the newer
version of flex.
I have Flex 2.5.35, I'm compiling with gcc/g++ 4.1 (because I need to)
I'm using Ubuntu 8.10. bison 1:2.3 and bisonc++ 2.4.2-1.

I can't find a way to make it through.

does any of you have an idea?

the line in the file is
virtual int yywrap();

i can't understand whether the problem is in my code or somewhere
else.

Are you sure that you really use Flex and not Flex++? A virtual method
would not make much sense if you actually used Flex. I use Flex 2.5.4,
and my FlexLexer.h doesn't even contain a definition of yywrap (it
only appears once inside a comment). As far as I remember, you have to
provide the function yywrap yourself, so it should actually appear in
your own code, not inside FlexLexer.h.

Regards,
Stuart
 
J

James Kanze

I'm compiling a c++ program of mine and I have a problem with flex:
the error is the following
/usr/include/FlexLexer.h:130: error: expected unqualified-id before
numeric constant
I search but I only found that this error has been fixed in the newer
version of flex.
I have Flex 2.5.35, I'm compiling with gcc/g++ 4.1 (because I need to)
I'm using Ubuntu 8.10. bison 1:2.3 and bisonc++ 2.4.2-1.
I can't find a way to make it through.
does any of you have an idea?
the line in the file is
virtual int yywrap();
i can't understand whether the problem is in my code or somewhere
else.

Flex doesn't really understand C++ very well, and the generated
code for any one version of flex tends to only work with one
particular version of C++---not necessarily the version used
with your compiler. I post-process the output (using sed) to
get it to compile, but it's a frustrating job at best, since the
post-processing depends on the version of flex you're using. If
I had it to do over, I'd just let flex generate C, and live with
it.
 
J

James Kanze

(e-mail address removed) schrieb:
Are you sure that you really use Flex and not Flex++? A
virtual method would not make much sense if you actually used
Flex. I use Flex 2.5.4, and my FlexLexer.h doesn't even
contain a definition of yywrap (it only appears once inside a
comment). As far as I remember, you have to provide the
function yywrap yourself, so it should actually appear in your
own code, not inside FlexLexer.h.

Flex will generate C++ if given the -+ option, or if you specify
"%option c++" in the source file. From the (latest)
documentation, however: "IMPORTANT: the present form of the
scanning class is experimental and may change considerably
between major releases." The code generator also seems to have
some problems tracking the evolutions in C++; some of the
versions I use still include <iostream.h>, for example, and I've
had a number of other problems getting the generated code to
compile with all my compilers. Generally, some creative use of
sed on the output solves the problem, but getting anything to
work with different versions of flex *and* different compilers
can be fairly tricky.
 
D

DerTopper

I'm compiling a c++ program of mine and I have a problem
with flex: the error is the following
/usr/include/FlexLexer.h:130: error: expected unqualified-id before
numeric constant [snip]
the line in the file is
   virtual int yywrap();
Are you sure that you really use Flex and not Flex++? A
virtual method would not make much sense if you actually used
Flex. I use Flex 2.5.4, and my FlexLexer.h doesn't even
contain a definition of yywrap (it only appears once inside a
comment). As far as I remember, you have to provide the
function yywrap yourself, so it should actually appear in your
own code, not inside FlexLexer.h.

Flex will generate C++ if given the -+ option,

Right. I checked my code and was mildly surprised that I used the -+
option myself. I'm having a memory like a sieve ...
or if you specify
"%option c++" in the source file.  From the (latest)
documentation, however: "IMPORTANT: the present form of the
scanning class is experimental and may change considerably
between major releases."  The code generator also seems to have
some problems tracking the evolutions in C++; some of the
versions I use still include <iostream.h>, for example,

but said:
and I've
had a number of other problems getting the generated code to
compile with all my compilers.  Generally, some creative use of
sed on the output solves the problem, but getting anything to
work with different versions of flex *and* different compilers
can be fairly tricky.

I updated my FlexLexer.h header, which is probably why I couldn't find
the definition of yywrap inside it anymore (see my previous posting).
Gosh, its like an expedition into the past (even though it was only
two or three years ago).

Anyway I still only provide a non-virtual function yywrap, and I
pretty much guess that I didn't tweak the FlexLexer.h header so far
that I changed a virtual yywrap method into a plain old function.
@cisco: Did removing the virtual keyword do any good?

Stuart
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top