[antlr-interest] Converting AST back to code

Andy Tripp antlr at jazillian.com
Fri Mar 14 07:38:12 PDT 2008


Adam,
You probably need to spell out the problem a bit more.
Whatever your approach is for printing a full tree...why wouldn't
it work for subtrees, too?

Andy

Adam Cooney wrote:
> Hi,
>   I was wondering if someone could tell me if its possible to use a 
> JavaAST grammar to convert sub-trees (of a full tree) to their 
> respective code segments. For instance:
> TREE:
> COMPILATION_UNIT, TYPE_IMPORT_ON_DEMAND_DECLARATION, SELECT, java, io, 
> TYPE_IMPORT_ON_DEMAND_DECLARATION, SELECT, java, util, 
> CLASS_DECLARATION, MODIFIERS, public, Input1b, CLASS_BODY,
> METHOD_DECLARATION, MODIFIERS, public, static, 132, main,
> FORMAL_PARAMETERS, FORMAL_PARAMETER, MODIFIERS, ARRAY_OF, String, args,
> BLOCK, EXPRESSION_STATEMENT, CALL, SELECT, SELECT, System, out, println,
> ARGUMENTS, "Test 2"
> 
> SUBTREES:
> [COMPILATION_UNIT, TYPE_IMPORT_ON_DEMAND_DECLARATION, SELECT, java, io, 
> TYPE_IM
> PORT_ON_DEMAND_DECLARATION, SELECT, java, util, CLASS_DECLARATION, 
> MODIFIERS, pu
> blic, Input1b, CLASS_BODY]
> [METHOD_DECLARATION, MODIFIERS, public, static, 132, main]
> [FORMAL_PARAMETERS, FORMAL_PARAMETER, MODIFIERS, ARRAY_OF, String, args]
> [BLOCK, EXPRESSION_STATEMENT, CALL, SELECT, SELECT, System, out, println
> [ARGUMENTS, "Test 2"]
>  
> I can covert the Tree into the original code no problem, im just 
> wondering if there is a way of doing it with sub-trees? Or perhaps im 
> just looking at this in the completely wrong way
>  
> 
> ------------------------------------------------------------------------
> She said what? About who? Shameful celebrity quotes on Search Star! 
> <http://www.msnsearchstar.com>



More information about the antlr-interest mailing list