Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

premature eof error in flex file

I have the following code and it gives an error" "hello.l",line 31: premature EOF" when I run the following command flex hello.l

%{

  #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);
}
like image 977
Waseem Avatar asked Nov 22 '11 12:11

Waseem


2 Answers

The problem is with your %} - flex is very sensitive about spacing. Remove the space before it, and all should be well.

Also, if you don't want a yywrap function, you can stick %option noyywrap in your flex file.

like image 113
barrucadu Avatar answered Oct 22 '22 18:10

barrucadu


Change this:

%{

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

  %}

To this:

%{

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

%}

It works with flex 2.5.35 (mingw)

like image 7
INS Avatar answered Oct 22 '22 18:10

INS