[antlr-interest] if-then-else rule design question

Gavin Lambert antlr at mirality.co.nz
Mon Jun 16 05:35:05 PDT 2008


At 21:07 16/06/2008, Fridi wrote:
 >How can I create a tree parser that conditionally runs into
 >specific leaves of the tree only? I have studied the great
 >ANTLR book, but I did not find a similar example right now.

I haven't actually used this myself, but from what I remember of a 
discussion a while back, something like this ought to work:

ifelse
   : ^(IFELSE condition
     ( { $condition.value }? => statement . { do($statement); }
     | . statement { do($statement); }
     )
   )
   ;

(You can adapt the idea for other tree structures.  The main point 
is the use of '.' to indicate "don't care".)



More information about the antlr-interest mailing list