The longest match is returned.
From flex and bison, word processing tools :
How Flex Handles Ambiguous Templates
Most flexible programs are rather ambiguous, with several patterns that can match the same input. Flex resolves ambiguity with two simple rules:
- Match the longest line each time you enter the scanner.
- In case of binding, use the template that appears first in the program.
You can check it yourself, of course:
file: demo.l
%% "//"[!/] {printf("FIRST");} "//"[!/]< {printf("SECOND");} %% int main(int argc, char **argv) { while(yylex() != 0); return 0; }
Note that / and < no escaping is required, and {1} is redundant.
bart@hades :~/Programming/GNU-Flex-Bison/demo$ flex demo.l bart@hades :~/Programming/GNU-Flex-Bison/demo$ cc lex.yy.c -lfl bart@hades :~/Programming/GNU-Flex-Bison/demo$ ./a.out < in.txt SECOND
where in.txt contains //!< .
source share