Fri Apr 27 2018

Difference between Compiler and Interpreter

Programming6072 views

Compiler vs Interpreter

As you already know, the programmer gives instruction to a computer by using different types of high-level language which contains words and phrases generally from the English language which humans can be understood, but the computer can’t. A computer only understands program which written in machine code that contains 0's and 1's binary language. A program written by a human is also called source code and that code needs to be converted into machine code to perform the task by computer and this conversion is made by compilers and interpreters. So, a compiler or an interpreter is a program that converts source code into machine code which understands by the computer.

But compiler and interpreter do not perform the same function. Both are two different ways to execute a program written in a programming or scripting language.

So, what is compiler?

The compiler derives its name from the way it works, as looking at the entire piece of source code and collecting and reorganizing the instructions. It translates high-level instructions directly into machine language. Compiled programs generally run faster. The machine code which typically stored in a file is also referred as binary code and can be directly executed by the machine after linking. Examples of compiled programming languages are C, C++, C#, Objective-C, SWIFT, and Fortran.

And what is interpreter?

In contrast, an interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code. That means you write the program using a text editor or something similar, and then instruct the interpreter to run the program. It takes the program one line at a time and translates each line before executing it. It translates the first line and runs it and then the second line so on. Examples of interpreted languages are Perl, Python, Ruby, PHP, JAVA, R, Powershell and Matlab.

Both compilers and interpreters covert source code which refers text files into machine language. Both may generate a parse tree and may generate immediate instructions. But between these translators, there has some technical and processing difference.

Let’s find out differences between compiler and interpreter

  • The basic difference is that a compiler system, including a (built-in or separate) linker, generates a stand-alone machine code program, while an interpreter system instead performs the actions described by the high-level program.

  • Compiler takes the entire program as input, where interpreter takes single instruction as input.

  • Interpreter translates program one statement at a time. But compiler scans the entire program and translates it as a whole into machine code.

  • Compiler process consumes more memory than interpreter.

  • In case of Java, the programs are first compiled into an intermediate form, then interpreted by the interpreter.

  • Compiled programs generally run faster than interpreted programs.

  • The program need not be compiled every time. in interpreter, every time higher level program is converted into lower level program.

  • Errors are displayed after the entire compiled program is checked, where errors are displayed for every instruction interpreted.

  • But compiler is a time-consuming process, where interpreter can immediately execute high-level programs.

  • Every high-level programming language comes with a compiler. However, BASIC and LISP are specially designed to be executed by an interpreter.


 

Conclusion

Human readable format undergoes many passes and phases of compiler and finally, it is converted into the machine-readable format. Traditionally in some operating systems, an additional step was required after compilation - that of resolving the relative location of instructions and data when more than one object module was to be run at the same time and they cross-referred to each other's instruction sequences or data. However, interpreter takes a single line of code as input at a time and execute that line. It will terminate the execution of the code as soon as it finds the error. So, rectify your requirements in a program then choose the perfect one which will fill up the demand to complete the task. Thank you!

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.