我对 flex 完全陌生。
使用 flex 时出现构建错误。也就是说,我使用 flex 生成了一个 .c 文件,并且在运行它时,我收到了这个错误:
1>lextest.obj : error LNK2001: unresolved external symbol "int __cdecl isatty(int)" (?isatty@@YAHH@Z)
1>C:\...\lextest.exe : fatal error LNK1120: 1 unresolved externals
这是我正在使用的 lex 文件(从这里获取):
/*** Definition section ***/
%{
/* C code to be copied verbatim */
#include <stdio.h>
%}
/* This tells flex to read only one input file */
%option noyywrap
%%
/*** Rules section ***/
/* [0-9]+ matches a string of one or more digits */
[0-9]+ {
/* yytext is a string containing the matched text. */
printf("Saw an integer: %s\n", yytext);
}
. { /* Ignore all other characters. */ }
%%
/*** C Code section ***/
int main(void)
{
/* Call the lexer, then quit. */
yylex();
return 0;
}
同样,为什么我必须在 lex 语法代码中放置一个“主”函数?我想要的是能够调用 yylex(); 从另一个c文件。