[antlr-interest] failed predicate problem

YINGAnnie yimm8369 at hotmail.com
Mon Mar 16 15:28:31 PDT 2009


 

Michael,

 

 

yes, I am trying to re-write a tree.

 

I leave it blank like:

 

callExpression
 : ^(CALL_EXPRESSION memberExpression indexSuffix *propertyReferenceSuffix* argumentSuffix*)
 {$memberExpression.text.equals("Math.abs")}?    ->mathabs(x={$argumentSuffix.text})
                                                                           -> 

;

 

 

But it seems does not work.

 

Could I ask another question:

 

On page 237 of the antlr book, the translation format is like :

 

callExpression
 : ^(CALL_EXPRESSION memberExpression indexSuffix *propertyReferenceSuffix* argumentSuffix*)
 ->{$memberExpression.text.equals("Math.abs")}?   mathabs(x={$argumentSuffix.text})

;
 

 

using-> before {  } ? 

 

But when I do the same, the error occur, what I can do is put the-> after { }?.

 

I dont know why?

 

 

Thank you very much.

 

Annie

 

 

 

 

 
> Date: Mon, 16 Mar 2009 15:28:53 +1100
> Subject: Re: [antlr-interest] failed predicate problem
> From: michael.bedward at gmail.com
> To: yimm8369 at hotmail.com
> CC: antlr-interest at antlr.org
> 
> Hi
> 
> You are re-writing an AST ? I ask because your question made it sound
> like you are running actions but the grammar looks like re-writing.
> 
> I was under the impression that you MUST provide an explicit
> alternative for when the predicate is not true.
> 
> So...
> 
> callExpression
> : ^(CALL_EXPRESSION memberExpression indexSuffix *
> propertyReferenceSuffix* argumentSuffix*)
> {$memberExpression.text.equals("Math.abs")}?
> ->mathabs(x={$argumentSuffix.text})
> 
> -> [ alternative re-write (or blank to just drop the node from
> the tree) ]
> ;
> 
> Hope this helps
> Michael

_________________________________________________________________
MSN安全保护中心,免费修复系统漏洞,保护MSN安全!
http://im.live.cn/safe/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090317/071c91bc/attachment.html 


More information about the antlr-interest mailing list