How do lexical analyzers handle comments and escape sequences?

A comment and an escape sequence (such as a string literal) are very exclusive to the regular symbolic representation.

I find it difficult to understand how regular lexical analyzers symbolize them. How do lexical analyzers such as lex, flexor the like , process such characters? Is there a general method? Or just in each case for each language?

+5
source share
3 answers

, - - . , lexer . , C, \" lexer .
flex . .
, C ( /* */) flex texinfo:

<INITIAL>"/*"   BEGIN(IN_COMMENT);
<IN_COMMENT>{
"*/"            BEGIN(INITIAL);
[^*\n]+         /* eat comment in chunks */
"*"             /* eat the lone star */
\n              yylineno++;
}

. , C, start " " FAQ escape- C? flex texinfo.
, .

+1

escape- (, ) .

, , , , . ( ), escape- .

, escape-, \\, \", \n \r, ( E):

E -> \ S
S -> \
S -> "
S -> n
S -> r

escape- (.. , ).

+1

lex, ( ++ style/comments) (, , Python), , //, .

+1

All Articles