I have a lex grammar that contains the rules for a double-quoted string:
...
%x DOUBLEQUOTE
...
%%
"\"" { yylval->string = NULL; BEGIN(DOUBLEQUOTE); }
<DOUBLEQUOTE> {
"\n" {
PARSER->linepos = 0;
(PARSER->linenum)++;
expr_parser_append_string(PARSER, &(yylval->string), yytext);
}
[^\"\n]+ { expr_parser_append_string(PARSER, &(yylval->string), yytext); }
"\\\"" { expr_parser_append_string(PARSER, &(yylval->string), yytext); }
"\"" {
BEGIN(INITIAL);
if ( yylval->string != NULL )
string_unescape_c(yylval->string);
return ( TOKEN_STRING );
}
}
Somehow the escape sequence \ " matches only at the beginning of the line. If \" appears last in the line, it looks like charactersand "are matched separately.
For example:
Why does the escape sequence \ " not match the rule "\\\""when it appears last on the line?
jozef source
share