Antlr4 left recursive rule contains a left recursive alternative which can be followed by the empty string
<p>So I defined a grammar to parse an C style syntax language:</p>

<pre><code>grammar mygrammar;

program
: (declaration)*
  (statement)*
  EOF
;

declaration
: INT ID '=' expression ';'
;

assignment
: ID '=' expression ';'
;

expression
: expression (op=('*'|'/') expression)*
| expression (op=('+'|'-') expression)*
| relation
| INT
| ID
| '(' expression ')'
;

relation
: expression (op=('&lt;'|'&gt;') expression)*
;

statement
: expression ';'
| ifstatement
| loopstatement
| printstatement
| assignment
;

ifstatement
: IF '(' expression ')' (statement)* FI ';'
;

loopstatement
: LOOP '(' expression ')' (statement)* POOL ';'
;

printstatement
: PRINT '(' expression ')' ';'
;

IF : 'if';
FI : 'fi';
LOOP : 'loop';
POOL : 'pool';
INT : 'int';
PRINT : 'print';
ID : [a-zA-Z][a-zA-Z0-9]*;
INTEGER : [0-9]+;
WS : [ \r\n\t] -&gt; skip;
</code></pre>

<p>And I can parse a simple test as this: </p>

<pre><code>int i = (2+3)*3/2*(3+36);
int j = i;
int k = 2*1+i*3;
if (k &gt; 2)
  k = k + 1;
  i = i / 3;
  j = j / 3;
fi;
loop (i &lt; 10)
  i = i + 1 * (i+k);
  j = (j + 1) * (j-k);
  k = i + j;
  print(k);
pool;
</code></pre>

<p>However, when I want to generate ANTLR Recogonizers in intelliJ, I got this error:</p>

<blockquote>
  <p>sCalc.g4:19:0: left recursive rule expression contains a left recursive alternative which can be followed by the empty string</p>
</blockquote>

<p>I wonder if this is caused by my <code>ID</code> could be an empty string?</p>