[antlr-interest] RES: Dangling ELSE on Cobol

Kevin Cummings cummings at kjchome.homeip.net
Wed Sep 26 19:38:13 PDT 2012


I don't think you need it at all.  Just remove the => and everything before it.

--
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232
(http://www.linuxcounter.net/)


On Sep 26, 2012, at 12:56, "Nilo Roberto C Paim" <nilopaim at gmail.com> wrote:

> Hi, all.
> 
> 
> 
> Does anyone knows how is this supposed to be in Antlr V4? The “=>” gave me syntax error…
> 
> 
> 
> No, I’ve not buy the book yet, but I intend to do soon…
> 
> 
> 
> TIA,
> 
> Nilo - Brazil
> 
> 
> 
> De: juancarlo.anez at gmail.com [mailto:juancarlo.anez at gmail.com] Em nome de Juancarlo Añez
> Enviada em: sexta-feira, 21 de setembro de 2012 14:11
> Para: Nilo Roberto C Paim
> Cc: antlr ANTLR
> Assunto: Re: [antlr-interest] Dangling ELSE on Cobol
> 
> 
> 
> Nilo,
> 
> 
> 
> It's a lot of lookahead, but it solves your problem:
> 
> 
> 
> command :
> 
>    ifCmd
> 
>    | 'INIT'
> 
>    | 'MOVE'
> 
>    ;
> 
> 
> 
> ifCmd:
> 
>    'IF' 'EXPRE' ((command)=>command)+ 
> 
>    (
> 
>        ('ELSE')=> 'ELSE' ((command)=>command)+ 
> 
>    |
> 
>        ()
> 
>    )
> 
>    ;
> 
> 
> 
> The ambiguity warning were saying that ANTLR didn't know to which nesting level to add the next "command". The lookaheads tell it to be greedy and match them against the closest IF or ELSE.
> 
> 
> 
> Cheers,
> 
> 
> 
> -- Juanca
> 
> 
> 
> On Thu, Sep 20, 2012 at 2:50 PM, Nilo Roberto C Paim <nilopaim at gmail.com> wrote:
> 
> Hi, folks.
> 
> I'm trying to parse Cobol sources using Antlr 3.4 (ANTLR Parser Generator
> 3.4 Jul 19, 2011 11:35:12. actually).
> 
> I'm stuck with the old dangling ELSE problem. Here the relevant piece of
> code of my grammar that shows me the problem:
> 
> 
>        command :
>                ifCmd
>                |       initializeCmd
>                |       moveCmd
>                |       openCmd
>                ;
> 
>        ifCmd:
>                        IF expr command+ ( (ELSE)=> ELSE command+)?
>                ;
> 
> 
> I cannot put a terminator on the commands 'cause commands in Cobol may end
> or with a '.' or with the following command. This is true including the
> ifCmd itself.
> 
> The code above shows me the following messages:
> 
> warning(200): /SuperCobol/src/SC.g:229:13:
> Decision can match input such as "IF" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> warning(200): /SuperCobol/src/SC.g:229:13:
> Decision can match input such as "MOVE" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> warning(200): /SuperCobol/src/SC.g:229:13:
> Decision can match input such as "OPEN" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> warning(200): /SuperCobol/src/SC.g:229:13:
> Decision can match input such as "INITIALIZE" using multiple alternatives:
> 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> warning(200): /SuperCobol/src/SC.g:229:38:
> Decision can match input such as "IF" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> warning(200): /SuperCobol/src/SC.g:229:38:
> Decision can match input such as "MOVE" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> warning(200): /SuperCobol/src/SC.g:229:38:
> Decision can match input such as "OPEN" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> warning(200): /SuperCobol/src/SC.g:229:38:
> Decision can match input such as "INITIALIZE" using multiple alternatives:
> 1, 2
> As a result, alternative(s) 2 were disabled for that input
> |---> IF expr command+ ( (ELSE)=> ELSE command+)?
> 
> 
> 8 warnings
> 
> Please, any hints?
> 
> Thanks in advance,
> Nilo
> Brazil
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
> 
> 
> 
> 
> 
> 
> -- 
> Juancarlo Añez
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list