[antlr-interest] Lazy Else,

Craig Main craig at palantir.co.za
Mon Jun 20 07:40:29 PDT 2005


Hi,

 

Given the following (working) if / else statement.

(The console will output True if the condition is met, False otherwise)

 

How can I get the parser to jump over the else if the conditional expression
is true, and only evaluate the statement_set if the condition is true.

Is that possible in the context of the parser, or not really.

 

Maybe I can specify a dummy statement_set if the condition is met, and the
real attributed statement_set if the condition is true?

That way it will get parsed, but the attributes will do nothing.

 

Regards

Craig

 

condition

[Context context]       {

                           object result = null;

                        }

                        : TOK_IF LPAREN! result =
conditional_expression[context] RPAREN! 

                          {

                             Console.WriteLine(result.ToString());

                          }

                          statement_set[context]

                                  (// CONFLICT: the old "dangling-else"
problem...

                                       //           ANTLR generates proper
code matching

                                       //              as soon as possible.
Hush warning.

                                       options {

                                             warnWhenFollowAmbig = false;

                                       }

                                   : (STATEMENT_SEP)? TOK_ELSE!
statement_set[context]

                                  )?

                        ;

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050620/a0647a41/attachment.html


More information about the antlr-interest mailing list