title: flex/bison: '$' operand giving large/wrong chunks of text
body: <p>I'm not sure how to put this, as "addressing" seems to refer to the "%" operand and specification of lines/columns, which is not what I am looking for. I am trying to figure out how exactly the "$" symbol works. Also I do not know if these are operands or what they are, if you can tell me, please do, if not, avoid focusing on what I call them, and emphasize on telling me what "$" does.
  I have this fairly long expression in bison:</p>
  
  <pre><code>for: KW_FOR S_PARENTHESIS_OPEN assignment S_SEMICOLON gen_ex S_SEMICOLON assignment S_PARENTHESIS_CLOSE command_block 
  {
  printf("condition: %s", $3);
  };
  </code></pre>
  
  <p>(note that anything in capitals is a token corresponding directly to a word/symbol)
  and the input is:</p>
  
  <pre><code>void myProgram ()
  BEGIN
  x = 1;
  if( x &lt; 3 ) x = 2;
  
  if(x &gt; 3) x = 3; else x = 2;
  
  while (x &lt; 2)
  BEGIN
  y = 2;
  END
  
  for ( x = 1; y &lt; 3; z = 2)
  BEGIN
  z = 4;
  END
  
  END
  </code></pre>
  
  <p>I was expecting that the printf() would give me the <code>for</code> keyword if I asked for <code>$1</code>, but it actually starts from <code>y = 2</code> in the previous "while" loop, which I cannot figure out since it is out of the scope of the expression.</p>
  
  <p>So, how exactly is this supposed to be deciding where the reference I am making is? And since we're at it, what is this called anyway?</p>
  
  <p><strong>Edit:</strong> I know I write $3, and that works. If I write $1 it doesn't work as expected. I am asking what these stuff are called, and how bison decides what is the first symbol, and thus why it gives me things from before the particular expression if I ask for $1. That's what I want to know, as well as how to properly refer to these things.</p>