title: Javacc - Eliminating choice conflict by using left factoring instead of lookahead
body: <p>I am writing a JAVACC program for a simple language and I am running into 1 conflict which is fixable by using a LOOKAHEAD(2).Would I be able to overcome this issue by left-factoring the code rather than using a look-ahead and if not, why?</p>
  
  <p>GRAMMAR</p>
  
  <pre><code>void expression() : {}
  {
      simple_expression() (addition_or_substraction() | {})
  }
  
  void simple_expression() : {}
  {
      &lt;NUMBER&gt;
      | &lt;LBRAC&gt; expression() &lt;RBRAC&gt; 
  }
  
  void condition() : {}
  {
       simple_condition() (compare_condition() | {})
  } 
  
  void prime_condition() : {}
  {
      expression_comparison()
      |&lt;NOT_OPERATOR&gt; condition()
      | LOOKAHEAD(2) &lt;LBRAC&gt; condition() &lt;RBRAC&gt; // Choice conflict for "("
  }
  
  void expression_comparison() : {}
  {
      expression()
      (   
           &lt;EQUAL&gt; expression()
           &lt;LESS_THAN&gt; expression()
           &lt;GREATER_THAN&gt; expression()
      )
  }
  
  void compare_condition() : {}
  {
      &lt;AND&gt; condition() | &lt;OR&gt; condition()
  }
  </code></pre>