Difference between Compiler and Interpreter: Interpreter vs Compiler.
Both compiler and interpreter are Language processor that translates high-level language into machine level language( 0,1). The program codes written in high-level languages are in plain English languages. Below is the sample code written in high-level language( QBASIC).
REM TO input a word and check whether the word is palindrome or not Cls INPUT “Enter a word”;w$ For I = LEN(w$) to 1 step -1 Palin$=Palin$+mid$(w$,I,1) NEXT I IF UCASE$(W$) = UCASE$(palin$) THEN PRINT w$;”Is a Palindrome” ELSE PRINT w$;” Is not palindrome” ENDIF END
The Key difference between Compiler and Interpreter.
- Working:
The way compiler work is different from Interpreter. When a block of codes needs translation through Compiler, It converts all the codes to machine language at once. The Compiler first reads a whole block of codes, converts it into executable machine code, and then runs the code. Therefore, in case of any bugs or errors in the program codes, all errors are listed at the end after the completion of a compilation process.
On the other hand, Interpreter is a language processor that converts the high-level program codes into machine language line by line. Unlike a compiler, an interpreter reads one line code, translates and execute the another line of codes. Therefore in case of any errors, the translations process is interrupted. The programmer needs to remove the error and the program needs to run from the beginning.
- Speed:
Since compiler translates all the codes at once. The translation process is faster as compared to Interpreter.
An Interpreter is slower while translating as it only converts one line at a time.
Difference between compiler and Interpreter in Table.
Interpreter | Compiler |
An Interpreter translates High-level language code on to machine instruction line by line. | Compiler translates the whole block of code at a time |
It reports the error at each line. | All errors are listed at the end after compilation of code |
The program must be translated each time when execution is required | No need of re-translation |
Interpreter is slower than compiler | Compiler is faster |
It uses less resources of computer | Compiler uses comparatively less resources |
Interpreter is smaller in size | It is larger in size |
QBASIC uses Interpreter | C, C++, Java etc uses Compiler |
Key Terms:
The Compilation is a process of converting source code into object code.
A Source code is a program written in high-level programming languages.
After the compilation of source code, the result obtained is a code equivalent to machine code, which is known as Object code.