Difference Between Compiler And Interpreter
Computers can understand only machine level language which can be written using 0's & 1's. It is difficult to write and maintain programs in machine level language. The present languages such as C, C++, Java, Scala all are high level languages which can be understand by humans. Computers can not understand higher level languages. The programs written in high level languages need to converted into machine level language using translators.
Translators are just computer programs which accept a program written in high level or low level language and produce an equivalent machine level program as output. Translators are of three types.
Compiled programs are translated into the machine language of the target computer. Interpreted Programs are either kept in their original source code or are pre compiled into an intermediate form, in both cases an interpreter is required to translate the program into machine code at runtime. Where as the compiled program is "ready to go".
Translators are just computer programs which accept a program written in high level or low level language and produce an equivalent machine level program as output. Translators are of three types.
- Assembler
- Compiler
- Interpreter
Assembler is used for converting the code of lower level language ( assembly language) into machine level language.
Compilers and interpreters are used to translate the code of high level language into machine language. The high level program is known as source code and the corresponding machine level program is known as object code. Although compiler and interpreter perform the same task but there is a difference in their working.
A compiler is nothing but a computer program written in some other programming language such as Pascal or C. compiler searches all the errors of a program and lists them. If the program is error free then it converts the code of program into machine code and then the program can be executed by separate commands. some popular compilers are gcc compiler to compile c source code, javac for java source codes.
An Interpreter is a computer program that directly executes i.e without compiling. An Interpreter checks the errors of a program statement by statement. After checking one statement, it converts that statement into machine code and then executes that statement. The process continues until thee last statement of program occurs. Interpretation does not replace compilation completely. It only hides it from the user and makes it gradual.
REPL (Read, Evaluate, Print, Loop) is a command line interpreter which can execute simple block of code with out need of creating source file. Virtual machines such as VMWare, Virtual Box are also interpret instructions of guest Os on host Operating system. A CPU is also an interpreter which executes machine instructions one by one.
Differences :
Compiled programs are translated into the machine language of the target computer. Interpreted Programs are either kept in their original source code or are pre compiled into an intermediate form, in both cases an interpreter is required to translate the program into machine code at runtime. Where as the compiled program is "ready to go".
The compiler generates success / error report after the translation of entire page while an interpreter stops the translation once it gets the first error. In this perspective the interpreter wins , because comparatively interpreter takes less time in analysis and processing of higher level language code.
Besides processing and analyzing time the overall execution time of a code is faster for compiler relative to the interpreter.
A small video depicting differences between Compiler and Interpreter
Comments
Post a Comment