Help please
<[email protected]> Sun, 27 Jan 2008 22:13:39 +0100
| Newsgroups | gmane.comp.lex.flex.general |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============0076698132==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C86129.7C9326E9"
This is a multi-part message in MIME format.
------_=_NextPart_001_01C86129.7C9326E9
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
I'm a new Flex user.
I'm having the follow problem:
1. I've created one file Example.l:
%option c++
%option yylineno
%option noyywrap
%option caseless
delim [ \t\n]
ws {delim}+
letter [A-Za-z]
digit [0-9]
id {letter}({letter}|{digit})*
number {digit}+(\.{digit}+)?(E[+\-]?{digit}+)?
%%
int yylval;
{ws} {;}
if { return(IF);}
then { return(THEN);}
else { return(ELSE);}
{id} { return(ID);}
{number} { return(NUMBER);}
"<" { yylval =3D LT; return(RELOP);}
"<=3D" { yylval =3D LE; return(RELOP);}
"=3D" { yylval =3D EQ; return(RELOP);}
"<>" { yylval =3D NE; return(RELOP);}
">" { yylval =3D GT; return(RELOP);}
">=3D" {yylval =3D GE; return(RELOP);}
. {return(ERROR);}
%%
and i've run >Flex example.l
and it has returned the file lex.yy.cc.
2. Well, i've created also the main program in c++, let's call it =
main_prog.cpp:
#include <stdio.h>
#include <ctype.h>
enum {LT, LE, NE, GT, GE, EQ, IF, THEN, ELSE, ID, NUMBER, RELOP, ERROR};
#include <FlexLexer.h>
#include "lex.yy.cc"
int main(int argc, char *argv[])
{
int token;
FlexLexer* lexer =3D new yyFlexLexer();
while ((token=3Dlexer->yylex()) !=3D 0) {
switch (token) {
case RELOP: printf("%s","RELOP"); break;
case NUMBER: printf("%s","NUMBER"); break;
case ID: printf("%s","ID"); break;
case IF: printf("%s","IF"); break;
case THEN: printf("%s","THEN"); break;
case ELSE: printf("%s","ELSE");break;
case ERROR: printf("%s", "illegal character"); break;
default:
printf("%s","UNKNOWN");
break;
}
printf("%s\n", lexer->YYText());
}
return 0;
}
The problem becomes when I compile it using=20
g++ main_prog.cpp -o main_prog
,infact the system answer me with:
/usr/include/FlexLexer.h:113: error: redefinition of =91class =
yyFlexLexer=92
/usr/include/FlexLexer.h:113: error: previous definition of =91class =
yyFlexLexer=92
thank you for helping me,
Simone.
**********
Scopri la nuova Alice Mail!
1 GB di spazio con antivirus, antispam e fino a 2 GB di allegati.
Registrati GRATIS su =
http://registra.rossoalice.alice.it/registra/basic/entratabasic.do?entryP=
oint=3Dfooter
------_=_NextPart_001_01C86129.7C9326E9
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
6.5.7653.15">
<TITLE>Help please</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=3D2>Hi,<BR>
I'm a new Flex user.<BR>
I'm having the follow problem:<BR>
<BR>
1. I've created one file Example.l:<BR>
<BR>
%option c++<BR>
%option yylineno<BR>
%option noyywrap<BR>
%option caseless<BR>
<BR>
delim [ \t\n]<BR>
ws {delim}+<BR>
letter [A-Za-z]<BR>
digit [0-9]<BR>
id {letter}({letter}|{digit})*<BR>
number {digit}+(\.{digit}+)?(E[+\-]?{digit}+)?<BR>
<BR>
%%<BR>
int =
yylval;<BR>
{ws} {;}<BR>
if { =
return(IF);}<BR>
then { return(THEN);}<BR>
else { return(ELSE);}<BR>
{id} { return(ID);}<BR>
{number} { return(NUMBER);}<BR>
"<" { =
yylval =3D LT; return(RELOP);}<BR>
"<=3D" { yylval =
=3D LE; return(RELOP);}<BR>
"=3D" { yylval =
=3D EQ; return(RELOP);}<BR>
"<>" { yylval =
=3D NE; return(RELOP);}<BR>
">" { =
yylval =3D GT; return(RELOP);}<BR>
">=3D" {yylval =
=3D GE; return(RELOP);}<BR>
. =
{return(ERROR);}<BR>
%%<BR>
<BR>
<BR>
and i've run >Flex example.l<BR>
<BR>
and it has returned the file lex.yy.cc.<BR>
<BR>
2. Well, i've created also the main program in c++, let's call it =
main_prog.cpp:<BR>
<BR>
<BR>
<BR>
#include <stdio.h><BR>
#include <ctype.h><BR>
enum {LT, LE, NE, GT, GE, EQ, IF, THEN, ELSE, ID, NUMBER, RELOP, =
ERROR};<BR>
#include <FlexLexer.h><BR>
#include "lex.yy.cc"<BR>
<BR>
int main(int argc, char *argv[])<BR>
{<BR>
int token;<BR>
FlexLexer* lexer =3D new yyFlexLexer();<BR>
while ((token=3Dlexer->yylex()) !=3D 0) {<BR>
switch (token) {<BR>
case RELOP: =
printf("%s","RELOP"); break;<BR>
case NUMBER: =
printf("%s","NUMBER"); break;<BR>
case ID: =
printf("%s","ID"); break;<BR>
case IF: =
printf("%s","IF"); break;<BR>
case THEN: =
printf("%s","THEN"); break;<BR>
case ELSE: =
printf("%s","ELSE");break;<BR>
case ERROR: =
printf("%s", "illegal character"); break;<BR>
default:<BR>
&=
nbsp; =
printf("%s","UNKNOWN");<BR>
&=
nbsp; break;<BR>
}<BR>
printf("%s\n", =
lexer->YYText());<BR>
}<BR>
return 0;<BR>
}<BR>
<BR>
The problem becomes when I compile it using<BR>
<BR>
g++ main_prog.cpp -o =
main_prog<BR>
<BR>
,infact the system answer me with:<BR>
<BR>
/usr/include/FlexLexer.h:113: error: redefinition of ‘class =
yyFlexLexer’<BR>
/usr/include/FlexLexer.h:113: error: previous definition of ‘class =
yyFlexLexer’<BR>
<BR>
thank you for helping me,<BR>
<BR>
Simone.<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
**********<BR>
Scopri la nuova Alice Mail!<BR>
1 GB di spazio con antivirus, antispam e fino a 2 GB di allegati.<BR>
<BR>
Registrati GRATIS su <A =
HREF=3D"http://registra.rossoalice.alice.it/registra/basic/entratabasic.d=
o?entryPoint=3Dfooter">http://registra.rossoalice.alice.it/registra/basic=
/entratabasic.do?entryPoint=3Dfooter</A></FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C86129.7C9326E9--
--===============0076698132==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
help-flex mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-flex
--===============0076698132==--