Before Discussing interpreter, we should be aware about the compiler and interpreter
- 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
- 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.
- 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.
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.
Job boss🌹
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)
Good job :)