私はフレックスがまったく初めてです。
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 構文コードに「main」関数を入れる必要があるのはなぜですか? 私が望むのは、yylex(); を呼び出せるようにすることです。別のcファイルから。