Compiler Vs Interpreter

Have you ever thought, how a computer understands your command?

The computer can only interpret programs that are in the form of 0 and 1. Hence conversion from source code into machine code determines the final program.

Interpreters and Compilers are responsible for this conversion of programming or scripting (high-level language) language into machine code. But if both are doing the same things, what make them different? Let’s take a look at that.

COMPILER

What is Compiler?

A Compiler is a computer program that translates computer code written in one programming language into another programming language. A Compiler takes the entire program and converts it into executable computer code. It takes an entire program because the computer only understands the program written in 0’s and 1’s and converts the executable program into machine code that is recognized by the computer. Examples of compiled programming languages are C and C++.

  • “Compiler” is primarily used for programs that translate source code from a high-level programming language to a lower-level programming language.

A Compiler is likely to perform many or all the operations: preprocessing, lexical analysis, parsing, semantic analysis, conversion of input programs to an intermediate representation, code optimizing and code generation.

INTERPRETER

What is an Interpreter?

An Interpreter is a computer program, which converts each high-level program statement into machine code. This include source code, pre-compiled code, and scripts.

An Interpreter is defined as a machine program that directly executes a set of instructions without compiling them. Examples of interpreted languages are Perl, Python and Matlab.

  • Both Compiler and Interpreter do the same job which is converting high-level programming language to machine code. However, a compiler will convert the code into machine code before the program run. Interpreter covers code into machine code when the program is run.

HOW IT WORKS?

Starting with, a compiler creates the program. It will analyze all the language statements to check whether they are correct or not. If it comes across something incorrect, it will give an error message. If there are no errors spotted, then the compiler will convert the source code into machine code. The compiler links the different code files into programs that can be run such as exe. Finally, the program runs.

An interpreter creates the program. It neither links the files nor generates machine code. The source statements are executed line by line while executing the program.

ADVANTAGES & DISADVANTAGES

Advantages Of Compiler

  • The program codes are translated into machine code already and hence the time to execute the code is very less.
  • EXE files execute faster than source codes. The object codes are saved and can run at any time.
  • Object Codes are harder for a user to change than source codes
  • The compiler checks the source code for syntax errors during compilation.

Disadvantages of Compiler

  • As the entire program is translated it uses much more of the computer’s memory.
  • It is not possible to change the program without going back to the source code while working with a compiler.
  • Object code needs to be produced before a final executable file, this can be a slow process.
  • The Source code must be 100% correct for the executable file to be produced.

Advantages Of Interpreter

  • Interpreters make working with the source code much easier.
  • It translates one instruction at a time;therefore it uses a minimum amount of memory.
  • It is also helpful in the debugging process because the interpreter can relate error messages to the instruction being executed

Disadvantages of Interpreter

  • Each time the program is executed time is spent interpreting, hence a slower execution time.
  • Interpreted programs can only run on the computers that have the respective interpreters.

DIFFERENCE

Here you will be more clear about Compiler and Interpreter-

Please comment if you find anything incorrect, or you want more information about the topic discussed above.

Visit the link below for more blogs on python :

Visit our website:

Author: Riya Patidar

Editor: Ashutosh Raghuwanshi, Devendra Patidar

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store