[antlr-interest] AST Rewrite & tree filters support using ActionScript

Des des at deshartman.com
Mon Mar 16 21:13:26 PDT 2009


As alqays thanks for the quick reply. I'll implement your suggestions  
and see how it goes.

Thanks
Des Hartman
+614 01 277 115
iPhone junky

On 17/03/2009, at 14:21, George Scott <george.scott at gmail.com> wrote:

> Des,
>
> Tree rewrites and filters should work.  I think the only problem is  
> you are missing a "var" declaration in your rule when you declare  
> iref.  Also, you will get a runtime error if you try to pass in a  
> Number to construct a token type.  You must use the "int" type, so  
> you should change your iref declaration to be int and the return  
> type of your function as well.  For example:
>
> @members {
>     // This code needs to be implemented in a child class
>     public function convertLocalReference(ref:CommonTree):int  
> {return TokenConstants.INVALID_TOKEN_TYPE;}
>
> }
>
> reference
>     : ^(LREF   lr=NAME) { var iref:int =  
> convertLocalReference($lr); }         -> ^(IREF [iref])
>     ;
>
> If you are not doing any processing in your convertLocalReference()  
> function then you can simplify futher to:
>
> reference
>     : ^(LREF   lr=NAME) -> ^(IREF [$lr.type])
>     ;
>
>
> On Mon, Mar 16, 2009 at 6:51 PM, Des Hartman <des at deshartman.com>  
> wrote:
> George
>
> Is AST rewrite and Tree filters supported in ActionScript? I have  
> the following code, but keep ending up with weird compiled as file.  
> I have checked as many of the errors as I can, but want to make sure  
> I am not wasting time with an unsupported feature.
>
> ==============================
> tree grammar L2ITree;
>
> options {
>     language=ActionScript;
>     tokenVocab=Formula;
>     output=AST;
>     ASTLabelType=CommonTree;
>     filter=true;
>     rewrite=true;
> }
>
> @members {
>     // This code needs to be implemented in a child class
>     public function convertLocalReference(ref:CommonTree):Number  
> {return null;}
>
> }
>
> reference
>     : ^(LREF   lr=NAME) { iref:Number =  
> convertLocalReference($lr); }         -> ^(IREF [iref])
>     ;
>
> =================================================
>
> I have attached the formula grammar.
>
> Output errors are on the following lines of code:
>
>                 switch (alt1) {
>                     case 1 :
> <snip>
>                         if ( this.state.backtracking==1 ) {
>                            iref:Number =  
> convertLocalReference(lr);    XXXXXXXXXX Implicit coersion of   
> Number and Class
>                         }
> <snip>
>                         if ( this.state.backtracking==0 ) {
>                         retval.tree =  
> root_0;                                              XXXXXXXXXXXX  
> Property is Read-only
>
>                         var  
> stream_retval:RewriteRuleSubtreeStream=new  
> RewriteRuleSubtreeStream(adaptor,"token retval", retval!=null?  
> retval.tree:null);
> <snip>
>
>                             // C:\\usr\\workspace\\SFXFormula\\src\ 
> \com\\wiredlizard\\grammar\\L2ITree.g:39:79: ^( IREF[iref] )
>                             {
>                             var root_1:CommonTree =  
> CommonTree(adaptor.nil());
>                             root_1 =  
> CommonTree(adaptor.becomeRoot(CommonTree(adaptor.create(IREF,  
> iref)), root_1));  XXXXXXXXXXX Access of undefined property iref
>
>                             adaptor.addChild(root_0, root_1);
>
> <snip>
>                         retval.tree =  
> CommonTree(adaptor.rulePostProcessing(root_0));               
> XXXXXXXXXXXX Property is Read-only
>                          
> input.replaceChildren(adaptor.getParent(retval.start),
>                                                
> adaptor.getChildIndex(retval.start),
>                                                
> adaptor.getChildIndex(_last),
>                                               retval.tree);}
>                         }
>
> Thanks
> Des
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090317/f816ba53/attachment.html 


More information about the antlr-interest mailing list