简体   繁体   中英

Generating Bytecode for Program for which a Compiler was build using ANTLR 4 with Java

I am currently developing a compiler for a particular programming language with ANTLR 4 and Java and now I would like to generate Bytecode or CIL for any program written in that particular languaje but I am not sure where to begin.

I have searched many pages but unable to find any tutorials and whatever example I find does not properly explain the proceedures. I have seen that a helpful library is asm but I don't understand it's implementation.

Can anyone assist me as to the the preferred library and it's implementation with a possible example?

This is not an ANTLR4 question, however the approach is relatively simple: study the executor, which will later execute your byte code. Find a document that describes the bytecode for this particular machine. Then write a listener or visitor to spill out that code.

Commenters here seem to assume you want to generate Java bytecode, but I'm actually not sure about that, since you mention Java only in the context of parsing, not code generation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM