Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building your own Interpreter that can function as a compiler

It is possible for me to build my own Interpreter that could then be transformed into a compiler? If yes, how do I go about building it?

like image 804
wantoknow Avatar asked Apr 14 '10 12:04

wantoknow


1 Answers

This is called the Second Futamura Projection. It was first described by Prof. Yoshihiko Futamura in his 1971 paper Partial Evaluation of Computation Process – An approach to a Compiler-Compiler (Japanese), an English version of which was republished 28 years later.

It uses Partial Evaluation, by partially evaluating the partial evaluator itself with respect to the interpreter, thus yielding a compiler.

So, you need two ingredients: an interpreter for your target language, written in some host language (which may or may not be the same as the target language) and a partial evaluator capable of evaluating both the interpreter and itself, in other words it needs to partially evaluate the host language and it needs to itself be written in the host language it can evaluate.

like image 186
Jörg W Mittag Avatar answered Sep 17 '22 22:09

Jörg W Mittag