Compilers and
Interpreters
What is Compiler?
A compiler is a computer program that transforms code written in a high-level programming
language into the machine code. It is a program which translates the human-readable code
to a language a computer processor understands (binary 1 and 0 bits). The computer
processes the machine code to perform the corresponding tasks.
A compiler should comply with the syntax rule of that programming language in which it is
written. However, the compiler is only a program and cannot fix errors found in that
program. So, if you make a mistake, you need to make changes in the syntax of your
program. Otherwise, it will not compile.
What is Interpreter?
An interpreter is a computer program, which coverts each high-level program statement
into the machine code. This includes source code, pre-compiled code, and scripts. Both
compiler and interpreters do the same job which is converting higher level programming
language to machine code. However, a compiler will convert the code into machine code
(create an exe) before program run. Interpreters convert code into machine code when the
program is run.
Interpreter Compiler
Scans the entire program and translates it as a
Translates program one statement at a time.
whole into machine code.
It takes less amount of time to analyze the It takes large amount of time to analyze the
source code but the overall execution time is source code but the overall execution time is
slower. comparatively faster.
Generates intermediate object code which
No intermediate object code is generated,
further requires linking, hence requires more
hence are memory efficient.
memory.
Continues translating the program until the It generates the error message only after
first error is met, in which case it stops. Hence scanning the whole program. Hence debugging
debugging is easy. is comparatively hard.
Programming language like Python, Ruby use Programming language like C, C++ use
interpreters. compilers.