Next: I am trying to port code from AT&T lex that uses yysptr and yysbuf., Previous: How can I build a two-pass scanner?, Up: FAQ [Contents][Index]
One way to assign precedence, is to place the more specific rules first. If
two rules would match the same input (same sequence of characters) then the
first rule listed in the flex
input wins, e.g.,
%% foo[a-zA-Z_]+ return FOO_ID; bar[a-zA-Z_]+ return BAR_ID; [a-zA-Z_]+ return GENERIC_ID;
Note that the rule [a-zA-Z_]+
must come *after* the others. It will match the
same amount of text as the more specific rules, and in that case the
flex
scanner will pick the first rule listed in your scanner as the
one to match.