Writing Languages ​​for the JVM

Suppose I write a programming language; for the namesake, I'll call him lang .

To start the long road of writing lang , I decided to start by writing lang on my own. I can not start it, because there is nothing to start a program that starts itself.

So, I start by writing another compiler for lang in Java. This time, when I finished, I decided to convert it to Bytecode and leave it to that. I now have a working compiler that converts all my lang code to Bytecode.

So, I decided to plug my own compiler for the language into the compiler that I just made in Java. Then I convert the self-compiler to Bytecode and pull out the Java compiler. I now have a lang compiler written by itself, converted to Bytecode, ready to use.

This creates a solid program, and I understand all this, but my question is about the compiler design for the JVM , what if I decide to release an update for my language? How do I update Bytecode? Am I just overwriting the updated version of the language in an older version?

I ask about it because it is what I want to do. Write a non-existent language by itself, and then load it into the JVM, first creating a compiler in Java.

This is the same as with C ++. C with classes was written, and then C ++ in it, and finally C with classes was left for loaded C ++. But then, how did they generally update the language?

+4
source share
4 answers

I will answer this from two possible scenarios of your development. With any byte code language, you can update the virtual machine or language at any time.

, , . , lang ( A), , . , , B. , B, C.

, JVM ? JVM, , , ( B). , -, . - , , ( C).

+3

, .

.

lexer/parser, (AST). AST - .

- , , AST.

?

, , -.

- , .

+1

lang lang. (bootstrap) ( interoreter). java.

lang. .


, lang java, lang, -.

+1
source

A new version of the compiler can only be compiled by a previous version. For example, to compile g ++ 4.6 you should use g ++ 4.5, but not g ++ 1.0.

BTW there is no need to write a compiler for lang on its own. He is going to demonstrate that the language is "mature", but some languages ​​should not demonstrate this.

-1
source

Source: https://habr.com/ru/post/1669918/


All Articles