in my SL.lex file i have this regular expression for fractional numbers:
Digit = [1-9]
Digit0 = 0|{Digit}
Num = {Digit} {Digit0}*
Frac = {Digit0}* {Digit}
Pos = {Num} | '.' {Frac} | 0 '.' {Frac} | {Num} '.' {Frac}
PosOrNeg = -{Pos} | {Pos}
Numbers = 0 | {PosOrNeg}
and then in
/* literals */
{Numbers} { return new Token(yytext(), sym.NUM, getLineNumber()); }
but every time i try to recognize a number with a dot, it fails and i get an error.
instead of '.' i also tried \\.,\.,".", but every time it fails.
You are right,
.needs to be escaped, otherwise it matches anything but line return.But quoting characters is done with double quotes, not single quotes.
If you do that, the input:
works as expected:
Also, regular expressions are more powerful than just unions, you could make it more concise: