10

By default flex uses the longest match rule. Is there any way to override this behavior to make it match the shortest sequence?

Thank you

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
VilleDePommes
  • 119
  • 1
  • 6
  • No, and you wouldn't want it if you had it. For example, many if not most lexers (certainly all mine) end with a catch-all rule `. return yytext[0];`. That would become the only rule that did anything. – user207421 Mar 01 '15 at 18:44

1 Answers1

2

This page in the Flex manual says that it doesn't have any non-greedy operators because it is a scanner rather than a parser, and suggests regular expressions could be used to add the missing functionality.

rici
  • 234,347
  • 28
  • 237
  • 341
Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
  • 2
    i didn't mean the greedy operators per se.If you have completely separate regexprs both matching the same prefix of some string a lexer by default chooses the longest one. what i need is to make it pick up the shorter one, reset, and start matching again. – VilleDePommes Nov 30 '11 at 21:45