title: parse error when handling strings
body: <pre><code>%option case-insensitive
  %option noyywrap
  %option yylineno
  
  
  id              [a-zA-Z][a-zA-Z_0-9]*
  
  integer         (0[xX][0-9A-Fa-f]+)|([0-9]+)
  
  real            [0-9]*\.[0-9](e|E)?[0-9]*
  
  undefined       [^"\r\n \t]
  
  %x STR
  %%
  \" string_buf_ptr = string_buf; BEGIN(STR);
  
  &lt;STR&gt;\"        { /* saw closing quote - all done */
      BEGIN(INITIAL);
      *string_buf_ptr = '\0';
      /* return string constant token type and
       * value to parser
       */
  
       yylval.strVal = strdup(string_buf);
       sprintf(yyout, yylval.strVal);
       return STR;
      }
  
  &lt;STR&gt;\\n  *string_buf_ptr++ = '\n';
  &lt;STR&gt;\\t  *string_buf_ptr++ = '\t';
  &lt;STR&gt;\\r  *string_buf_ptr++ = '\r';
  &lt;STR&gt;\\b  *string_buf_ptr++ = '\b';
  &lt;STR&gt;\\f  *string_buf_ptr++ = '\f';
  
  &lt;STR&gt;\\(.|\n)  *string_buf_ptr++ = yytext[1];
  
  &lt;STR&gt;[^\\\n\"]+        {
      char *yptr = yytext;
  
      while ( *yptr )
              *string_buf_ptr++ = *yptr++;
      }
  </code></pre>
  
  <p>This is part of my code for the lexical analysis of strings. The goal of this code is to locate strings (C-like strings ex. <code>"Hello World"</code>) and return them to our parser for handling. </p>
  
  <p>I've also constructed a parser using the <code>Yacc</code> tool and it's almost perfect except from when we are assigning strings to variables (ex. <code>x="Hello World";</code>)
  When I do that, the <code>yyerror(const char*)</code> function is invoked and the message is <code>unexpected $undefined.</code> I cannot understand why this is happening. The reduction should recognize a <code>left value</code> <code>x</code>, an <code>assignment</code> and a <code>constant String</code> <code>"Hello World"</code>, what am I getting wrong?</p>