title: passing value from flex to bison
body: <p>I am trying to print token value in bison sent from flex but for some reason the value printed is garbage in some cases.</p>
  
  <p>lex code:</p>
  
  <pre><code>\".*\" {
  std::string* s1 = new std::string(yytext);
      std::string s2 = *s1;
      std::string s3 = s2.substr(1,s2.size() - 2);
      yylval.s = &amp;s3;
  
      return VARIABLE;
  }
  </code></pre>
  
  <p>bison code:</p>
  
  <pre><code>    %union{
              std::string *s;
      };
  
  %type &lt;s&gt; expr
  
  expr : VARIABLE { caps($1); }
  
  void caps(std::string *str){
      std::string str1 = *str;
  
      for(std::string::size_type i=0;i&lt;str1.length();i++)
              std::cout &lt;&lt; str1[i];
  }
  </code></pre>
  
  <p>If i input a string with length less than 15 characters it outputs fine but if the length goes beyond it garbage is printed.</p>
  
  <p>If i isolate the c++ code and running it works fine i am not getting why is it happening so can someone find the mistake in it.</p>