Reputation: 11
I am making a program in flex that takes a user's input in the form of a string that describes a shape. Now my code seems correct, but I get a premature eof on compilation.
I have also tried doing what similar questions have as answers, but still nothing.
%{
int flag = 0;
}%
%%
"point" + [A-H]|"line" + [A-H]{2}|"triangle" + [A-H]{3}|"square" + [A-H]{4}|"pentagon" + [A-H] {5}|"hexagon" + [A-H]{6}|"heptagon" + [A-H]{7}|"octagon" + [A-H]{8}
flag=1;
%%
main(){
yylex();
if (flag == 1){
printf("Accepted");
}else{
printf("Not accepted");
}
}
Upvotes: 1
Views: 911
Reputation: 370465
Your %{
is unclosed because you wrote }%
instead of %}
. So flex thinks the }%
and everything after it is supposed to be part of the C code and is still waiting for a closing %}
when it reached the end of the file.
Upvotes: 3