<<EOF>>
is not a character, it is a special flex rule. So you cannot put it inside [...]
to make it part of a character class. When you try to do that, the letters <
, >
, E
, O
and F
become part of the character class.
You hardly ever need a <<EOF>>
rule, anyway and you certainly should not attempt to ignore it.
Remember that flex will use the first matching pattern in a scanner definition, when more than one pattern has the same longest match. So order matters. Unless you suppressed or ignored flex's warnings, it would have told you that your "<"
and "<<"
rules could never match, because they were overridden by the erroneous whitespace rules. It's always important to read and try to understand warnings (or at a minimum ask about what they mean, particularly when they seem relevant.)
From your comment about EOF matching the error pattern, I suspect that you are using an empty match to trigger an error condition. Don't do that. Your error (default) rule should be the last one in the definition, and it should match .|\n
(or just .
if you are certain that \n
will always be matched by some rule.) That will catch any otherwise unrecognized single character, but will not be triggered by the end of file, because, as I said earlier, <<EOF>>
is not a character.