2

if I have defined something like that

COMMAND         = "HI" | "HOW" | "ARE" | "YOU" 

How can i say "if u match something that is not a COMMAND"?..

I tried with this one

[^COMMAND]

But didn't work..

2 Answers2

0

As far as I can tell this is not possible with (current) JFlex.

We would need an effective tempered negative lookahead: ((?!bad).)*

There are two ways to do a negative lookahead in JFlex:

  • negation in the lookahead: x / !(y [^]*) (match x if not followed by y in the lookahead).
  • lookahead with negated elements: x / [^y]|y[^z] (match if x is followed by something that is !a or a!b.

Otherwise, you may get some ideas from this answer (specifically the lookaround alternatives): https://stackoverflow.com/a/37988661/8291949

wp78de
  • 18,207
  • 7
  • 43
  • 71
0

Well, you can just match anything else, then

COMMAND         = "HI" | "HOW" | "ARE" | "YOU" 
. {throw new RuntimeException("Illegal character: <" + yytext() + ">");}
rds
  • 26,253
  • 19
  • 107
  • 134