title: $1 of [...] has no declared type
body: <p>I am unfamiliar with Yacc and trying to get an example I found <a href="http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.genprogc%2Fdoc%2Fgenprogc%2Fie_prog_4lex_yacc.htm" rel="nofollow noreferrer">here</a> to work. When I try to compile with <code>yacc -d calc.yacc</code>, I get the following errors.</p>
  <blockquote>
  <p>calc.yacc:42.17-18: $1 of `stat' has no declared type</p>
  <p>calc.yacc:96.22-23: $1 of `expr' has no declared type</p>
  <p>calc.yacc:105.17-18: $1 of `number' has no declared type</p>
  <p>calc.yacc:106.20-21: $1 of `number' has no declared type</p>
  <p>calc.yacc:110.29-30: $2 of `number' has no declared type</p>
  </blockquote>
  <p>I tried googling and from what I can tell, the solution has to do with %type, but I'm not sure what to add.</p>
  <p>The code is below:</p>
  <pre><code>%{
      #include &lt;stdio.h&gt;
  
      int regs[26];
      int base;
  
      %}
  
      %start list
  
      %union { int a; }
  
      %type &lt;a&gt; expr number
  
      %token DIGIT LETTER
  
      %left '|'
      %left '&amp;'
      %left '+' '-'
      %left '*' '/' '%'
      %left UMINUS  /*supplies precedence for unary minus */
  
      %%                   /* beginning of rules section */
  
      list:                       /*empty */
               |
              list stat '\n'
               |
              list error '\n'
               {
                 yyerrok;
               }
               ;
  
      stat:    expr
               {
                 printf(&quot;%d\n&quot;,$1);
               }
               |
               LETTER '=' expr
               {
                 regs[$1] = $3;
               }
  
               ;
  
      expr:    '(' expr ')'
               {
                 $$ = $2;
               }
               |
               expr '*' expr
               {
  
                 $$ = $1 * $3;
               }
               |
               expr '/' expr
               {
                 $$ = $1 / $3;
               }
               |
               expr '%' expr
               {
                 $$ = $1 % $3;
               }
               |
               expr '+' expr
               {
                 $$ = $1 + $3;
               }
               |
               expr '-' expr
               {
                 $$ = $1 - $3;
               }
               |
               expr '&amp;' expr
               {
                 $$ = $1 &amp; $3;
               }
               |
               expr '|' expr
               {
                 $$ = $1 | $3;
               }
               |
  
              '-' expr %prec UMINUS
               {
                 $$ = -$2;
               }
               |
               LETTER
               {
                 $$ = regs[$1];
               }
  
               |
               number
               ;
  
      number:  DIGIT
               {
                 $$ = $1;
                 base = ($1==0) ? 8 : 10;
               }       |
               number DIGIT
               {
                 $$ = base * $1 + $2;
               }
               ;
  
      %%
      main()
      {
       return(yyparse());
      }
  
      yyerror(s)
      char *s;
      {
        fprintf(stderr, &quot;%s\n&quot;,s);
      }
  
      yywrap()
      {
        return(1);
      }
  </code></pre>