Next: How can I make REJECT cascade across start condition boundaries?, Previous: Can I build nested parsers that work with the same input file?, Up: FAQ
There is no way to write a rule which is “match this text, but only if
it comes at the end of the file”.  You can fake it, though, if you happen
to have a character lying around that you don't allow in your input. 
Then you redefine YY_INPUT to call your own routine which, if it sees
an ‘EOF’, returns the magic character first (and remembers to return a
real EOF next time it's called).  Then you could write:
     <COMMENT>(.|\n)*{EOF_CHAR}    /* saw comment at EOF */