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

YINGAnnie yimm8369 at hotmail.com
Sun Mar 8 15:41:56 PDT 2009



 like this?

 

multiplicativeExpression
  
    :^(DIV unaryExpression+)
    |^(MOD unaryExpression+)  
    |^(STAR u1=unaryExpression u2=unaryExpression)  ->{$u2.text==2}? assgin(x={$u1.text},y={$u2.text},z={"<<"})
    ;

 

 

The errors are still there.

 

 

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: Sun, 8 Mar 2009 15:36:01 -0700
> 
> remove if from predicate. it's an expression.
> ter
> On Mar 8, 2009, at 3:27 PM, YINGAnnie wrote:
> 
> >
> > 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
> >
> > 把MSN装进手机,更多聊天乐趣等你挖掘! 立刻下载!
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 

_________________________________________________________________
MSN 表情魔法书,改变你的对话时代!
http://im.live.cn/emoticons/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090309/7619a5b0/attachment.html 


More information about the antlr-interest mailing list