Saturday 7 June 2014

Difference Between Compiler and Interpreter

A Compiler and Interpreter both carry out the same purpose – convert a high level language (like C, Java) instructions into the binary form which is understandable by computer hardware. Specific compilers/interpreters are designed for different high level languages. However both compiler and interpreter have the same goal but they different in the way they accomplish their task i.e. convert high level language into machine language. Through this article we will talk about the basic knowledge of both and distinguish the basic difference between compiler and interpreter.
Compiler
Compiler is a piece of code that translates the high level language into machine language. When a user writes a code in a high level language and wants to execute, a specific compiler which is designed for that specific language is used before it will be executed. Compiler scans whole program first and then translates it into machine code which will be executed by the computer processor and the corresponding tasks will be performed.  
Here program written in higher level language is known as source code and converted one is called object program.

Interpreter
Interpreters are not much different than compilers. They also convert the high level language into machine readable binary equivalents. Each time when an interpreter gets a high level language code to be executed, it converts the code into an intermediate code before converting it into the machine code. Each part of the code is interpreted and then execute separately in a sequence and an error is found in a part of the code it will stop the interpretation of the code without translating the next set of the codes.  
In the above figure, first a source code is converted to an intermediate form and then that is executed by the interpreter.
The main differences between compiler and interpreter are listed below:
  • The interpreter takes one statement then translates it and executes it and then takes another statement. While the compiler translates the entire program in one go and then executes it.
  • Compiler generates the error report after the translation of the entire page while an interpreter will stop the translation after it gets the first error.
  • ·Compiler takes a larger amount of time in analyzing and processing the high level language code comparatively interpreter takes lesser time in the same process.
  • The compiler derives its name from the way it works, looking at the entire piece of source code and collecting and reorganizing the instructions. Thus, a compiler differs from an interpreter, which analyzes and executes each line of source code in succession, without looking at the entire program. 
  • Besides the processing and analyzing time the overall execution time of a code is faster for compiler relative to the interpreter.

0 comments:

Post a Comment