Difference between Compiler and Interpreter. Compiler vs Interpreter

 










Compiler: A compiler is a computer program(or a set of program) that transforms source code written in a programming language into another computer language(the target language).
Interpreter: An interpreter is a common kind of language processor
Compiler Interpreter
A compiler is a computer program(or a set of program) that transforms source code written in a programming language into another computer language(the target language). An interpreter is a common kind of language processor, instead of producing a target program as a translation an interpreter appears to directly execute the operations specified in the source program on inputs supplied by the user.
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 as input.
Compiler generate the intermediate code called as object code or machine code. Interpreter does not generate intermediate code.
Compiler executes conditional control statements(like if-else and switch case) faster than interpreter. Interpreter executes conditional control statements at a slower rate.
It takes more memory since the entire compiled code(object code) has to be reside in memory. Interpreted programs are more memory efficient as they do not generate any object code.
Compile once and run anytime, they doesn't need to run eveytime. Interpreted programs are interpreted line-by-line every time they are run.
Errors are reported after the whole program is checked for syntactical and other errors. Errors are 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 language are more efficient but difficult ot debug. Interpreted language are less efficient but easy to debug.
Examples of programming languages that use compiler are C, C++, COBOL, JAVA. Examples of programming languages that use interpreter are BASIC, Python, PHP, Perl, LISP.