Java compiler in java

Possible duplicate:
implementation of the compiler in "itself"

I read about the Java compiler and realized that it was written in Java. How is this possible?

I mean, isn't that the Chicken and Egg problem? How to write a compiler in one language?

+4
source share
3 answers

the original was written in C. Then you can write the next version in Java. :)

+3
source

The problem you are addressing is indeed a problem for any compiler. For example, many compilers are written in C. Well ... how do you compile a C compiler without a C compiler without ... etc. Etc.

The process you are looking for is called bootstrapping . From Wikipedia (see Article for more information and links to other articles):

Bootstraping is a term used in computer science to describe methods associated with writing a compiler (or assembler) into a target programming language intended for compilation. Applying this technique leads to a self-service compiler.

Most programming languages ​​are loaded, including BASIC, C, Pascal, Factor, Haskell, Modula-2, Oberon, OCaml, Common Lisp, Scheme, Python, etc.

The article also addresses the chicken problem and the egg problem that you mentioned. I can quote all of this here, but hopefully you will begin to understand this. The big question!

+1
source

Once you get enough features in a programming language, you can write your own compiler by simply treating the compiler as a program that accepts “specific formatted” input and writes out “specific formatted” output.

In other words, there is no dependence on the language in which the compiler is implemented and the language that it compiles. Without dependence, this does not require the same from him. And he does not need to be different.

The original compiler is not explicitly written in Java. It was written in C; however, it is possible to have strong documentation and just write the “compiled code” using a hex editor if you really want the bootstrap method step by step. While it is possible to bypass the download, boot loading is recommended, because writing object code in a hex editor is incredibly expensive and error prone.

0
source

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


All Articles