[antlr-interest] why <if(y==2 )> in Stringtemplate does not work?

YINGAnnie yimm8369 at hotmail.com
Sun Mar 8 15:27:26 PDT 2009



But there's some errors as the red color shows: 

 

additiveExpression
    
    :   ^(ADDITIVE_EXPRESSION multiplicativeExpression+)             (106): reference to undefined rule: multiplicativeExpression                     
    ;
   

multiplicativeExpression
  
    :^(DIV unaryExpression+)          (106): reference to undefined rule: unaryExpression
    |^(MOD unaryExpression+)         (106): reference to undefined rule: unaryExpression
    |^(STAR u1=unaryExpression u2=unaryExpression)  ->{if($u2.text==2)}? assgin(x={$u1.text},y={$u2.text},z={"<<"})
    ;                                               (100): syntax error: antlr: expecting REWRITE, found ';'


unaryExpression
    : ^(UNARY_EXPRESSION unaryOp? postfixExpression)      (100): syntax error: antlr: expecting SEMI, found ')'
    ;     

 

If I delete  ->{if($u2.text==2)}? assgin(x={$u1.text},y={$u2.text},z={"<<"}) , all the errors are gone. I am not sure what is the problem.

 

Thanks.

 

Ann


    

 

 

 

 

 

 
> CC: antlr-interest at antlr.org
> From: parrt at cs.usfca.edu
> To: yimm8369 at hotmail.com
> Subject: Re: [antlr-interest] why <if(y==2 )> in Stringtemplate does not work?
> Date: Fri, 6 Mar 2009 15:56:11 -0800
> 
> 
> On Mar 6, 2009, at 3:46 PM, YingAnnie wrote:
> 
> >
> > So, what I expect is that when the code is "a=b*c", and c==2, then 
> > change * to /.
> >
> > multiplicativeExpression
> > :^(STAR u1=unaryExpression u2=unaryExpression) -> 
> > assgin(x={$u1.text},y={$u2.text},z={"/"})
> > ;
> >
> > group T;
> > assgin(x,y,z)::= <<
> > <if(y==2)><x><z><y><else><"error"><endif>
> >
> > If I can not test the value of attributes within ST,Then it has to 
> > be done in the tree grammar. can I do something like this:
> >
> > multiplicativeExpression
> > :^(STAR u1=unaryExpression u2='2') -> 
> > assgin(x={$u1.text},y={$u2.text},z={"/"})
> > ;
> 
> Almost. you need predicated -> alternatives
> 
> -> {..}? template one
> -> {...}? template two
> -> else template
> 
> T

_________________________________________________________________
梦幻K图,百变造型,让你的照片与众不同,快来MClub试试吧!
http://club.msn.cn/?form=3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090309/e7bf13a0/attachment.html 


More information about the antlr-interest mailing list