Lex: default rule for unrecognized strings

In ocamllex, I can use _ as a rule, lexer to match any string that does not match the previously defined rules, and causes errors. How to achieve this in lex / flex?

+4
source share
1 answer

Typically, you should define a rule like this that will go at the very end:

 .|\n { /* process default here */ } 

This rule will match any character that did not match any other rule.

Hope this helps!

+3
source

All Articles