title: How to avoid conflicts when generating IR codes in yacc?
body: <pre><code>%nonassoc NO_ELSE
  %nonassoc ELSE
  
  stmt_conditional
       : IF '(' expr { show_if_begin($3); } ')' stmt_compound { show_if_end(); } %prec NO_ELSE
       | IF '(' expr { show_if_begin($3); } ')' stmt_compound { show_if_else(); }  ELSE stmt_compound { show_if_end(); }
  </code></pre>
  
  <p>Since <code>stmt_compound</code> will generate IRs, <code>show_if_begin()</code> should be in front of <code>stmt_compound</code>. However, this will cause reduce/reduce conflicts in yacc. How to solve this problem?</p>
  
  <p><strong>EDITED</strong></p>
  
  <p>This is what I've tried, but it didn't work.</p>
  
  <pre><code>stmt_conditional
       : stmt_cond_if { show_if_end(); } %prec NO_ELSE
       | stmt_cond_if { show_if_else(); } ELSE stmt_compound { show_if_end(); }
       ;
  
  stmt_cond_if
       : IF '(' expr { show_if_begin($3); } ')' stmt_compound
  </code></pre>