title: How to structure yacc code to support optional nonterminals
body: <p>What is the best way to model optional data in yacc? I have the following statement:</p>
  
  <pre><code>StmtBlock           :    '{' VariableDeclList StmtList '}' {  $$ = new StmtBlock($2, $3); }
                      ;
  </code></pre>
  
  <p>Both, VariableDeclList and StmtList are optional (epsilon) so I modeled them as follows:</p>
  
  <pre><code>VariableDeclList    :    VariableDeclList VariableDecl  { ($$=$1)-&gt;Append($2); }
                      |    { $$ = new List&lt;VarDecl*&gt;; }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>StmtList            :    StmtList Stmt { ($$=$1)-&gt;Append($2); }
                      |    { $$ = new List&lt;Stmt*&gt;; }
                      ;
  </code></pre>
  
  <p>The only problem is when I think this causes shift/reduce conflicts. When I try to compile my code my y.ouput file has the following:</p>
  
  <pre><code>State 74 conflicts: 1 shift/reduce
  ...
  state 74
  
     38 StmtBlock: '{' VariableDeclList . StmtList '}'
     39 VariableDeclList: VariableDeclList . VariableDecl
  
      T_Bool        shift, and go to state 2
      T_Int         shift, and go to state 3
      T_Double      shift, and go to state 4
      T_String      shift, and go to state 5
      T_Identifier  shift, and go to state 8
  
      T_Identifier  [reduce using rule 18 (Epsilon)]
      $default      reduce using rule 18 (Epsilon)
  
      VariableDecl  go to state 80
      Variable      go to state 13
      Type          go to state 34
      Epsilon       go to state 81
      StmtList      go to state 82
  ...
  </code></pre>
  
  <p>Is there a more proper way to model this?</p>