Difference WikiComputers

Difference Between Compiler and Interpreter

Primary Difference

The compiler and interpreter both translates the higher level language programs, the difference lies that a compiler compiles the source code into an executable machine code whereas an interpreter interprets each instruction and executes it without producing any machine/object code. The compiler work is a onetime go, once a program is compiled; it can be saved for a later time execution whereas interpreter has to interpret every time, the program runs. Object code is generated in case of compiler whereas no object code is produced in interpreter; it only produces an intermediate code. Compiler processes the program on the whole but an interpreter processes it instruction by instruction. In compiler, program execution is fast and in case of interpreter it’s slower because statement by statement interpretation and execution is time consuming. In compiler, debugging process is difficult as compared to the debugging in an interpreter. Compiler does not require source code at run time but in case of interpreter complete source code file is required to execute a program. Compiler requires more memory because the machine code generated is quite large but in case of interpreter, no extra memory is needed. In compilers, the errors in a program are displayed after the complete source code is analyzed but in case of interpreter, errors are displayed for every line interpreted. The compiled code is executed by the computer hardware in case of compilers whereas in interpreters, the intermediate code is processed by another program. In programming scenario, the compiler checks the program’s syntax but interpreters verify the keywords of a program. In compilers there is a scope of code optimization and interpreters allow the modification of code at run time. Both of these are commonly in use by programmers and both possess their own specifications and advantages.

ADVERTISEMENTS

Comparison Chart

InterpreterCompiler
InputInterpreter takes single instruction as input.Compiler takes entire program as input.
Object CodeNo Intermediate Object Code is generated in Interpreter.Intermediate Object Code is produced in Compiler
Control StatementsA sluggish execution of Conditional Control Statement in Interpreter.Conditional Control Statements are executed quickly in Compiler
ConversionHigher level program is converted into lower level program every time.Program does not need to get compiled every time in Compiler.

Definition of Compiler

A compiler is a specialized program that processes the source code written in some higher level language into computer understandable machine code. This machine code is actually in binary language that a processor understands and executes. To write a source code, the programmer writes the program in a language like C, C++ or Pascal using some programming editor. This program is then executed using a compiler that is appropriate for the language in which the source code is written. A compiler’s input is a complete program; it first analyzes it and then processes it. It performs a number of analysis on the source code given as an input, the lexical and syntactical analysis. After performing both these steps the final task of compiler is to generate the machine code. The output of this compilation is the object code and is executable. The program is compiled once and do not need to be compiled every time the program runs.

ADVERTISEMENTS

Definition of Interpreter

An interpreter is a program that performs the statement by statement (line by line) translation of the program source code written in some higher level language. An interpreter, when given a program it takes its one line, interprets it and then executes it. Interpreter generates an intermediate code after interpreting source code and therefore executes it. There is no compilation stage and no machine code is generated. This is how interpreter translates and runs the whole program line by line. It is preferred when immediate instruction by instruction execution is required. They are useful especially when code testing is done. Every time, when a program is to make run, the interpreter interprets it the same way.

ADVERTISEMENTS

DifferenceS in a Nutshell

  1. Compiler processes the whole program; interpreter interprets code line by line.
  2. Compiler produces a binary machine code; interpreter generates an intermediate code.
  3. Compiler machine code can be saved and reused once compiled; interpreter has to interpret source code every time.
  4. Compilers examines the validity of code syntax; interpreters checks for the keywords.
  5. In compiler, program execution is fast; in interpreter program execution is slow.
  6. Debugging is complicated in compilers; debugging is easy in interpreters.
  7. Compilers display errors after checking complete source code; interpreters display errors of each instruction in code in the specified sequence.
  8. Compiler’s machine code is further processed by hardware; interpreter’s intermediate code is processed by another specialized program.
  9. Compilers do not require source code file on the time of execution; interpreters need source code file for run time execution.
  10. In compilers, execution of program is done after compilation stage; interpreters directly execute the program without any compilation.
  11. Compiler uses more memory; interpreter requires less memory.

Conclusion

Computer architecture and understanding terms associated to it can be a troublesome task and these two terms above are similar ones which have various differences between them but always seem similar to each other. This article has, therefore, looks to explain the differences between them to help people create a clear understanding.

Harlon Moss

Harlon currently works as a quality moderator and content writer for Difference Wiki. He graduated from the University of California in 2010 with a degree in Computer Science. Follow him on Twitter @HarlonMoss