title: Lex - double quotation mark inside string
body: <p>I have lex grammar that contains rules for double quotes string:</p>
  
  <pre><code>...
  %x DOUBLEQUOTE
  ...
  %%
  "\""                { yylval-&gt;string = NULL; BEGIN(DOUBLEQUOTE); }
  &lt;DOUBLEQUOTE&gt; {
      "\n"            {
                          /* reset column counter on new line */
                          PARSER-&gt;linepos = 0;
                          (PARSER-&gt;linenum)++;
                          expr_parser_append_string(PARSER, &amp;(yylval-&gt;string), yytext);
                      }
      [^\"\n]+        { expr_parser_append_string(PARSER, &amp;(yylval-&gt;string), yytext); }
      "\\\""          { expr_parser_append_string(PARSER, &amp;(yylval-&gt;string), yytext); }
      "\""            {
                          BEGIN(INITIAL);
                          if ( yylval-&gt;string != NULL )
                              string_unescape_c(yylval-&gt;string);
                          return ( TOKEN_STRING );
                      }
  }
  </code></pre>
  
  <p>Somehow the escape sequence <strong>\"</strong> is matched only at beginning of a string. If the <strong>\"</strong> appears latter in a string it looks like the characters <strong>\</strong> and <strong>"</strong> are matched separately.</p>
  
  <p>For instance:</p>
  
  <ol>
  <li><p>Passes: <code>"\"    "</code></p></li>
  <li><p>Fails:  <code>" \"   "</code></p></li>
  <li><p>Fails:  <code>"This is string example: \"a string inside of string\""</code></p></li>
  </ol>
  
  <p>Why the escape sequence <strong>\"</strong> is not matched by the rule <code>"\\\""</code> when appears latter in a string?</p>