How Python Compiler Works

preview_player
Показать описание
Can you tell me how Python compiler works?

In general, it doesn't.

This is Python, not Java.

Traditional programming languages like Fortran and major ones today like C++ use compilers. Python uses an interpreter.

What is the difference?

An interpreter interprets the Python code as it is run, AKA run-time. You don't lose programming time compiling the code to create an executable.

You also slow down the code because it has to be interpreted every time.

You can swap out modules as the interpreter is running, or update a module when the run-time fails before testing it again. In that regard, the Python interpreter supports rapid prototyping and debugging.

It also does not use the variables until they are called in run-time. So you don't get all issues debugged until after it runs.

You also do not get the confusion about where in the code the bug is. Or make the mistake that because it compiled, the code must be good.

But I've heard about a Python compiler.

Maybe they were confusing the interpreter for a compiler, since both do execute the code in their own fashion. Or they were thinking of another language.

No, I heard Python.

CPython is a C-Python hybrid, and it uses a compiler.

How do compilers work?

For CPython, the source code is parsed into a parse tree before the bytecode is emitted based on the parse tree.

The way you say that, you imply that is not standard.

Traditionally, the source code is broken up into tokens; this is called lexing. Then it gets parsed to a parse tree or abstract tree.

That's getting too abstract for me.

After the abstract syntax tree is generated, it is transformed into a control flow graph by Python hybrid languages or optimized by the compiler. Then the parse tree is used to generate machine instructions or JVM code in the case of Java.

No wonder Python tries to avoid all those steps with an interpreter.
Рекомендации по теме
Комментарии
Автор

the most appropriate place to discuss about Python :)

sabr
Автор

this was extremely helpful. Thank you very much

RebeliousSapien
Автор

"An interpreter interprets the Python code as it is run"....Awesome

Landofjello
Автор

The title of this video is a bit misleading then...

bsncomputing
Автор

i should try this on a movie queue. Hope she would explain without slapping

SupunKandambige