Deep Python Concepts.

Deep Python Concepts.

Before Discussing interpreter, we should be aware about the compiler and interpreter

What is a compiler?

  • A compiler is a set of programs that compile (translate) source code of a program into machine language instructions.
  • Compiler compile the whole source code in a single go.
  • It is best suited for production environment
  • Languages like C, C++, C#, java use compilers

What is an interpreter?

  • An interpreter is a set of programs that executes the program line by line
  • It does not generate machine code, instead it executes Byte code.
  • It is best suited for software development
  • Languages like Python, php, Perl use interpreter.

WORKING OF COMPILERS AND INTERPRETERS.

how Compiler works?

  • Compiler resides in RAM. Our Source code present in ROM.
  • When program run compiler compile (Translate) the program into machine code and store it in memory (RAM)
  • When compilation get complete then processor fetch instructions of compiled machine code and executes these instructions to give output. 

Pictorial representation.

No alt text provided for this image

How Python Interpreter works?

  • Python source code resides in ROM while interpreter in RAM.
  • When we run a python program it goes to python interpreter
  • There are two sections in python interpreter. First is compiler and the second is PVM.
  • Compiler compile the program into the intermediate language (Byte code) not in the machine code. No processor can understand this bytecode.
  •  After that this byte code is goes to PVM which in known as python virtual machine that will execute this program.

No alt text provided for this image

Thanks for reading,

Regards: ALI AHMAD

References

https://www.youtube.com/watch?v=BkHdmAhapws

https://medium.com/@dpthegrey/what-is-interpreter-explain-how-python-interpreter-works-125205c1f8d6



Compilation happens in RAM/Processor, but compiled program can reside in ROM. C# & Java don't compile the program in single go, they turn it into byte code (intermediate language between machine code and source code)

To view or add a comment, sign in

More articles by ALI AHMAD

Explore content categories