Hey 轶凡,

You might like to match the elseif_part and else_part with an any.
Then continue the walk on the correct branch.

   ifs: ^(IF test a=. b=.) ;

Have a look at a previous post that does something similar.
  http://www.antlr.org/pipermail/antlr-interest/2011-April/041307.html

Regards
Gary

On Fri, Sep 23, 2011 at 12:47 AM, 轶凡 <yifan....@taobao.com> wrote:
> Hi, gurus, I defined a tree grammar which contains if statements, it looks 
> like below:
>
> ifs: ^(IF test elseif_part else_part) ;
>
> In normal, this rule will generate source code as below:
>
> test(); //it will return a boolean value
> ....
> elseif_part();
> ....
> else_part();
>
> As you see, if the rule 'test' is ok in some conditions, there's no need to 
> evaluate rule 'elseif_part' and 'else_part'.
> What I need is conditional tree node expansion. Ideally generated code in my 
> mind:
>
> if (test())
> {
>  //skip elseif_part and else_part
> }else{
>  elseif_part();
>  if (some condition was satisfied){
>    //skip else_part;
>  }else{
>    else_part();
>  }
> }
>
> Hope for you help, thanks!
>
>
> This email (including any attachments) is confidential and may be legally 
> privileged. If you received this email in error, please delete it immediately 
> and do not copy it or use it for any purpose or disclose its contents to any 
> other person. Thank you.
>
> 本电邮(包括任何附件)可能含有机密资料并受法律保护。如您不是正确的收件人,请您立即删除本邮件。请不要将本电邮进行复制并用作任何其他用途、或透露本邮件之内容。谢谢。
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: 
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>

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

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to