title: Convert a form of BNF grammar to g4 grammar
body: <p>I'm trying to covert this BNF grammar for validating boolean expression which is currently being used in Swift. Now want to implement similar parser in Java. I came across Antlr4 lib and want to use it to generate parser for the same grammar. I'm not very familiar with antlr4. Can someone please provide me some guidance? This is what I have so far.</p>
  
  <pre><code>Expr                ::= &lt;ConcatenationExpr&gt;;
  NonInfixExpr        ::= &lt;BracketExpr&gt;
                        | &lt;Function&gt;
                        | &lt;Literal&gt;
                        | &lt;Accessor&gt;;
  BracketExpr         ::= '(' &lt;Expr&gt; ')';
  Accessor            ::= ('$' &lt;AccessorComponent&gt; | &lt;AccessorComponent&gt;) ('.' &lt;AccessorComponent&gt; )*;
  AccessorComponent   ::= 'Identifier' ':' 'Identifier' | 'Identifier';
  Function            ::= 'Identifier' '(' ')' | ('Identifier' '(' &lt;Expr&gt; (',' &lt;Expr&gt;)* ')');
  Literal             ::= 'True'
                       | 'False'
                       | 'Null'
                       | 'Number'
                       | 'Text';
  ConcatenationExpr   ::= &lt;AndExpr&gt;
                       | &lt;ConcatenationExpr&gt; '&amp;' &lt;AndExpr&gt;;
  AndExpr             ::= &lt;OrExpr&gt;
                       | &lt;AndExpr&gt; '&amp;&amp;' &lt;OrExpr&gt;;
  OrExpr              ::= &lt;EqualityExpr&gt;
                       | &lt;OrExpr&gt; '||' &lt;EqualityExpr&gt;;
  EqualityExpr        ::= &lt;ComparisonExpr&gt;
                       | &lt;EqualityExpr&gt; ('==' | '=' | '!=' | '&lt;&gt;') &lt;ComparisonExpr&gt;;
  ComparisonExpr      ::= &lt;AddExpr&gt;
                       | &lt;AddExpr&gt; ('&lt;' | '&lt;=' | '&gt;' | '&gt;=') &lt;AddExpr&gt;;
  AddExpr             ::= &lt;ExponentialExpr&gt;
                       | &lt;AddExpr&gt; ('+' | '-') &lt;ExponentialExpr&gt;;
  ExponentialExpr     ::= &lt;MultExpr&gt;
                       | &lt;ExponentialExpr&gt; '^' &lt;MultExpr&gt;;
  MultExpr            ::= &lt;NonInfixExpr&gt;
                       | &lt;MultExpr&gt; ('*' | '/') &lt;NonInfixExpr&gt;;
  </code></pre>
  
  <p>I tried to convert to g4 and this is what it looks like.</p>
  
  <pre><code>grammar VALIDATE;
  
  Expr
      : ConcatenationExpr ';'
      ;
  
  NonInfixExpr
      : BracketExpr 
      | Function 
      | Literal 
      | Accessor
      ;
  
  BracketExpr 
      : '(' Expr ')'
      ;
  
  Accessor
      : ('$' AccessorComponent | AccessorComponent ) ('.' AccessorComponent )*
      ;
  
  AccessorComponent
      : 'Identifier' ':' 'Identifier' | 'Identifier'
      ;
  
  Function
      : 'Identifier' '(' ')' | ('Identifier' '(' Expr (',' Expr)* ')')
      ;
  
  Literal
      : 'True' | 'False' | 'Null' | 'Number' | 'Text'
      ;
  
  ConcatenationExpr
      : AndExpr 
      | ConcatenationExpr '&amp;&amp;' AndExpr
      ;
  
  AndExpr
      : OrExpr | AndExpr '&amp;&amp;' OrExpr
      ;
  
  OrExpr
      : EqualityExpr | OrExpr '||' EqualityExpr
      ;
  
  EqualityExpr
      : ComparisonExpr | EqualityExpr ('==' | '=' | '!=' | '&lt;&gt;') ComparisonExpr
      ;
  
  ComparisonExpr
      : AddExpr | AddExpr ('&lt;' | '&lt;=' | '&gt;' | '&gt;=') AddExpr
      ;
  
  AddExpr
      : ExponentialExpr | AddExpr ('+' | '-') ExponentialExpr
      ;
  
  ExponentialExpr
      : MultExpr | ExponentialExpr '^' MultExpr
      ;
  
  MultExpr
      : NonInfixExpr | MultExpr ('*' | '/') NonInfixExpr
      ;
  </code></pre>
  
  <p>I'm stuck at antlr4 VALIDATE.g4 step. I'm not sure I did the conversion right.</p>
  
  <pre><code>error(119): VALIDATE.g4::: The following sets of rules are mutually left-recursive [MultExpr] and [ExponentialExpr] and [AddExpr] and [EqualityExpr] and [OrExpr] and [AndExpr] and [ConcatenationExpr]
  error(99): VALIDATE.g4::: grammar VALIDATE has no rules
  </code></pre>