Compiler vs Interpreter

Blake Tolman
2 min readFeb 3, 2021

Coding is a complex process that has been made easier over time with higher level computer languages.These high level languages create what is called source code, which is not directly able to be read by a computer. A computer’s reads and stores information in binary data (10010110) also called machine code. This language is not readable for people so a gap has to be made between source code and machine code for the computer to operate. This is all done by either a compiler or an interpreter.

The Difference:

Both compilers and interpreters have the same end process of making machine code but do so in different ways. During compilation, all the language statements will be parsed or analyzed to see if it is correct. If there is no error, the compiler would then convert the source code into machine code which is then ready to execute. The output of the compilation is also known as object code or object module. The task of a compiler is generally divided into several phases. The phases include lexical analysis, syntax analysis, sematic analysis, intermediate code generator, code optimizer and code generator. Each of these phases helps convert the source code by breaking it down into tokens, generating parse trees and optimizing the source code. Interpreters do not produce any intermediary object code like compilers. In interpreters, the source code is compiled and executed at the same time. It continues to translate the program until it encounters the first error after which it stops. Therefore, it is easy to debug. With interpreters, the source statements are executed line by line in contrast to a compiler that converts the whole program at once.The interpreter also performs lexing, parsing and type checking which is similar to a compiler. However, interpreters directly process syntax tree rather than generating code from it.

Pros and Cons:

  • A compiler takes an entire program and a lot of time to analyze the source code, whereas the interpreter takes a single line of code and very little time to analyze it.
  • A compiled code runs faster while interpreted code runs slower.
  • A compiler displays all errors after compilation. If your code has mistakes, it will not compile. But the interpreter displays errors of each line one by one.
  • Interpretation does not replace compilation completely.
  • Compilers can contain interpreters for optimization reasons like faster performance and smaller memory footprint.

--

--