Converting ANTLR AST to Java bytecode using ASM

Posted by Nick on Programmers See other posts from Programmers or by Nick
Published on 2012-03-08T01:50:37Z Indexed on 2012/04/07 5:43 UTC
Read the original article Hit count: 317

Filed under:
|

I am currently trying to write my own compiler, targeting the JVM.

I have completed the parsing step using Java classes generated by ANTLR, and have an AST of the source code to work from (An ANTLR "CommonTree", specifically). I am using ASM to simplify the generating of the bytecode.

Could anyone give a broad overview of how to convert this AST to bytecode?

My current strategy is to explore down the tree, generating different code depending on the current node (using "Tree.getType()").

The problem is that I can only recognise tokens from my lexer this way, rather than more complex patterns from the parser.

Is there something I am missing, or am I simply approaching this wrong?

Thanks in advance :)

© Programmers or respective owner

Related posts about compiler

Related posts about jvm