Generate Bytecode from an AST

Jonathan Gibbons jonathan.gibbons at
Tue Jun 24 17:56:39 UTC 2014

On 06/21/2014 09:53 PM, Daisy Nkweteyim wrote:
> Heelo everyone,
> I saw a blog post on Generating Byte Code by Building AST's 
> <> which 
> describes how bytecode can be generated from an AST.  It involves 
> changing the javac source code to  bypass the parsing phase and 
> generate bytecode which is produced when one passes his/her own AST.  
> But I would ike to do this in a better way.
> Is it possible to actually generate a .class file from an AST using 
> javac without changing the javac source code and without using a 
> framework?
> Thanks for your time.  Any help is greatly appreciated.
> Regards,
> -- 
> /Daisy Nkweteyim
> Cameroon/

Right now, the recommended solution is to print the AST to a string and 
to compile the string. This can all be done in memory -- there is no 
need to write the text to the filesystem as an interim step.

Currently, there is no way to compile an arbitrary tree created by the 
user using arbitrary implementions of com.sun.source.tree.*.

-- Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list