如何以编程方式生成.class文件? [英] How to programmatically generate .class files?

查看:288
本文介绍了如何以编程方式生成.class文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Java编写一个玩具语言的编译器。我想生成runnable .class文件。我想知道什么是最好的图书馆或工具可以做到这一点?我知道我可以学习所有的指令的二进制格式,并建立自己的常量池等,但这似乎是工作,应该已经做了:没有意义重新发明的轮子,对吧?

I would like to write a compiler for a toy-language for Java. I would like to generate runnable .class files. I was wondering what is the best library or tool available for doing this? I know I could learn the binary format for all the instructions and build my own constant pool etc, but that seems like work that ought to have been already done: no point reinventing the wheel, right?

在线搜索我发现了两种不同的Java汇编语言, Jasmin 牙买加,但只有Jasmin看起来有点保持。

Searching online I've found two different Java Assembly languages, Jasmin and Jamaica, however only Jasmin looks somewhat maintained.

是否有用于向流写入字节码的Java库?这是 Apache BCEL 的用途吗?

Is there a Java library for writing byte codes to a stream? Is this what the Apache BCEL is?

是他们的一个工具,这是字节码生成的标准,如Antlr是用于解析?

Is their a tool for this that is the "standard" for byte-code generation, like Antlr is for parsing?

PS-玩具语言是 Brainf *** ,我想要的东西,我可以有一个简单的语法,所以我可以专注于生成方面,而不是解析部分,这将在后面的步骤。

PS- The toy language is Brainf***, I wanted something where I could have a simple "grammar" so I could focus on the generation aspect and not the parsing part... that will come later on the next step.

推荐答案

ASM BCEL 做基本相似的事情。我推荐ASM,因为它受到更多的支持,更小,是JDK的最新版本。

ASM and BCEL do basically similar things. I'd recommend ASM as it's much more supported, much smaller, and is up to date JDK-wise.

这篇关于如何以编程方式生成.class文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆