Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lex: default rule for unrecognized strings

Tags:

flex-lexer

lex

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

like image 360
osolmaz Avatar asked Oct 06 '22 03:10

osolmaz


1 Answers

Typically, you would define a rule like this, which would go at the very end:

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

This rule will match any character that wasn't matched by any other rule.

Hope this helps!

like image 127
templatetypedef Avatar answered Oct 10 '22 03:10

templatetypedef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!