Creating your own interpreter that can work as a compiler

Is it possible to create your own interpreter, which can then be converted to a compiler? If so, how do I build it?

+7
compiler-construction programming-languages build-process interpreter
source share
3 answers

This is called the second projection of Futamura. It was first described by Prof. Yoshihiko Futamura, in his 1971 article, Partial Evaluation of the Computing Process — An Approach to the Compiler-Compiler (Japanese) , an English version that was reissued 28 years later.

It uses Partial Evaluation , partially evaluating the evaluator itself in relation to the interpreter, which the compiler gives.

So, you need two components: an interpreter for your target language, written in some host language (which may or may not coincide with the target language) and a partial evaluator, capable of evaluating both the interpreter and yourself in other words, it must partially evaluate the host language, and it must be written in a host language that it can evaluate.

+11
source share

The partial assessment already mentioned is one of the possible methods (very intensive from a computational point of view, but quite general on the other hand). Another approach is metaprogramming: if the language interpreter is implemented as a simple translator that targets another interpreted language, it is very easy to redirect it later to some compiled language or replace the target interpreter with a compiler.

0
source share

Besides Futaruma forecasts, another approach is jit meta-tracing. Meta-tracing jit does not directly track your programs, but indirectly, through a translator. RPython is a cool meta trace. You write an interpreter in a limited version of python, and RPython turns it into a jit compiler in C.

0
source share

All Articles