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

Nilo Roberto C Paim nilopaim at gmail.com
Thu Sep 27 06:48:07 PDT 2012


Hi, Juanca.

 

On the lexer part, 

 

ELSE: ‘ELSE;

IF: ‘IF’;

And so on... exactly as on the input.

 

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 10:43
Para: Nilo Roberto C Paim
Cc: Kevin Cummings; antlr ANTLR
Assunto: Re: [antlr-interest] RES: RES: Dangling ELSE on Cobol

 

How is 'ELSE' defined?

 

-- Juanca

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

Hi, Kevin.

You were right about the changes. Thanks for your interest.

But with the following syntax:

ifCmd
  :
  IF boolExpr command+
  (
    ELSE command+
  )?
  ;

When I input something like:

   IF (a > b)
      Close z
      Call x
   ELSE
      Open y.

The parser shows me:

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...).

Any hints?

TIA.
Nilo - Brazil

-----Mensagem original-----
De: Kevin Cummings [mailto:cummings at kjchome.homeip.net]
Enviada em: quarta-feira, 26 de setembro de 2012 23:38

Para: Nilo Roberto C Paim

Cc: Juancarlo Añez; antlr ANTLR
Assunto: Re: [antlr-interest] RES: Dangling ELSE on Cobol


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


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address





 

-- 
Juancarlo Añez



More information about the antlr-interest mailing list