[antlr-interest] Trouble with statement block,

Craig Main craig at palantir.co.za
Tue Jun 21 03:30:46 PDT 2005


Hi,

 

I am struggling to get the statement block to work with extra separators.

I have to be very careful where I place the statement separators in the
input text.

I need to try and make this more lenient.

 

The following does not work.

If (cond) {

} else {

            A = 10; <separator not allowed here>

} ; <separator required here>

 

What is a good way to make this more lenient in terms of the input string? I
am struggling to get it correct without invalid grammar rules.

 

rules                   : (statement STATEMENT_SEP)* EOF

                        ;

 

statement_set           : statement

                        | statement_block

                        ;

 

statement               : assignment_statement

                        | constant_declaration

                        | condition

                        ;

 

statement_block         : LCURL (statement)? (STATEMENT_SEP statement)*
RCURL

 

condition               

                        : TOK_IF LPAREN! result = conditional_expression
RPAREN! 

                          statement_set

                                  (// 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

                                  )?

                        ;

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


More information about the antlr-interest mailing list