title: Bison example code not compiling
body: <p>I'm reading LFS and came across <strong>bison</strong> which I've seen it before other places so I thought I should learn a bit more about it. I found <a href="http://alumni.cs.ucr.edu/~lgao/teaching/bison.html" rel="nofollow">this page from UC Riverside CS department</a> and the example code is not working. Anyone know whats wrong? For convenience I pasted the code:</p>
  
  <p><strong>calc.lex</strong> file:</p>
  
  <pre><code>/* Mini Calculator */
  /* calc.lex */
  
  %{
  #include "heading.h"
  #include "tok.h"
  int yyerror(char *s);
  int yylineno = 1;
  %}
  
  digit       [0-9]
  int_const   {digit}+
  
  %%
  
  {int_const} { yylval.int_val = atoi(yytext); return INTEGER_LITERAL; }
  "+"     { yylval.op_val = new std::string(yytext); return PLUS; }
  "*"     { yylval.op_val = new std::string(yytext); return MULT; }
  
  [ \t]*      {}
  [\n]        { yylineno++;   }
  
  .       { std::cerr &lt;&lt; "SCANNER "; yyerror(""); exit(1);    }
  </code></pre>
  
  <p><strong>calc.y</strong> file:</p>
  
  <pre><code>/* Mini Calculator */
  /* calc.y */
  
  %{
  #include "heading.h"
  int yyerror(char *s);
  int yylex(void);
  %}
  
  %union{
    int       int_val;
    string*   op_val;
  }
  
  %start  input 
  
  %token  &lt;int_val&gt;   INTEGER_LITERAL
  %type   &lt;int_val&gt;   exp
  %left   PLUS
  %left   MULT
  
  %%
  
  input:      /* empty */
          | exp   { cout &lt;&lt; "Result: " &lt;&lt; $1 &lt;&lt; endl; }
          ;
  
  exp:        INTEGER_LITERAL { $$ = $1; }
          | exp PLUS exp  { $$ = $1 + $3; }
          | exp MULT exp  { $$ = $1 * $3; }
          ;
  
  %%
  
  int yyerror(string s)
  {
    extern int yylineno;  // defined and maintained in lex.c
    extern char *yytext;  // defined and maintained in lex.c
  
    cerr &lt;&lt; "ERROR: " &lt;&lt; s &lt;&lt; " at symbol \"" &lt;&lt; yytext;
    cerr &lt;&lt; "\" on line " &lt;&lt; yylineno &lt;&lt; endl;
    exit(1);
  }
  
  int yyerror(char *s)
  {
    return yyerror(string(s));
  }
  </code></pre>
  
  <p>here is the error message:</p>
  
  <pre><code>$ make
  bison -d -v calc.y
  cp calc.tab.c bison.c
  cmp -s calc.tab.h tok.h || cp calc.tab.h tok.h
  g++ -g -Wall -ansi -pedantic -c bison.c -o bison.o
  calc.tab.c: In function ‘int yyparse()’:
  calc.tab.c:1381: warning: deprecated conversion from string constant to ‘char*’
  calc.tab.c:1524: warning: deprecated conversion from string constant to ‘char*’
  flex calc.lex
  cp lex.yy.c lex.c
  g++ -g -Wall -ansi -pedantic -c lex.c -o lex.o
  calc.lex:8: error: redefinition of ‘int yylineno’
  lex.yy.c:349: error: ‘int yylineno’ previously defined here
  calc.lex: In function ‘int yylex()’:
  calc.lex:23: warning: deprecated conversion from string constant to ‘char*’
  lex.yy.c: At global scope:
  lex.yy.c:1105: warning: ‘void yyunput(int, char*)’ defined but not used
  make: *** [lex.o] Error 1
  </code></pre>