premature eof error in flex file

37,242

Solution 1

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.

Solution 2

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)

Share:
37,242
Waseem
Author by

Waseem

Updated on January 24, 2022

Comments

  • Waseem
    Waseem over 2 years

    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);
    }
    
  • Waseem
    Waseem over 12 years
    Can you tell me how to run compile both lex.yy.c and y.tab.c files in dev-C++ ?