Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello CPs,

I am new to Flex and I'm trying to understand how compilers and lexical analyzers work. I acquired this sample program from the internet and it doesn't seem to work. I am using Flex 2.5.4a. There were a few fixes but it didn't work. Are there any other syntactical errors or is the updated version changed any semantics. Given below is the program. While in the cmd-line when given the command flex -filename it returns the error message Premature end of file at line 32. Thanks in advance.

C#
%{

  #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);
}
Posted
Updated 27-Jul-15 9:42am
v2

I don't know Flex, but usually when you see an error like that you've got mismatched braces or quotes or something else that must be paired up.
 
Share this answer
 
First result in google for "flex premature end of file" gives the exact same question AND CODE on stackoverflow from nearly four years ago http://stackoverflow.com/questions/8226993/premature-eof-error-in-flex-file[^].

Problem is the space before the %}, flex i sensitive to spacing.
 
Share this answer
 
Comments
Ashwin2013 27-Jul-15 15:42pm    
I'm sorry I didn't post the edited version of that code. I removed the spacing and it still doesn't work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900