Change the future

Friday 12:10 p.m.–12:55 p.m.

So you want to write an interpreter?

Alex Gaynor

Audience level:


You're a programmer, you use interpreter and compilers every day (and twice on Sundays!). But how do these things work? Could you build one yourself? What would it take? Where would you start? This talk takes you through the process, from lexing to interpreting, and leaves you ready to start on your own language!


This talk is a) going to be at a breakneck pace, just enough of each step of the compilation pipeline to really be able to understand it, b) going to use PyPy's infrastructure for the implementation (it goes without saying all code is in Python).

  • Steps in an interpreter
    • Lexing
    • Parsing
    • AST construction
    • Bytecode compilation
    • Interpretation
    • Object model construction
  • Lexing
    • Regex all the things
  • Parsing
    • Syntax construction
    • Precedence rules ("tree climbing")
  • AST construction
    • Abstract tree vs. syntax tree
  • Bytecode compilation
    • Creating arrays of constants and local variables.
    • Designing a bytecode.
  • Interpretation
    • Implementing your bytecodes
  • Object model
    • Building your objects
    • This will feature some nifty Python metaprogramming

At the end of the talk, attendees are going to walk away with an interpreter for a tiny subset of javascript which is actually very similar to the CPython and PyPy interpreters in design, they'll also walk away with the ability to add new features to the language, and places to look to do really cool things like add a JIT.