Je rencontre un problème avec mon analyseur lexical écrit en flex. Quand j'essaye de le compiler il n'y a aucun dossier d'exe créé et j'obtiens beaucoup d'erreurs. Ce qui suit est le fichier flex:Flex ne compile pas Lexical Analyzer - erreur avec macro
%{
#ifdef PRINT
#define TOKEN(t) printf("Token: " #t "\n");
#else
#define TOKEN(t) return(t);
#endif
%}
delim [ \t\n]
ws {delim}+
digit [0-9]
id {character}({character}|{digit})*
number {digit}+
character [A-Za-z]
%%
{ws} ; /* Do Nothing */
":" TOKEN(COLON);
";" TOKEN(SEMICOLON);
"," TOKEN(COMMA);
"(" TOKEN(BRA);
")" TOKEN(CKET);
"." TOKEN(DOT);
"'" TOKEN(APOS);
"=" TOKEN(EQUALS);
"<" TOKEN(LESSTHAN);
">" TOKEN(GREATERTHAN);
"+" TOKEN(PLUS);
"-" TOKEN(SUBTRACT);
"*" TOKEN(MULTIPLY);
"/" TOKEN(DIVIDE);
{id} TOKEN(ID);
{number} TOKEN(NUMBER);
'{character}' TOKEN(CHARACTER_CONSTANT);
%%
Ce sont les erreurs que je reçois:
spl.l: In function 'yylex':
spl.l:19:7: error: 'COLON' undeclared (first use in this function)
":" TOKEN(COLON);
^
spl.l:5:25: note: in definition of macro 'TOKEN'
#define TOKEN(t) return(t);
^
spl.l:19:7: note: each undeclared identifier is reported only once for each function it appears in
":" TOKEN(COLON);
^
spl.l:5:25: note: in definition of macro 'TOKEN'
#define TOKEN(t) return(t);
^
spl.l:20:7: error: 'SEMICOLON' undeclared (first use in this function)
";" TOKEN(SEMICOLON);
^
spl.l:5:25: note: in definition of macro 'TOKEN'
#define TOKEN(t) return(t);
Et les commandes que je utilise pour compiler sont:
flex a.l
gcc -o newlex.exe lex.yy.c -lfl
Quelqu'un peut voir où je peut-être aller mal?
BTW vous ne devriez pas avoir besoin de ";" dans votre macro comme vous l'appelez déjà avec un –