Example HTML page

Compiler Vs Interpreter

Compiler vs Interpreter

Compiler and Interpreter are two different ways to convert a program written in a programming or scripting language.

A Compiler takes entire program and converts it into object code which is typically stored in a file. The object code is also refereed as binary code and can be directly executed by the machine after linking.

Examples: C and C++

An Interpreter directly executes instructions written in a programming or scripting language without previously converting them to an object code or machine code.

Examples: Perl, Python and MATLAB.

Interesting facts about interpreters and compilers:

1) Both compilers and interpreters covert source code (text files) into tokens, both may generate a parse tree, and both may generate immediate instructions. 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.

2) Once a program is compiled, its source code is not useful for running the code. For interpreted programs, the source code is needed to run the program every time.

3) In general, interpreted programs run slower than the compiled programs.

4) Java programs are first compiled to an intermediate form, then interpreted by the interpreter.

Program→ Compiler→Intermediate file→Interpreter→output


Figure : Compiler Vs Interpreter

                             “Python is an interpreted, object-oriented, high-level programming language.

Compiler vs Interpreter



Compiler works on the complete program at once. It takes the entire program as input. Interpreter program works line-by-line. It takes one statement at a time.
Compiler generates intermediate code, called the object code or machine code. Interpreter does not generate intermediate object code or machine code.
Compiler executes conditional control statements (like if-else and switch-case) and logical constructs faster than interpreter. Interpreter executes conditional control statements at much slower speed.
Compiled programs take more memory because the entire object code has to reside in memory. Interpreter does not generate intermediate object code. As a result, interpreted programs are more memory efficient.
Compile once and run anytime. Compiled program does not need to be compiled every time. Interpreted programs are interpreted line-by-line every time they are run.
Errors are reported after the entire program is checked for syntactical and other errors. 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.
A compiled language is more difficult to debug. Debugging is easy because interpreter stops and reports errors as it encounter them.
Compiler does not allow a program to run until it is completely error-free. Interpreter runs the program from first line and stops execution only if it encounters an error.
Compiled languages are more efficient but difficult to debug. Interpreted languages are less efficient but easier to debug. This makes such languages an ideal choice for new students.
Examples of programming languages that use compilers: C, C++, COBOL. Examples of programming languages that use interpreters: BASIC, Visual Basic, Python, Ruby, PHP, Perl, MATLAB, Lisp.

Table : Comparison of Compiler and Interpreter.




Example HTML page

Leave a Reply

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

Pin It on Pinterest