フレックスで書かれた字句解析ツールに問題があります。私はそれをコンパイルしようとすると、exeファイルが作成されていないと私は多くのエラーを取得します。Lexical Analyzerをコンパイルしていないフレックス - マクロのエラー
%{
#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);
%%
これらは私が受け取るエラーです:
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);
そして、私はコンパイルするために使用していたコマンドは次のとおりです。どこ
flex a.l
gcc -o newlex.exe lex.yy.c -lfl
誰でも見ることができます以下は、フレックスファイルです間違っている可能性がありますか?
ご参考までに、 ";"あなたのマクロでは既に1つで呼んでいるように –