title: flex and bison: string literal
body: <p>I need your advice on how to get string literal. String literals is everything what starts with <code>b"</code>, has zero or more symbols then and ends with <code>"</code>. Token is called <code>BYTES_OBJECT</code>. <code>bytes_type</code> is a name of type which stores such string literals.
  Here is what I've tried:</p>
  
  <pre><code>{%
  #include "parser.hpp"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  string BUFFER;
  %}
  
  %option noyywrap
  %x COMMENT
  %x BYTESMODE
  
  "b"[\"] {
    BUFFER = string();
    BEGIN BYTESMODE;
  } // BYTESMODE
  
    &lt;BYTESMODE&gt;{BYTES_HEXCODE} {
      // convert to hexcode
    } // BYTES_HEXCODE
  
    &lt;BYTESMODE&gt;{BYTES_ESCAPE} {
      yytext++; // Move to the next char
      switch (*yytext) {
        case '\'': BUFFER += '\''; break;
        case '\"': BUFFER += '\"'; break;
        case '\\': BUFFER += '\\'; break;
        case '\?': BUFFER += '?';  break;
        case 'a':  BUFFER += '\a'; break;
        case 'b':  BUFFER += '\b'; break;
        case 'f':  BUFFER += '\f'; break;
        case 'n':  BUFFER += '\n'; break;
        case 'r':  BUFFER += '\r'; break;
        case 't':  BUFFER += '\t'; break;
        case 'v':  BUFFER += '\v'; break;
      } // end of switch
    } // BYTES_ESCAPE
  
    &lt;BYTESMODE&gt;[^\"] {
      BUFFER += yytext;
    } // BYTES_SYMBOL
  
    &lt;BYTESMODE&gt;\" {
      bytes_type object = BUFFER;
      yylval.bytes_buffer = &amp;object;
      BEGIN INITIAL;
      return BYTES_OBJECT;
    } // closing quote
  </code></pre>
  
  <p>However, when I try to create string, it cause segment fault. If <code>return BYTES_OBJECT</code> is before <code>BEGIN INITIAL</code>, it processes literals incorrect. How can I solve it? I guess that even concept can be done more easy than I've written.</p>
  
  <p>Thanks in advance!</p>