title: Bison reads semantic values of char * symbols until the end of rule
body: <p>Can anyone help me with these simple problem. I have these tiny grammar rules in Bison:</p>
  
  <pre><code>pair_list
   : pair_list pair               
   | pair                         
  ; 
  
  pair
   : KEY ':' VAR ';'          { $$ = new_sym($1, $3); add_entry($$);}
  ;
  </code></pre>
  
  <p>I have these type declarations:</p>
  
  <pre><code>%union {
      struct symbol *symbl;
      char *key;
      int val;
      int token;
  }
  
  %token &lt;key&gt; KEY
  %token &lt;val&gt; VAL
  %token &lt;token&gt; EOL
  
  %type &lt;symbl&gt; pair
  %type &lt;key&gt; id
  </code></pre>
  
  <p>My problem is that the value Bison assigns to <code>$1</code> is the string value of the rule from '$1' up to the end of the rule. For example, if the Flex returned <code>"hello"</code> for <code>KEY</code> and <code>23</code> for <code>VAL</code>, the value of <code>$1</code> becomes <code>"hello:23;"</code>. How can I make bison make <code>$1</code> to be just <code>"hello"</code>?</p>
  
  <p>Here are my flex rules:</p>
  
  <pre><code>[ \t\n]+                {/*Ignore*/}
  [0-9]+                  {yylval.val = atoi(yytext); return VAL;}
  ":"                     {return ':';}
  ";"                     {return ';';}
  [A-Za-z][A-Za-z0-9_]*   {yylval.key = yytext; return KEY;}
  </code></pre>
  
  <p>To prove that Flex rules are correct I edited my grammar:</p>
  
  <pre><code>/*Edited grammar to show that yylex returns correct value yylval.key for KEY which is assigned to    id. However, when evaluated in rule pair: KEY ':' VAR ';', the value of $1 became the string representation of KEY + ":" + VAR + ";" (where + is for concatenation).
  */
  pair_list
   : pair_list pair               
   | pair                         
  ; 
  
  pair
   : id ':' VAR ';'           { $$ = new_sym($1, $3); add_entry($$);}
  ;
  
  id
   : KEY                      {printf("%s\n", $1); /*This prints the id correctly*/}
  ;
  </code></pre>