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.
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:
See the JFlex manual chapter on regular expressions for details