Difference between Compiler and Interpreter

In this tutorial you will learn about difference between compiler and interpreter i.e. compiler vs interpreter.

We know that computers can only understand machine language which is in binary format. But we write in natural programming language (like C, Java etc). So there must be something which converts these programming instructions into machine understandable instructions. Those are compilers and interpreters. Both are intended for same purpose. But there they differ in the way they accomplish the task.

Compiler: Compiler can be defined as, it is a computer program, that used to convert high level instructions or language into a form that can be understood by the computer which is called low level language. There are specific compilers for certain specific languages. After compilation an executable file will be generated.

Interpreter: The programs created in high level languages can be executed by using different ways. The first one is the use of compiler and the other method is to use an interpreter. High level instruction or language is converted into intermediate from by an interpreter. The advantage of using an interpreter is that the high level program does not goes through compilation stage, which can be a time consuming method. So by using interpreter high level program executed directly.

All most all high level programming languages have compilers and interpreters. But some languages like LISP and BASIC are designed in such a way that the programs made using them are executed by an interpreter.

Now we will see some differences between them.

Difference between Compiler and Interpreter

Compiler Interpreter
1) Compiler converts high level instructions into machine understandable instructions. 1) Interpreter directly executes high level code without converting.
2) Before execution, entire program will be executed by compiler. 2) Interpreter executes line by line. So after translating first line only it executes second line and so on.
3) If there any compiler errors, it shows entire programs compiler errors once. First line error won’t stop program to be executed in compiler. 3) If there any errors, only one line error displayed at once. Not all at once like compiler. Error in nth line will stop execution of lines form n+1.
4) After compilation an executable file will be created. That will be executed for program output. 4) Interpreter is required by an interpreted program each time.
5) We can use object code which is generated by compiler (like .exe, a.out files) repeatedly, without executing original program every time. Unless we want to change original program. 5) In interpreter whenever we want output of program we should execute entire original program.
6) Compilation need more extra space since an extra executable file will be generated. 6) Requires less memory space. Because no need to store any intermediate code.
7) Compiled code runs faster than original code. This way of doing is faster than using interpreter 7) There is no intermediate code generation/executable files. Each time entire program must be executed. Therefore interpreted program is slower than compiled program.
8) It is faster in assigning memory to variables and accessing those. 8) Access to variables is also slower in an interpreter because the mapping of identifiers to storage locations must be done repeatedly at run-time rather than at compile time.
9) Spends a lot of time analyzing and processing the program. 9) Relatively little time is spent analyzing and processing the program.
10) Native compiler, cross compiler, Source to source compiler, one pass compiler, incremental compiler, source compiler are some different types of compilers. 10) Bytecode interpreter, threaded code interpreter, abstract syntax tree interpreter are some types of interpreters.
11) Example: C, Java compilers 11) Example: LISP, BASIC interpreters

Comment below if you have queries related to above tutorial for difference between Compiler and Interpreter.

Leave a Reply

Your email address will not be published. Required fields are marked *