Compilers Interpreters and Engines

Mahi!
feedflood
Published in
2 min readAug 3, 2019

Interpreter

Interpreters directly translate a program P into machine code which is then executed piece by piece as the program runs. An Interpreter comes into action only when the program is executed i.e. runtime. If there is an error at any point of execution then the program stops. The interpreter is faster but every time the code runs the same process occurs.

Compiler

A Compiler usually translates a program P into an equivalent object code P’. Now, this P’ is then mixed with required libraries and other code of respective OS using a linker to create an executable file. This requires more time initially but after that, we just need to run the executable file. Thus compiled languages are faster than interpreted languages.

Compilers are of two types JIT and AOT based on when the translation is done. In both cases, the program P and its compiled version P’ are semantically equivalent.

In JIT(Just-in-time) compilers the program P is translated into P’ as the program runs.

In AOT(Ahead-of-time) compilers the program P is translated into P’ before execution and later executed.

Engine

Now if you mix the compiler and Interpreter together than this system is called an engine.

In the first case, you have an AOT compiler for language X which converts P into P’ and the interpreter converts P’ into byte code. Here the languages for compiler and interpreter are different so the interpreter must wait for the compiler to finish.

In another case, we can have a JIT compiler and interpreter of the same language. The compiler compiles P to P’ and simultaneously the interpreter for P’ translates it into machine code. This system can work only at runtime since the interpreter needs P’ which is compiled from P.

--

--