[antlr-interest] Tree Construction for empty while loop

Suman Karumuri mansuk at gmail.com
Wed Nov 2 16:12:49 PST 2005


Hi all,

I have am constructing a grammar for a while loop using the following grammar.

stmt :       WHILE^ cond stmt_lst EOL!
stmt_lst : stmt_lst:       BEGIN^ (EOL!)* (stmt)* END!
                                 { ##.setType(STMT_LIST);##.setText("B"); }


This returns a tree of the form (WHILE (<cond>)  (B (stmt1) (stmt2) ... ) ).
This works for the following while loop:

while( a < b) {
//some statements
}

But it fails to construct a tree when there are no statements(i.e. an
empty while loop).

It only constucts (WHILE (<cond>) B). How can i get the tree as
(WHILE (<cond>) (B) ). Also what does ## signify?
TIA.
-Suman


More information about the antlr-interest mailing list