If your input is really on two different lines, then your ANY_CHAR rule is matching the newline character. If you don't care about newlines, you should ignore them. I'd also recommend dropping the *
modifier on ANY_CHAR
as per David Gorsline's comments.
...
ANY_CHAR .
NEW_LINE [\n\r]
...
%%
"gago" { BEGIN V_TYPE; }
<V_TYPE>"If" { printf("print If"); exit(1);}
<V_TYPE>"Then" { printf("print Then"); exit(1);}
<V_TYPE>"Endif" { printf("print Endif"); exit(1);}
<V_TYPE>"While" { printf("print While"); exit(1);}
<V_TYPE>"EndWhile" { printf("print EndWhile"); exit(1);}
<V_TYPE>{NEW_LINE}+ { /* ignore */ }
<V_TYPE>{ANY_CHAR} { printf("print Other"); exit(1);}