title: Dealing with overloaded symbols in ambiguous grammars in ANTLR4
body: <p>I am trying to write a parser for a dialect of <em>Answer Set Programming (ASP)</em> which, in terms of grammar, looks like <em>Prolog</em> with some extensions. 
  One extension, for instance is <em>expansion</em>, meaning that <code>fact(1..3).</code> for instance is expanded in <code>fact(1). fact(2). fact(3).</code>. Notice that the language understands <code>INT</code> and <code>FLOAT</code> numbers and uses <code>.</code> also as a terminator.</p>
  
  <p>In some cases the parser fails to distinguish between integers, floats, extensions and separators because I reckon the language is clearly ambiguous. In that cases, I have to explicitly separate tokens with white spaces. Any <em>Prolog</em> or <em>ASP</em> parser, however, correctly deals with such productions. I read that <em>ANTLR4</em> can disambiguate problematic productions autonomously, but probably it needs some help but I don't know how to do! ;-) I read something like <a href="https://stackoverflow.com/questions/18005972/antlr4-grammar-ambiguity">here</a> and <a href="https://stackoverflow.com/questions/21579350/antlr4-lexer-not-resolving-ambiguity-in-grammar-order">here</a>, but apparently they did not help me.</p>
  
  <p>Could somebody please tell me what to do to overcome this ambiguity?
  Please notice that I cannot change the language because it is quite standard.
  In order to simplify the experts' work, I created a minimal working example that follows.</p>
  
  <pre><code>grammar Test;
  
  program: 
    statement* ;
  
  statement: // DOT is the statement terminator
    range DOT |
    intNum DOT |
    floatNum DOT ;
  
  intNum: // not needed, but helps in TestRig
    INT;
  
  floatNum: // not needed, but helps in TestRig
    FLOAT;
  
  range: // defines an expansion
    INT DOTS INT ;
  
  DOTS: '..';
  DOT: '.';
  
  FLOAT: DIGIT+ '.' DIGIT* | '.' DIGIT+ ;
  INT: DIGIT+ ;
  
  WS: [ \t\r\n]+ -&gt; skip ;
  
  fragment NONZERO     : [1-9] ;
  fragment DIGIT       : [0] | NONZERO ;
  </code></pre>
  
  <p>I use the following input:</p>
  
  <pre><code>1 .
  1. .
  1.5 .
  .5 .
  1 .. 5 .
  
  1.
  1..
  1.5.
  .5.
  1..5.
  </code></pre>
  
  <p>And I get the following errors which instead are parsed corrected by other tools:</p>
  
  <pre><code>line 8:0 extraneous input '1.' expecting '.'
  line 11:2 extraneous input '.5' expecting '.'
  </code></pre>
  
  <p>Many thanks in advance! </p>