[antlr-interest] why <if(y==2 )> in Stringtemplate does not work?
Terence Parr
parrt at cs.usfca.edu
Fri Mar 6 15:56:11 PST 2009
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
More information about the antlr-interest
mailing list