title: Bison/Flex print value of terminal from alternative
body: <p>I have written a simple grammar:</p>
  
  <pre><code>operations :
      /* empty */
      | operations operation ';'
      | operations operation_id ';'
      ;
  
  operation :
      NUM operator NUM
      {
          printf("%d\n%d\n",$1, $3);
      }
      ;
  
  operation_id :
      WORD operator WORD
      {
          printf("%s\n%s\n%s\n",$1, $3, $&lt;string&gt;2);
      }
      ;
  
  operator :
      '+' | '-' | '*' | '/'
      {
          $&lt;string&gt;$ = strdup(yytext);
      }
      ;
  </code></pre>
  
  <p>As you can see, I have defined an <code>operator</code> that recognizes one of 4 symbols. Now, I want to print this symbol in <code>operation_id</code>. Problem is, that logic in <code>operator</code> works only for last symbol in alternative.
  So if I write <strong>a/b;</strong> it prints <strong>ab/</strong> and that's cool. But for other operations, eg. <strong>a+b;</strong> it prints <strong>aba</strong>. What am I doing wrong?</p>
  
  <p>*I ommited new lines symbols in example output.</p>