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

Nilo Roberto C Paim nilopaim at gmail.com
Thu Sep 27 08:24:38 PDT 2012


Juanca,

 

It doesn’t make the trick. Provided the same input, it shows:

 

line 207:49 no viable alternative at input '.'

 

Note that “command” have optionally a “.” terminating it. It’s exactly that “.” That it is not recognized.

 

I attach my grammar and my input file, because I think that maybe some another rules need to be changed either. I guess this can make easier to find the problems.

 

Under Antlr V3, your initial hint worked as expected. The current problem occurs under Antlr V4, that is apparently more, much more adequate to what I’m trying to do.

 

Thanks a lot for your interest. I have not enough words to thank you.

 

Regards,

Nilo - Brazil

 

De: juancarlo.anez at gmail.com [mailto:juancarlo.anez at gmail.com] Em nome de Juancarlo Añez
Enviada em: quinta-feira, 27 de setembro de 2012 11:59
Para: Nilo Roberto C Paim
Cc: antlr ANTLR
Assunto: Re: [antlr-interest] RES: RES: Dangling ELSE on Cobol

 

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: SC.g4
Type: application/octet-stream
Size: 7368 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20120927/43f3147c/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sga.cob
Type: application/octet-stream
Size: 24632 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20120927/43f3147c/attachment-0001.obj 


More information about the antlr-interest mailing list