python 2
python 2
Compiler is a program that converts the code written in high level language into low level
language so that the program can be executed easily.
In other words, “Compiler is a language translator which translates the code of high level
language into machine language.”
The compiler converts the entire high level language code into machine language at once.
Whereas the interpreter converts each line into machine language.
The source code is converted into object code by the compiler. If there is any error in the source
code then the compiler cannot convert the source code into object code.
Compiler is more intelligent than interpreter because it translates the entire source code at once.
Programming languages such as C++, JAVA , C, C# etc. use compilers to translate their
programs.
It converts the code into machine language line by line. If there is an error in any line, it does not
translate the code further until that error is corrected.
The interpreter checks each line of code carefully. If the line is correct, it converts it directly into
machine language.
High level language can only be understood by humans. We also call it source code. On the other
hand, a computer can only understand programs written in binary language. That is why an
interpreter and compiler are required.
In other words, “Assembler is a program that converts assembly language into machine
language.”
Difference between compiler, assembler and interpreter in Hindi – Difference between compiler,
assembler and interpreter
Compiler Assembler Interpreter
Some examples of compilers are C and Some examples of this Some of its examples – Ruby and Python
C++ etc. are – GAS, GNU etc. etc.
Interpreter aur Compiler dono programming tools hain jo source code ko machine-readable
format me convert karte hain, lekin unka kaam karne ka tareeka alag hota hai. Let's explain in
Hinglish:
Interpreter
Interpreter ek program hai jo source code ko line-by-line execute karta hai. Matlab, jab aap code
likhte ho aur run karte ho, toh interpreter har line ko ek-ek karke read karta hai aur turant usse
execute kar deta hai.
Example:
Python ek interpreted language hai. Agar aap Python me koi code likhte ho, toh interpreter us
code ko directly read karta hai aur turant execute kar leta hai.
Example in Python:
python
Copy code
print("Hello, World!")
Jab aap yeh Python code run karte ho, interpreter line by line execute karta hai aur turant output
de deta hai:
Copy code
Hello, World!
Advantages:
Faster execution for small programs: Code ko line-by-line execute karte hain, toh small programs
me jaldi result mil jata hai.
Error detection: Jab error aata hai, interpreter turant us line par rok leta hai aur bata deta hai ki
kaha error hai.
Disadvantages:
Slower execution: Larger programs ke liye slower hota hai kyunki har line ko individually interpret
karna padta hai.
Re-execution required: Har baar jab program run karte ho, interpreter code ko dobara se process
karta hai.
Compiler
Compiler ek program hai jo poore source code ko ek saath machine code ya intermediate code
me convert kar deta hai. Matlab, jab aap code compile karte ho, toh compiler poora program
pehle se read kar leta hai aur ek output file (like .exe in C++) generate karta hai.
Example:
C ek compiled language hai. Agar aap C me code likhte ho, toh pehle aapko code ko compile karna
padta hai. Compiler source code ko machine code me convert kar deta hai aur fir aap usse directly
run kar sakte ho.
Example in C:
c
Copy code
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Aap jab is code ko compile karte ho, compiler poora program ek baar me read karta hai, fir
machine code me convert karta hai aur ek executable file (e.g., a.exe) banata hai. Jab aap us
executable file ko run karte ho, output milta hai:
code
Hello, World!
Advantages:
Faster execution: Ek baar compile karne ke baad, program ko baar-baar run karne par speed fast
hoti hai kyunki already machine code me convert ho chuka hota hai.
Error handling: Compiler code ko puri tarah se check karta hai aur syntax errors ko compile hone
se pehle detect kar leta hai.
Disadvantages:
Longer compilation time: Source code ko ek baar me compile karne me time lagta hai, jo large
programs me zyada hota hai.
Requires recompilation for changes: Agar aap source code me koi changes karte ho, toh aapko
phir se code ko compile karna padta hai.
Summary:
Error Detection Immediate (on line of error) Errors detected after complete compilation
Interpreter: Python code ko execute karte waqt, Python interpreter line by line read karke directly
output deta hai.
Compiler: C language me, pehle aapko code ko compile karna padta hai, fir executable file banane
ke baad program run hota hai.
In simple words, interpreter code ko turant execute karta hai, jabki compiler poore code ko pehle
process karke output banata hai.