Often I read in forums posts like “C is a compiled language” or “PHP is a interpreted language”. But a programming language is just a definition of a language and says nothing about the execution strategy. There are also developed interpreters for C and there also exist compilers for PHP. But what is the difference between interpreters and compilers?
Interpreter are tools that translate a source code in machine code, operation by operation, parallel to the execution. Because of the reason that the translation happens during the runtime the performance is decreased. For every new execution it’s nessesary to translate the source code again.
Compiler are seperated in two different types depending on the time of translation. The first one ist the Ahead-of-time-Compiler (AOT-Compiler) and the second one ist the Just-in-time-Compiler (JIT-Compiler). The AOT-Compiler translates the whole source code before it is executed and the JIT-Compiler does the translation just a little bit before it is needed for the execution. Because of the reason that already translated source code is saved temporarily by the JIT-Compiler it has a better performance then the Interpreter but it has a worse performance compared to the AOT-Compiler.
An AOT-Compiler can either translate the source code straight into machine code, e.g. gcc (C) and g++ (C++), or it can translate it into an intermediate representation (IR) (e.g. Bytecode (Java) and MSIL (C#)), e.g. javac (Java) and csc (C#). As soon as the IR-Code gets executed a JIT-Compiler is used to translate the IR-Code into machine code.
A typical example is JavaScript. In the past JavaScript was interpreted by the web browsers. These days the most used web browser Chrome uses V8 a JavaScript JIT-Compiler. By the way V8 gets also used by Node.js.