[antlr-interest] ANTLR3 Mapping AST Tree to StringTemplate

Kailey Joanette kaileyjo at bigbluebubble.com
Tue Mar 20 11:25:48 PDT 2007

I'll ask our people here to look into picking up a copy of the book, I'm
sure it'll be invaluable when it comes down to trying to get this translator
Correct me if I'm wrong but the syntax for doing what I want with an AST
would look something like this:
modifier returns [StringTemplate code=template("access")]
        {StringTemplate e1=null;}
                       ^(MODIFIER name='public') {code.setAttribute("name",
            |   ^(MODIFIER name='protected') {code.setAttribute("name",
            |   ^(MODIFIER name='private') {code.setAttribute("name", e1);}
            |   ^(MODIFIER name='static') {code.setAttribute("name", e1);}
            |   ^(MODIFIER name='abstract') {code.setAttribute("name", e1);}
            |   ^(MODIFIER name='final') {code.setAttribute("name", e1);}
            |   ^(MODIFIER name='native') {code.setAttribute("name", e1);}
            |   ^(MODIFIER name='synchronized') {code.setAttribute("name",
            |   ^(MODIFIER name='transient') {code.setAttribute("name",
            |   ^(MODIFIER name='volatile') {code.setAttribute("name", e1);}
            |   ^(MODIFIER name='strictfp') {code.setAttribute("name", e1);}
And the ST grammar would obviously have an "access" rule with "name"
Thanks for the quick reply btw!
Now if I could just figure out how to manipulate my AST trees. Being this is
the first time I've ever had to do any language parsing/translating
>Hi. ANTLR integrates ST nicely.  Either a grammar or tree grammar can  
>emit templates, which feed off the input tokens or tree nodes.  No  
>real doc on this exception examples so far.  The book has a whole  
>chapter on this.
>Final beta of book is available.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070320/0b9315ac/attachment-0001.html 

More information about the antlr-interest mailing list