C flex文件中的过早eof错误

C flex文件中的过早eof错误,c,bison,lexical-analysis,flex-lexer,C,Bison,Lexical Analysis,Flex Lexer,我有下面的代码,当我运行下面的命令时,它给出了一个错误“hello.l”,第31行:premature EOF 你好,我是弗莱克斯 %{ #include <stdlib.h> #include "y.tab.h" %} %% ("hi"|"oi")"\n" {return HI; } ("tchau"|"bye")"\n" {return BYE;} . {yyerror(); } %% int main(v

我有下面的代码,当我运行下面的命令时,它给出了一个错误“hello.l”,第31行:premature EOF 你好,我是弗莱克斯

%{

  #include <stdlib.h>
  #include "y.tab.h"

  %}

%%

("hi"|"oi")"\n"      {return HI; }
("tchau"|"bye")"\n"  {return BYE;}
.                    {yyerror(); }

%%

int main(void)
{
    yyparse();
    return 0;
}

int yywrap(void)
{
    return 0;
}

int yyerror(void)
{
    printf("Error\n");
    exit(1);
}
%{
#包括
#包括“y.tab.h”
%}
%%
(“hi”|“oi”)“\n”{返回hi;}
(“tchau”|“bye”)“\n”{返回bye;}
.                    {yyerror();}
%%
内部主(空)
{
yyparse();
返回0;
}
int-yywrap(无效)
{
返回0;
}
int yyerror(无效)
{
printf(“错误\n”);
出口(1);
}

问题在于您的
%}
-flex对间距非常敏感。把它前面的空间移走,一切都会好起来的

此外,如果您不想要yywrap函数,可以将
%option noyyywrap
粘贴到flex文件中。

更改此选项:

%{

  #include <stdlib.h>
  #include "y.tab.h"

  %}
%{
#包括
#包括“y.tab.h”
%}
为此:

%{

  #include <stdlib.h>
  #include "y.tab.h"

%}
%{
#包括
#包括“y.tab.h”
%}

它与flex 2.5.35(mingw)配合使用

您能告诉我如何在dev-c++中编译lex.yy.c和y.tab.c文件吗?