[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Help please
From: |
lookthree |
Subject: |
Help please |
Date: |
Sun, 27 Jan 2008 22:13:39 +0100 |
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 = LT; return(RELOP);}
"<=" { yylval = LE; return(RELOP);}
"=" { yylval = EQ; return(RELOP);}
"<>" { yylval = NE; return(RELOP);}
">" { yylval = GT; return(RELOP);}
">=" {yylval = 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 = new yyFlexLexer();
while ((token=lexer->yylex()) != 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
g++ main_prog.cpp -o main_prog
,infact the system answer me with:
/usr/include/FlexLexer.h:113: error: redefinition of class yyFlexLexer
/usr/include/FlexLexer.h:113: error: previous definition of class yyFlexLexer
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?entryPoint=footer
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Help please,
lookthree <=