[antlr-interest] RES: Dangling ELSE on Cobol
Nilo Roberto C Paim
nilopaim at gmail.com
Fri Sep 21 11:37:05 PDT 2012
Juanca,
Thanks a lot! Works like a charm!
Gracias por su interés.
Saludos from Brazil,
Nilo
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
More information about the antlr-interest
mailing list