Is it possible to write a lex or flex script containing a set of rules where the maximal-munch matching step will always match a length-zero string?
I ask this because the mathematical definition of regular expressions permits regular expressions that only match zero-length strings. For example, the simple regular expression ε only matches the empty string. However, the flex pattern documentation doesn’t seem to allow you to specify regular expressions of this form.
I don’t know about lex, but flex can match the empty string by using a trailing context:
This will match an empty string before any character, but it can be almost any pattern (see flex documentation about limitations).
If you want to match the end of the input, you have to use the special symbol <<EOF>> (see flex documentation about eof).
EDIT: Now that i think a little more about it, the trailing context might not be mandatory. Just “” may work. If it does, i still highly recommand to use a trailing context in this case when possible. It prevents many side effects with malformed inputs and helps debugging.