Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>$1, $2, and so on refer to the terms on the right-hand side of a grammar rule. For example in</p> <pre><code>stat: expr { printf("%d\n",$1); } | LETTER '=' expr { regs[$1] = $3; } </code></pre> <p>LETTER '=' expr is one of the rules and in the following parentheses $1 refers to LETTER. <code>regs[$1] = $3;</code> will be made into a C statement but in order to do that, yacc needs to know what type $1 has. If you add</p> <pre><code>%type &lt;a&gt; LETTER </code></pre> <p>after the first %type declaration (or simply list <code>LETTER</code> after expr) the first error will be taken care of. Same goes for <code>DIGIT</code> and <code>base</code>. Note that there is nothing that refers to the value of stat (naturally) so there is no need for a %type declaration for stat. Thus in</p> <pre><code>calc.yacc:105.17-18: $1 of `number' has no declared type calc.yacc:106.20-21: $1 of `number' has no declared type calc.yacc:110.29-30: $2 of `number' has no declared type </code></pre> <p>the first line implies that <code>DIGIT</code> has an unknown type, the second line refers to the same problem with <code>number</code>; finally the last line reminds you to declare the type for <code>base</code>. Here is the yacc code it is referring to:</p> <pre><code> number: DIGIT { $$ = $1; base = ($1==0) ? 8 : 10; } | number DIGIT { $$ = base * $1 + $2; } ; </code></pre> <p>Finally, without getting into too many details, the statement</p> <pre><code>regs[$1]=$3; </code></pre> <p>will be translated by yacc into something close to:</p> <pre><code>regs[YS[1].&lt;type of LETTER&gt;]=YS[3].&lt;type of expr&gt;; </code></pre> <p>where YS is a 'magic array' (actually yacc's stack); YS has the type of the declared %union. Thus you can see that to make this into legal C, yacc needs to know which member of the %union <code>&lt;type of LETTER&gt;</code> refers to. This is what the <code>%type</code> declaration is for.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload