创建JVM编程语言 [英] Create a JVM programming language
问题描述
我已经在C(使用lex& bison)中创建了一个编译器,用于支持循环,函数中的函数声明,递归调用等的动态类型编程语言。我还创建了一个虚拟机,用于运行中间代码编译器。
I have created a compiler in C (using lex & bison) for a dynamic typed programming language that supports loops, functions declarations inside functions, recursive calls etc. I also created a virtual machine for that runs the intermediate code created by the compiler.
我现在想,而不是编译到我自己的中间代码,编译为java字节代码。
I was now thinking instead of compiling to my own intermediate code, compile it to java byte code.
我看到有关创建JVM语言的问题已经问题,但我没有找到答案非常翔实。
I saw that the question about creating a JVM language has already been asked but I don't find the answer very informative.
这里是我的问题: / p>
So here are my questions:
- 我想为JVM创建语言必须是读取 JVM规范书,你能建议什么其他书(当然除了Dragon Book)?
- 有许多Java库可以读取,写入和更改.class文件,例如< a href =http://www.ej-technologies.com/products/jclasslib/overview.html =nofollow noreferrer> jclasslib , bcel , gnu字节码,等等。你会建议哪一个?
- 我想要看看可能是另一种面向JVM的语言,比如Clojure,Jython或JRuby。但是所有这些语言都非常高级和复杂(为它们创建一个编译器)。我正在寻找一个更简单的(我不介意它是未知或未使用)编程语言的目标JVM和它的编译器是开源。任何想法?
- I guess to create a language for JVM a must is to read the JVM specification book, what other books can you suggest (except Dragon Book of course)? I'm mostly concerned in books or tutorials on how to create a JVM language, not a compiler in general.
- There are many Java libraries to read, write and change .class files like jclasslib, bcel, gnu bytecode, etc. Which one would you suggest? Also, are you aware of C libraries that do the same job?
- I was thinking to have a look at maybe another language that targets the JVM like Clojure, Jython or JRuby. But all these languages are very high level and complicated (to create a compiler for them). I was looking for a simpler (I don't mind it it's unknown or unused) programming language that targets the JVM and it's compiler is open source. Any ideas?
推荐答案
我也建议使用ASM, =http://jasmin.sourceforge.net/ =nofollow noreferrer> Jasmin ,我用它(或:不得不使用它)一个大学项目,它的工作相当不错,我使用java和jasmin为程序语言编写了一个lexer / parse / analyzer / optimizer / generator组合,因此生成JVM代码。我上传了代码这里,有趣的部分应该是源代码本身。在文件夹bytecode / InsanelyFastByteCodeCreator.java中,您会发现一个代码块,它将AST树转换为jasmin汇编器的输入格式。很简单。
I would also recommend ASM, but have a look at Jasmin, I used it (or: had to use it) for an university-project, and it works quite well, I wrote a lexer/parse/analyzer/optimizer/generator combination for a programing-language using java and jasmin, so generating JVM Code. I uploaded the code here, the interesting part should be the source-code itself. In the folder "bytecode/InsanelyFastByteCodeCreator.java" you find a pice of code which transforms an AST Tree into the input format of jasmin assembler. Is quite straight forward.
源语言(由Lexer + Parser + Analyzer转换为AST)是Java的一个子集,称为MiniJava。它缺少一些复杂的功能,如继承,构造函数,静态方法,私有字段/方法。这些功能都不难实现,但是还有一个任务是写一个X86后端(以便生成机器汇编程序),如果没有处理某些东西的JVM,这些东西就会变得很困难。
The source-language (which was tranformed to the AST by Lexer+Parser+Analyzer) is a subset of Java called MiniJava. It lacks some "complicated" features like Inheritance, Constructors, static methods, private fields/methods. None of those features are difficult to implement, but there was another task to write an X86 backend (so to generate machine-assembler), and those things tend to get difficult if you got no JVM which handles some things.
如果你想知道奇怪的类名:大学项目的任务是将AST转换为aa SSA 图形(因此代表输入代码的图形),然后优化图形,然后将图形转换为java字节代码。这是项目的大约3/4的工作,InsanlyFastByteCodeCreator只是一个捷径来测试一切。
In case you wonder about the strange Class name: The task of the university project was to transform the AST into a a SSA Graph (so a graph representing the input code), then optimize the graph and then turn the graph into java byte code. That was about 3/4 of the work of the project and the InsanlyFastByteCodeCreator was just a short-cut to test everything.
看看 Java虚拟机一书,来自Jon Meyer和Troy Downing。这本书大量引用了Jasmin-Assembler,它对理解JVM内部结构非常有帮助。
Have a look at the "Java Virtual Machine" book from Jon Meyer and Troy Downing. This book heavily references the Jasmin-Assembler, it's quite helpful for understanding the JVM internals.
这篇关于创建JVM编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!