title: Antlr4: The following sets of rules are mutually left-recursive
body: <p>I am trying to describle simple grammar with <code>AND</code> and <code>OR</code>, but fail with the following error</p>
  
  <p>The following sets of rules are mutually left-recursive</p>
  
  <p>The grammar is following:</p>
  
  <pre><code>expr:
      NAME |
      and |
      or;
  
  and:
      expr AND expr;
  
  or:
      expr OR expr;
  
  NAME : 'A' .. 'B' + ;
  OR: 'OR' | '|';
  AND: 'AND' | '&amp;';
  </code></pre>
  
  <p>Simultaneously, the following grammar</p>
  
  <pre><code>expr:
      NAME |
      expr AND expr |
      expr OR expr;
  
  NAME : 'A' .. 'B' + ;
  OR: 'OR' | '|';
  AND: 'AND' | '&amp;';
  </code></pre>
  
  <p>does compile.</p>
  
  <p>Why?</p>