Using flex offers you the opportunity to handle an end of file with the pattern <<EOF>>.
flex
<<EOF>>
Is there any similar solution with lex(1)?
lex(1)
No; what you describe is a flex extension.