Interpreter Vs Compiler: Difference Between Interpreter and Compiler
Computer programmes are generally written using a high-level language. A high-level language is one which is understandable to humans. It contains words and phrases from the English (or other) language. A computer does not understand high-level language. The only language a computer understands is 0's and 1's in binary, called the machine code. A program written in the high-level language is called a source code. We need to convert the source code into machine code and this conversion task is accomplished by compilers and interpreters. Hence, a compiler or an interpreter is a program that converts the program written in a high-level language into machine code understood by the computer.
In computer science, an interpreter is a computer program that directly executes, i.e. performs, instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:
- parse the source code and perform its behavior directly;
- translate source code into some efficient intermediate representation and immediately execute this;
- explicitly execute stored precompiled code made by a compiler which is part of the interpreter system.
An interpreter translates high-level instructions into an intermediate form, which it then executes. In contrast, a compiler translates high-level instructions directly into machine language. Compiled programs generally run faster than interpreted programs. The advantage of an interpreter, however, is that it does not need to go through the compilation stage during which machine instructions are generated.
Interpreter
|
Compiler
|
| An interpreter translates program one statement at a time. |
A compiler scans the entire program and translates it as a whole into machine code.
|
It takes less amount of time to analyze the source code but the overall execution time is slower.
|
It takes a large amount of time to analyze the source code but the overall execution time is comparatively faster.
|
No intermediate object code is generated, hence is memory efficient.
|
Generates intermediate object code which further requires linking, hence requires more memory.
|
Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy.
|
It generates the error message only after scanning the whole program. Hence debugging is comparatively hard.
|
Programming language like Python, Ruby use interpreters.
|
Programming language like C, C++ use compilers.
|
