title: What to use in ANTLR4 to resolve ambiguities (instead of syntactic predicates)?
body: <p>In ANTLR v3, syntactic predicates could be used to solve e.g., the dangling else problem. ANTLR4 seems to accept grammars with similar ambiguities, but during parsing it reports these ambiguities (e.g., "line 2:29 reportAmbiguity d=0 (e): ambigAlts={1, 2}, input=..."). It produces a parse tree, despite these ambiguities (by chosing the first alternative, according to the documentation). But what can I do, if I want it to chose some other alternative? In other words, how can I explicitly resolve ambiguities?</p>
  
  <p>For example, the dangling else problem:</p>
  
  <pre><code>prog
      :   e EOF
      ;
  
  e
      :   'if' e 'then' e ('else' e)?
      |   INT
      ;
  </code></pre>
  
  <p>With this grammar, from the input "if 1 then if 2 then 3 else 4", it builds this parse tree: (prog (e if (e 1) then (e if (e 2) then (e 3) else (e 4))) ).</p>
  
  <p>What can I do, if for some reason, I want the other tree: (prog (e if (e 1) then (e if (e 2) then (e 3)) else (e 4)) ) ?</p>
  
  <p>Edit: for a more complex example, see <a href="https://stackoverflow.com/questions/21441651/what-to-use-in-antlr4-to-resolve-ambiguities-in-more-complex-cases-instead-of-s">What to use in ANTLR4 to resolve ambiguities in more complex cases (instead of syntactic predicates)?</a>)</p>