bison end of file
In fact to catch end of file in lex|flex you can use the yywrap()
function which is called by lexical analyzer if end of the input file is reached.
this solution is available by both lex and flex.the callback of yywrap()
indicates the EOF
so you can reimplement this function and inject the work you need to do at the end of your input stream.
You could use a flex EOF rule to append a newline to the input:
<<EOF>> { static int once = 0; return once++ ? 0 : '\n' }
In your lex file
#define yyterminate() return token::END
In your yacc file
%token END 0 "end of file"