<p>Is it possible to bootstrap an interpreted language? <a href="https://en.wikipedia.org/wiki/Bootstrapping#Computing" rel="noreferrer">Bootstrapping</a>, broadly, refers to writing a programming language in that same programming language.</p>
<p>This is obviously possible for compiled languages. Once you have a programming language, you can code a compiler for it in that language. Since it compiles to an executable, you don't need the original implementation to run the bootstrapped compiler.</p>
<p>However, for interpreted languages, if you write a compiler in that language, you'll still need the original interpreter to run the implementation. It is seemingly not possible.</p>
<p>So, my question is basically whether it is possible to bootstrap an interpreted language without needing the original interpreter?</p>

<implementation><interpreters><bootstrapping>
Is it possible to bootstrap an interpreted language?
CC BY-SA 4.0
2023-05-20T19:44:05.730Z
You mean self-hosted, not bootstrapped. Bootstrapping refers to an initial implementation of a language in another language, with the aim to later replace it with a self-hosted implementation.
pxeger
CC BY-SA 4.0
2023-05-20T21:41:59.927Z
Related question on Software Engineering: [Is it possible to create a "bootstrapped" interpreter independent of the original interpreter?](https://softwareengineering.stackexchange.com/questions/348476/whyareyoureadingthis)
user
<p>It is not possible to create a <em>fully</em> bootstrapped interpreter. However, it <em>is</em> entirely possible to create a bootstrapped compiler that targets some lower language which is then interpreted. For example, you could write a Java compiler in Java that targets JVM bytecode. This isn't full bootstrapping in the original sense, as it still requires an interpreter for this bytecode that's written in another language. However, this approach still reaps much of the benefits of bootstrapping.</p>
<p>This is quite similar to compiled languages with self-hosted compilers that target an existing intermediate representation. For example, the major compilers for both Rust and Zig (as well as many other languages I do not have the pleasure of knowing) are self-hosted but target the LLVM bytecode.</p>

CC BY-SA 4.0
2023-05-20T11:53:56.907Z
2023-05-20T12:07:50.350Z
2023-05-20T12:07:50.350Z
Olive
<p>It is obviously impossible for a interpreter to only be able to be interpreted by itself, as that would require a infinite chain of interpreters. Each one would slow down the entire system and require more memory, unlike compiled programs that function mostly the same no matter how often the compiler has compiled itself.</p>
<p>However, languages can definitely interpret themselves in specific situations:</p>
<ul>
<li>If a language is also able to be compiled with a compiler, you could compile the interpreter and then use the compiled executable to interpret other code. <a href="https://www.pypy.org/" rel="noreferrer">This is how PyPy works.</a></li>
<li>Simply interpret your interpreter in a different interpreter, like <a href="https://esolangs.org/wiki/Mbfi" rel="noreferrer">the Brainfuck self-interpreter</a></li>
<li>Write code that can compile code to bytecode or some intermediate language that can then be interpreted <a href="https://languagedesign.stackexchange.com/a/811/8">as suggested by Olive</a>.</li>
</ul>
<p>Even for a interpreted language, trying to write it in itself is a useful exercise, but unfortunately you are still going to need some other language someplace in the interpretation stack.</p>

CC BY-SA 4.0
2023-05-20T12:31:34.900Z
2023-05-20T15:32:24.663Z
2023-05-20T15:32:24.663Z
mousetail 'he-him'
# Is it possible to bootstrap an interpreted language?
Posted by: username_0 on 2023-05-20
Is it possible to bootstrap an interpreted language? [Bootstrapping](https://en.wikipedia.org/wiki/Bootstrapping#Computing), broadly, refers to writing a programming language in that same programming language.

This is obviously possible for compiled languages. Once you have a programming language, you can code a compiler for it in that language. Since it compiles to an executable, you don't need the original implementation to run the bootstrapped compiler.

However, for interpreted languages, if you write a compiler in that language, you'll still need the original interpreter to run the implementation. It is seemingly not possible.

So, my question is basically whether it is possible to bootstrap an interpreted language without needing the original interpreter?
**Tags:** implementation interpreters bootstrapping
> **Comments:**
> **username_1**: You mean self-hosted, not bootstrapped. Bootstrapping refers to an initial implementation of a language in another language, with the aim to later replace it with a self-hosted implementation.  
> **username_2**: Related question on Software Engineering: [Is it possible to create a "bootstrapped" interpreter independent of the original interpreter?](https://softwareengineering.stackexchange.com/questions/348476/whyareyoureadingthis)  
---
## 2 answers
### Answer by username_4 on 2023-05-20. Score: 10 | Accepted answer
It is obviously impossible for a interpreter to only be able to be interpreted by itself, as that would require a infinite chain of interpreters. Each one would slow down the entire system and require more memory, unlike compiled programs that function mostly the same no matter how often the compiler has compiled itself.

However, languages can definitely interpret themselves in specific situations:

* If a language is also able to be compiled with a compiler, you could compile the interpreter and then use the compiled executable to interpret other code. [This is how PyPy works.](https://www.pypy.org/)
* Simply interpret your interpreter in a different interpreter, like [the Brainfuck self-interpreter](https://esolangs.org/wiki/Mbfi)
* Write code that can compile code to bytecode or some intermediate language that can then be interpreted [as suggested by Olive](https://languagedesign.stackexchange.com/a/811/8).

Even for a interpreted language, trying to write it in itself is a useful exercise, but unfortunately you are still going to need some other language someplace in the interpretation stack.
---
### Answer by username_3 on 2023-05-20. Score: 9
It is not possible to create a *fully* bootstrapped interpreter. However, it *is* entirely possible to create a bootstrapped compiler that targets some lower language which is then interpreted. For example, you could write a Java compiler in Java that targets JVM bytecode. This isn't full bootstrapping in the original sense, as it still requires an interpreter for this bytecode that's written in another language. However, this approach still reaps much of the benefits of bootstrapping.

This is quite similar to compiled languages with self-hosted compilers that target an existing intermediate representation. For example, the major compilers for both Rust and Zig (as well as many other languages I do not have the pleasure of knowing) are self-hosted but target the LLVM bytecode.
---
