Writing a Python interpreter from scratch, in half an hour.
- Level:
- intermediate
- Room:
- pycharm (forum hall)
- Start:
- Duration:
- 45 minutes
Abstract
You use the Python interpreter every single day. It does a lot of things for you: checks that your code has valid syntax and is properly indented, imports modules from various locations, and runs your code instruction-by-instruction.
But if you've ever wondered how exactly it happens, this talk will teach you the entire process, by building a working python interpreter from scratch.
TalkPython Internals & Ecosystem
Description
The plan is to write a really simple, but working Python interpreter that can run Python code, from scratch.
The topics we'll be going through to build this interpreter:
- Lexing an indentation based language
- Why
Indent
andDedent
need to be tokens
- Why
- Writing a Recursive Descent parser
- Parsing literals: ints, strings, lists, dictionaries
- Parsing expressions
- Parsing function calls -
print("Hello world!")
- Semantic analysis: removing invalid code
- A tree-walk interpreter
- Interpreting
print()
statements - Running
import
statements - File I/O: implementing
open()
calls
- Interpreting
- Running
json.loads()
andjson.dumps()
from scratch