Writing a Python interpreter from scratch, in half an hour.
Tushar Sadhwani (~tushar29) |
Description:
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.
The topics we'll be going through to build this interpreter:
- Lexing an indentation based language
- Why
Indent
andDedent
need to be tokens - Writing a Recursive Descent parser
- Parsing literals:
int
s, strings, lists, dictionaries - Parsing expressions
- Parsing function calls -
print("Hello world!")
- A tree-walk interpreter
- Interpreting assignments and
print()
statements - Running
json.loads()
from scratch
Prerequisites:
People are expected to be able to read Python code. There are no other major pre-requisites. The interpreter will not be using any libraries, kr require knowledge about parsers or compilers.
Content URLs:
Slide deck: https://slides.com/tusharsadhwani-1/deck
GitHub link of the interpreter: https://github.com/tusharsadhwani/interpreted
Speaker Info:
Long term Python user, contributor, author and speaker.
I've contributed to various Python and PSF projects, such as cpython, black, mypy, pip, and pypi.org.
Currently working at DeepSource, maintaining their Python code analysis stack.