You need to return something from the EOF
action; otherwise, flex
will continue to attempt to read the input, and everytime it does it will find that it is at the EOF
, causing it to execute your action again.
In fact, you should always return 0
from an <<EOF>>
pattern, if you are working with yacc/bison
, because that's how you signal the parser that it has reached the end of input. However, in most cases it is not actually necessary to explicitly do anything because return 0
is the default EOF
action.