我有一个简单的“语言”,我使用Flex(词法分析器),它是这样的:
@H_301_2@/* Just like UNIX wc */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}
%%
[a-zA-Z]+ { words++; chars += strlen(yytext); }
\n { chars++; lines++; }
. { chars++; }
%%
int main()
{
yylex();
printf("%8d%8d%8d\n",lines,words,chars);
}
我运行flex count.l,一切正常,没有错误或警告,然后当我尝试做一个cc lex.yy.c我得到这个错误:
ubuntu@eeepc:~/Desktop$ cc lex.yy.c
/tmp/ccwwkhvq.o: In functionyylex':
yywrap’
lex.yy.c:(.text+0x402): undefined reference to
/tmp/ccwwkhvq.o: In functioninput':
yywrap’
lex.yy.c:(.text+0xe25): undefined reference to
collect2: ld returned 1 exit status
哪里不对?