0% found this document useful (0 votes)
16 views

python 2

goofd

Uploaded by

skhan660954
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

python 2

goofd

Uploaded by

skhan660954
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Compiler– What is Compiler?

 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.

Advantage of compiler – Advantages of compiler


Following are the advantages of compiler-
1. The compiler can execute the entire program or source code at one time.
2. The compiled program runs very fast.
3. There is less chance of errors in the compiler.
4. The compiler optimizes the program so the code requires less memory.
5. The compiler shows the error to the programmer.
6. In this the programs remain safe and no hacker can hack these programs.
7. In this the utilization of CPU is more.
8. It is supported by many high-level languages such as C++, JAVA, C# etc.

Disadvantages of compiler – Disadvantages of compiler


The disadvantages of compiler are given below-
1. The compiler is not flexible.
2. It is difficult to debug the program in this.
3. It is difficult to find errors in this.
4. If there is any change in the program then the entire program has to be compiled again.
Types of compiler – Types of compiler
There are two types of it-
1. One Pass compiler – This compiler reads the code only once and translates it.
2. Multi pass compiler – This compiler reads and translates the code many times.
Interpreter – What is Interpreter?
 Interpreter is a computer program that converts code written in high-level language into machine
language.

 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.

 The interpreter was first used in 1952.

 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.

How does the interpreter work?


Before writing any program, the memory is loaded in the interpreter. After this we start writing the
program. As we start writing code in high level language, the interpreter checks that code.
If you make a mistake while writing, the interpreter bolds that line so that you can correct that code.
When there is no mistake then the interpreter converts it into machine language.

Advantages of Interpreter in Hindi (Advantages of Interpreter )


1. It is very easy to debug the code through this because it reads the code line by line.
2. By checking line by line, it becomes much easier to find mistakes.
3. It does not create a separate file like a compiler. Due to which the memory usage is reduced
considerably.
4. You can stop the interpreter at any time and correct the code.
5. There is very little chance of mistake in this.

Disadvantages of Interpreter in Hindi – Disadvantages of Interpreter


1. It works much slower than the compiler.
2. Its security is very weak.
3. To execute the source code in the computer, we have to install the interpreter.

Assembler – What is Assembler?


 Assembler is a computer program that helps in converting the code written in assembly language
into machine language.

 In other words, “Assembler is a program that converts assembly language into machine
language.”

 Assembler is sometimes also called compiler of assembly language.


Types of Assembler– Types of Assembler
1:- One-Pass Assembler - This is a type of load-and-go assembler. Which converts assembly code into
machine code in one go. There is no need to work on it again and again.
2:- Multi-Pass/Two-Pass Assembler - In this, assembly code is converted into machine code many
times. It requires repeated work.

Advantages of Assembler – Advantages of Assembler


1. Through this, difficult tasks can be completed easily.
2. It requires less memory space.
3. Its working speed is fast because its execution time is less.
4. It is used to complete important work on time.
5. There is no need to track the memory location.
6. It is flexible.

Disadvantage of Assembler – Disadvantages of Assembler


1. It takes a lot of time and effort to write code in it.
2. Assemblers are not easy to understand. They are very complex.
3. It is very difficult to remember the syntax in this.
4. To run a long program in assembly language, more memory space has to be used.

Difference between compiler, assembler and interpreter in Hindi – Difference between compiler,
assembler and interpreter
Compiler Assembler Interpreter

It scans the entire program and converts


It scans the program in
the entire program into machine code in It scans the program line by line.
phases.
one go.

In this also it takes a lot of time to analyze


It takes a lot of time to analyze the It takes very less time to
the source code. But the process is executed
source code. scan the source code.
quickly.

It does not require much


It requires more memory space. It does not require much memory space.
memory space.

It finds the errors after scanning the The assembler finds


It finds mistakes line by line.
entire program. errors in phases.

While working with it, we face a lot of Difficulties are faced


Debugging is quite easy with this.
problems in debugging. while debugging.

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:

Feature Interpreter Compiler

Execution Line-by-line Entire code at once

Speed Slower for large programs Faster after compilation

Error Detection Immediate (on line of error) Errors detected after complete compilation

Example Languages Python, JavaScript C, C++, Java (compiled to bytecode)


Real-world Example:

 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.

You might also like