[antlr-interest] AST Tree rewriting

Des Hartman des at deshartman.com
Mon Mar 16 04:40:55 PDT 2009


I has just been reading up about AST tree rewriting and it seems to be
exactly what I need. However I am struggling to compile what I believe is a
very simple tree.  I have tried it with language=Java, but the same errors.
Looks like ANTLRWorks does not understand tree rewrites??? The problem I am
having is that ANTLRWorks 1.2.3 with antlr-3.1.2 complains and will not
compile this code. It says

"Unexpected token: ^("
"expecting SEMI, found ')' "

LREF and IREF are defined in the Parser Formula and convertLocalReference
converts a reference like "A" to "{1}" in code.



tree grammar L2ITree;

options {
    language=ActionScript;
    tokenVocab=Formula;
    ASTLabelType=CommonTree;
    filter=true;
    rewrite=true;
}

@members {
    // This function gets overriden in the main code. Returns the IREF value
based on LREF value.
    public function convertLocalReference(ref:CommonTree):Number {return
null;}

}

reference
    : ^(LREF   lr=NAME) { iref:Number = convertLocalReference($lr); }
-> ^(IREF iref)
    ;

===================================================
Thanks
Des
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090316/97fed0fa/attachment.html 


More information about the antlr-interest mailing list