I think this - case by case for each language - is true.
If comment starter exists in a string literal, lexer has to ignore it.
Similarly, in C, if escaped double quote \"
exists in a string literal,
lexer has to ignore it.
For this purpose, flex has start condition.
This enables contextual analysis.
For instance, there is an example for C comment analysis(between /*
and */
)
in flex texinfo manual:
<INITIAL>"/*" BEGIN(IN_COMMENT);
<IN_COMMENT>{
"*/" BEGIN(INITIAL);
[^*\n]+ /* eat comment in chunks */
"*" /* eat the lone star */
\n yylineno++;
}
Start condition also enables string literal analysis.
There is an example of how to match C-style quoted strings using start
conditions in the item Start Conditions, and
there is also FAQ item titled
How do I expand backslash-escape sequences in C-style quoted strings?
in flex texinfo manual.
Probably this will answer directly your question about string literal.