[antlr-interest] A question about multiple alternatives

Jose Ventura jose.ventura.roda at gmail.com
Mon Oct 23 03:24:18 PDT 2006


I post my own if command code, I hope help you

Regards,


comando
               : comando_if
               |  comando_perform
               |  comando_call
...

comando_if
	: IF^ condicion
                       parte_then
                       (options {greedy=true;}: ELSE! parte_else)?
                  (options {greedy=true;}: END_IF)? 				;

parte_then
: (THEN!)?
       ( (NEXT^ SENTENCE {## = #( #[SENTENCIAS, "THEN"] ,##);})
          |sentencia_interna
       )
;
	
parte_else
: (NEXT^ SENTENCE {## = #( #[SENTENCIAS, "ELSE"] ,##);})	
| sentencia_interna
;



2006/10/23, Alexandre Porcelli <porcelli at uol.com.br>:
> I´d like to know from you how could I solve this problem....
>
>   I'm developing a Cobol Grammar using v3. The "IF" statement in
> cobol language there isn't block to define scopes, for this there is
> just the "." token to say it has finished.
> For this I created a nestedIfStatement that is the same as If but
> with no ".", but with my approach I got always a message :
>
> "[19:50:39] CobolParser.g:891:3: Decision can match input such as
> "'ELSE'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> [19:50:39] CobolParser.g:892:3: Decision can match input such as
> "'END-IF'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input"
>
>
> Here is a piece of my code:
>
> imperativeStatementList
>        :       imperativeStatement+
>        ;
>
> imperativeStatement
>        :       acceptStatement
>        |       addImperativeStatement
>        |       alterStatement
>        |       callImperativeStatement
>        |       cancelStatement
>        |       closeStatement
>        |       computeImperativeStatement
>        ;
>
> ifStatement
>        :       'IF' generalCondition 'THEN'? (nestedIfStatement |
> imperativeStatementList nestedIfStatement?)
>                ('ELSE' (nestedIfStatement | imperativeStatementList nestedIfStatement?) )?
>                'END-IF'? DOT
>        ;
>
> nestedIfStatement
>        :       'IF' generalCondition 'THEN'? (nestedIfStatement |
> imperativeStatementList nestedIfStatement?)
>                ('ELSE' (nestedIfStatement | imperativeStatementList nestedIfStatement?))?
>                'END-IF'?
>        ;
>
> Does anyone has any sugestion?
>
> Thanks in Advance,
> Alexandre Porcelli
>


More information about the antlr-interest mailing list