By EuroPython Conference ยท 9/19/2023
In this video, Tushar Sadhwani explains how a Python interpreter works by building a simple interpreter from scratch. The goal is to demystify the process of creating a programming language and encourage contributions to Python, which has been around for 32 years and has many contributors. Watch the introduction.
The session begins with a story about wanting to create a JSON parser similar to Python's built-in functionality. The parser will take a string and extract structured data from it. The first step is tokenization, which involves breaking the string into meaningful components. Learn about tokenization.
The tokenizer identifies different parts of the string, such as braces and colons, and creates tokens. This process is guided by the JSON specification, which defines the structure of JSON objects. Explore the tokenizer function.
Once tokenized, the parser processes these tokens to create a structured representation of the data. It uses recursive descent parsing to handle nested structures effectively. Understand the parsing phase.
After building the JSON parser, Tushar transitions to creating a Python interpreter. The interpreter consists of three main components: the tokenizer, the parser, and the execution engine. Get an overview of the interpreter.
The Python tokenizer is similar to the JSON tokenizer but includes additional features like handling new lines and indentation, which are crucial in Python syntax. Discover the tokenizer's role.
The parser converts the tokenized input into a nested data structure, known as an abstract syntax tree (AST). This structure represents the program's logic and flow. Learn about the parsing process.
The interpreter executes the AST by visiting each node and performing the corresponding operations. This involves a visitor pattern to handle different types of nodes effectively. See how execution works.
Tushar concludes by emphasizing that while this implementation is a simplified version of a Python interpreter, it lays the groundwork for further enhancements. He encourages viewers to explore the resources available for deeper understanding. Watch the conclusion.
11/11/2022
8/26/2020
8/4/2021
10/29/2018
8/27/2021
12/27/2024