简体   繁体   English

为使用 ANTLR 4 和 Java 构建编译器的程序生成字节码

[英]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.我目前正在使用 ANTLR 4 和 Java 为特定编程语言开发编译器,现在我想为用该特定语言编写的任何程序生成字节码或 CIL,但我不确定从哪里开始。

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.我已经看到一个有用的库是asm但我不明白它的实现。

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.这不是 ANTLR4 的问题,但是方法相对简单:研究执行器,它稍后将执行您的字节码。 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.这里的评论者似乎假设您想要生成 Java 字节码,但我实际上并不确定,因为您仅在解析的上下文中提到 Java,而不是在代码生成的上下文中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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