[antlr-interest] [C Target] How to skip a whole sub-tree (not just a token)

Jim Idle jimi at temporal-wave.com
Sat Nov 14 22:38:55 PST 2009

I think I have said more than a few times now that this will be fixed up for 3.2.1 - I thought I had fixed it for 3.2. Sorry it is really useless - sigh. For what it's worth, I think that you are going about this incorrectly, and that's why you are having problems beyond the '.' bug - probably your code is really useless - no offence though right?




From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mohamed Yousef
Sent: Saturday, November 14, 2009 7:50 PM
To: Claude Moulin
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] [C Target] How to skip a whole sub-tree (not just a token)


Thanks Claude,
if i understand your code correctly , it looks that the "." eats the whole "Then" tree ( tree executed when condition is true ) so u mark berfore it ( then case) and after it (else cases) , is that true ?

well , if this is true and this is the standard implementation , then this is a bug in the C Target
in the C Target the macro MATCHANYT() represents the "." , unfortunetly it matches only a signle token , not a sub-tree , making it really usless

however , it's really easy to modify this in the c target , just confirm me this is the standard behavior
( a note i thinked of now , can anybody check to see if the java terget saves the indexes of nodes , and i mean indexes of them as they appear in the flattened parse tree , coz this is another cause of problems in C Target )

Mohammed Yousef

2009/11/14 Claude Moulin <claude.moulin at hds.utc.fr>

Here is the solution I use in Java. The principle is also valid for loops.

I suppose the CommonTreeNodeStream methods () I use have equivalent functions in C

push, pop, and mark




  int mark_before_true = 0;

  int mark_before_false = 0;

}     :

 ^(IF e = expbool {mark_before_true = input.mark();} . ({mark_before_false = input.mark();} else_list = .)? ) 


         if ($e.b) {






         if (else_liste != null) {







expbool is a rule returning a Boolean in its b field.

list_instructions is a rule parsing a tree containing instructions in a list.

input.mark()  gives the index of the following node and in this case it is the index I want to store.

And in the @members section I add two methods in order to simplify the code:

  public void push(int index) {



  public void pop() {




I hope it is usefull.


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


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

More information about the antlr-interest mailing list