0

I am generating lexical analyzer with JLEX. I found a regular expression for string literal from this link and used it in .jflex file same of other expressions. but it gives me this error : unterminated string at the end of the line
StringLiteral = \"(\\.|[^"\\])*\"

can anyone help me please, thanks.

user9137963
  • 105
  • 9

1 Answers1

1

The regular expression you copied is for (f)lex, which uses a slightly different syntax for regular expressions. In particular, (f)lex treats " as an ordinary character inside bracketed classes, so [^"\\] is a character class matching anything other than (^) a quotation mark (") or a backslash (\\).

However, in JFlex, the " is a quoting character, whether outside or inside brackets. So the " in the character class is unterminated. Hence the error message.

So you need to backslash-escape it:

StringLiteral = \"(\\.|[^\"\\])*\"

See the JFlex manual chapter on regular expressions for details

rici
  • 234,347
  • 28
  • 237
  • 341