title: Use of undeclared identifier 'yylval'
body: <p>I tried to run this program in lex and yacc. I work on a Macbook Pro.</p>
  <p>I don't understand why is not recognised the yylval in lex file;
  does someone know what should I do here?
  I perhaps need to add some includes, or something else? I did find something on the internet like this:</p>
  <p>lex file:</p>
  <pre><code>%% 
  
  August { yylval = 8; return AUGUST; }
  September { yylval = 9; return SEPTEMBER; }
  October { yylval = 10; return OCTOBER; }
  November { yylval = 11; return NOVEMBER; } 
  December  { yylval = 12; return DECEMBER; }
  20[0-9][0-9]        { yylval = atoi(yytext); return YEAR; }
  .        return yytext[0];
  %%
  </code></pre>
  <p>yacc file:</p>
  <pre><code>%{
    
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  #include &quot;lex.yy.c&quot;
  
  
  int yylex(void);
  int yyerror();
  
  %}
  
  
  %token AUGUST SEPTEMBER OCTOBER NOVEMBER DECEMBER 
  %token YEAR
  
  %%
  
  s: month '#' YEAR
  
  {
      printf(&quot;%d  %d\n&quot;,$1,$3);
      printf(&quot;DATE IS OK\n&quot;);
  }
  
  month  :  AUGUST {$$ = $1;}
        |  SEPTEMBER {$$ = $1;}
        |  OCTOBER {$$ = $1;}
        |  NOVEMBER {$$ = $1;}
        |  DECEMBER{$$ = $1;}
  %%
  
  
  
  int main(){
      return yyparse();
  }
  
  int yyerror(){
      printf(&quot;Error in date\n&quot;);
      return 0;
  }
  </code></pre>
  <p>when i run this</p>
  <pre><code>lex file.l 
  yacc file.y
  gcc -o file y.tab.c -ll
  </code></pre>
  <p>this the error i get!:</p>
  <pre><code>In file included from test.y:8:
  test.l:3:3: error: use of undeclared identifier 'yylval'
  { yylval = 8; return AUGUST; }
    ^
  test.l:4:3: error: use of undeclared identifier 'yylval'
  { yylval = 9; return SEPTEMBER; }
    ^
  test.l:5:3: error: use of undeclared identifier 'yylval'
  { yylval = 10; return OCTOBER; }
    ^
  test.l:6:3: error: use of undeclared identifier 'yylval'
  { yylval = 11; return NOVEMBER; } 
    ^
  test.l:7:3: error: use of undeclared identifier 'yylval'
  { yylval = 12; return DECEMBER; }
    ^
  test.l:8:3: error: use of undeclared identifier 'yylval'
  { yylval = atoi(yytext); return YEAR; }
    ^
  6 errors generated.
  </code></pre>