[antlr-interest] RES: RES: Dangling ELSE on Cobol

Juancarlo Añez apalala at gmail.com
Thu Sep 27 07:59:14 PDT 2012


Nilo,

On Thu, Sep 27, 2012 at 8:14 AM, Nilo Roberto C Paim <nilopaim at gmail.com>wrote:

> line 204:11 no viable alternative at input 'call x'
> line 204:11 extraneous input 'ELSE' expecting {'.', 'call', 'close',
> 'open'}
>
> If I remove the "else" and the following line from the input, everything
> parses without errors (but obviously, that´s not what I need...).
>

I'm not using ANTLR4 yet, but the -trace option in ANTLR3 helped me through
the hardest parts of the large grammar I'e been working on. It lets you see
what the parser is trying to do, and on which rule and token it is failing.

Another hint is that there have been parts of the grammar that I was not
able to solve with +/* repetitions, but only with recursion, all of them
having lists with no terminator token.

command: if|...;

if
    :
    IF expre if_commands
    ;

if_commands
    :
    ELSE command+
    | command if_commands
   ;

Using recursion takes away the greedyness of + (I don't know if
greedy=false can be used in rules; if it can, it may be an option).

-- 
Juanca


More information about the antlr-interest mailing list