title: Runtime "syntax error" from lex and yacc
body: <p>I cannot figure out why I am getting these results.</p>
  
  <pre><code>++
  +add
  +syntax error 2
  
  ++
  +add
  +syntax error 4
  </code></pre>
  
  <p>The ++ is my input and lex echoes each character and yacc prints add whenever it gets a +. It's giving me this error on every other + it gets. Doesn't matter how I give the input, I get the same results if I hit enter on every +.</p>
  
  <p>lex</p>
  
  <pre><code>%{
  #include "y.tab.h"
  
  int chars = 0;
  %}
  %%
  "+"     {ECHO; chars++; return ADD;}
  .       {ECHO; chars++;}
  \n      {ECHO;}
  %%
  </code></pre>
  
  <p>yacc</p>
  
  <pre><code>%{
  #include &lt;stdio.h&gt;
  extern int chars;
  
  void yyerror (const char *str) {
      printf ("%s %d\n", str, chars);
  }
  %}
  
  %token ADD
  %%
  symbol  : ADD       {printf ("add\n");}
          ;
  %%
  
  int main () {
      while (1) {
          yyparse ();
      }
  }
  </code></pre>