What is Compiler and Interpreter ??

Compiler  VS  Interpreter 



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.

Interpreter:

 An interpreter is a computer program, which coverts each high-level program statement into the machine code. This includes source code, per-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 (creates a .exe) before program run. Interpreters convert code into machine code when the  program runs.


                                      Compiler                                                Interpreter 


1) Compiler works on the complete
program at once. It takes the entire program as input.

2)   Compiler generates
intermediate code, called the object code or
machine code.


3) Compiled programs take more memory because the entire object code has to reside in memory.



1) Interpreter program works line-by line
It takes one statement at a time as input.


2) Interpreter does not generate intermediate object code or machine code.


3) Interpreter does not generate intermediate object code. As a result, interpreted programs are more memory efficient.


4) Compiled programs take more memory because the entire object code has to reside in memory.

5) It displays all the errors after compilation  , all at same time i,e Errors are reported after the entire program is checked for syntactical and other errors.

4)Interpreter execute conditional control
statements at a much slower speed.


5) It displays error of each line one by one. i,e Error is reported as soon as the first error is encountered. Rest of the program will not be checked until the existing error is removed.




6) Compiler executes conditional control statements (like if-else and
switch-case) and logical constructs faster than interpreter.

7) Compile once and run anytime.
Compiled program does not need to be compiled every time.



6) Interpreter execute conditional control
statements at a much slower speed.



7) Interpreted programs are interpreted line-by-line every time they are run.


8)A compiled language is more difficult to debug.


9)Compiler does not allow a program to run until it is completely error free.



8) Debugging is easy because interpreter stops and reports errors as it encounters them.

9)Interpreter runs the program from first line and stops execution only if it
encounters an error.

10) Compiled languages are more efficient but difficult to debug.


Examples of programming
languages that use compilers: C
C++, COBOL






10) Interpreted languages are less efficient but easier to debug. 


Examples of programming languages
that use interpreters: BASIC, Visual
Basic, Python, Ruby, PHP, Perl,
MATLAB, Lispe 




Function  of compiler and interpreter :

Source code written in a high level language is put through a piece of software called a compiler or interpreter. This software takes in the source code and converts it to some other language , usually a lower level language such as C or assembly language. From there , this code is then translated again into machine code which the processor is actually able to understand.

Machine code , being made up of individual processor instructions , is passed to the CPU , where each instruction goes through a hardware structure called a decoder. The decoder converts this instruction into individual control signals , and then drives data through the CPU’s functional units, as to produce the desired result.










Comments

Popular Posts

Translate