Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrapping still requires outside support

I've heard of the idea of bootstrapping a language, that is, writing a compiler/interpreter for the language in itself. I was wondering how this could be accomplished and looked around a bit, and saw someone say that it could only be done by either

  • writing an initial compiler in a different language.
  • hand-coding an initial compiler in Assembly, which seems like a special case of the first

To me, neither of these seem to actually be bootstrapping a language in the sense that they both require outside support. Is there a way to actually write a compiler in its own language?

like image 809
pbh101 Avatar asked Aug 17 '08 06:08

pbh101


People also ask

What is bootstrapping explain briefly about bootstrapping process?

Bootstrapping is a process in which simple language is used to translate more complicated program which in turn may handle for more complicated program. This complicated program can further handle even more complicated program and so on. Writing a compiler for any high level language is a complicated process.

What do you mean by bootstrapping?

Bootstrapping is a term used in business to refer to the process of using only existing resources, such as personal savings, personal computing equipment, and garage space, to start and grow a company.

What is the role of bootstrapping in cross compiler?

It is an approach for making a self-compiling compiler that is a compiler written in the source programming language that it determine to compile. A bootstrap compiler can compile the compiler and thus you can use this compiled compiler to compile everything else and the future versions of itself.


2 Answers

Is there a way to actually write a compiler in its own language?

You have to have some existing language to write your new compiler in. If you were writing a new, say, C++ compiler, you would just write it in C++ and compile it with an existing compiler first. On the other hand, if you were creating a compiler for a new language, let's call it Yazzleof, you would need to write the new compiler in another language first. Generally, this would be another programming language, but it doesn't have to be. It can be assembly, or if necessary, machine code.

If you were going to bootstrap a compiler for Yazzleof, you generally wouldn't write a compiler for the full language initially. Instead you would write a compiler for Yazzle-lite, the smallest possible subset of the Yazzleof (well, a pretty small subset at least). Then in Yazzle-lite, you would write a compiler for the full language. (Obviously this can occur iteratively instead of in one jump.) Because Yazzle-lite is a proper subset of Yazzleof, you now have a compiler which can compile itself.

There is a really good writeup about bootstrapping a compiler from the lowest possible level (which on a modern machine is basically a hex editor), titled Bootstrapping a simple compiler from nothing. It can be found at https://web.archive.org/web/20061108010907/http://www.rano.org/bcompiler.html.

like image 159
Derek Park Avatar answered Oct 14 '22 23:10

Derek Park


The explanation you've read is correct. There's a discussion of this in Compilers: Principles, Techniques, and Tools (the Dragon Book):

  • Write a compiler C1 for language X in language Y
  • Use the compiler C1 to write compiler C2 for language X in language X
  • Now C2 is a fully self hosting environment.
like image 30
Mark Harrison Avatar answered Oct 15 '22 00:10

Mark Harrison