[antlr-interest] Changing Root Nodes in an AST,

Craig Main craig at palantir.co.za
Fri Jul 15 05:38:50 PDT 2005


Hi all,

 

What do I change in my parser to alter

 

THIS:

 

   #( TOK_IF expr ( statement )* ( TOK_ELSE ( statement )* )? ) With this:

 

TO THIS:

 

   #( TOK_IF expr #(BLOCK (statement)* ) ( #(BLOCK (statement)* ) ) )? )

 

 

GIVEN:

 

ifStatement               {log.Debug(null);}

                        : TOK_IF^ LPAREN! conditional RPAREN!
statementSequence

                          (

                             options {

                                 warnWhenFollowAmbig = false;

                             }

                          : TOK_ELSE statementSequence

                          )?

                        ;

 

statementSequence        {log.Debug(null);}

                        : statementBlock

                        | statement

                        ;

 

statementBlock            {log.Debug(null);}

                        : LCURL! (statement (SEMI! statement)*)? RCURL!

                        ;

 

statement                 {log.Debug(null);}

                        : assignmentStatement

                        | constantStatement

                        | ifStatement

                        ;

 

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


More information about the antlr-interest mailing list