11
$\begingroup$

Is it possible to bootstrap an interpreted language? Bootstrapping, 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?

$\endgroup$
2

2 Answers 2

10
$\begingroup$

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.
  • Simply interpret your interpreter in a different interpreter, like the Brainfuck self-interpreter
  • Write code that can compile code to bytecode or some intermediate language that can then be interpreted as suggested by Olive.

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.

$\endgroup$
9
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .