Technology

How to Build Your Own Programming Language (Yes, Really)

Martin HollowayPublished 2month ago3 min readBased on 3 sources
Reading level
How to Build Your Own Programming Language (Yes, Really)

Peter Norvig, a renowned computer scientist, recently published a tutorial called "How to Write a (Lisp) Interpreter (in Python)". It explains how to build a working programming language from scratch—specifically, a language called Lisp—using Python. You might think building a language is impossibly complex, but Norvig's version does it in fewer than 100 lines of code.

Norvig is not a random internet tutorial writer. He co-authored Artificial Intelligence: A Modern Approach, a textbook used in universities worldwide, and was Director of Research at Google. When someone with that track record explains something, it comes with real-world credibility.

Here's what happens inside an interpreter: when you write code, a program needs to turn your words into actions. This happens in three stages. First, the interpreter reads your code and breaks it into individual pieces—like how a human reads a sentence word by word. This is called lexing. Second, it checks that those pieces fit together in a valid way, like checking that a sentence has proper grammar. This is called parsing. Third, it actually runs the code. This is called evaluation. Norvig's tutorial walks through all three stages and shows how little code you actually need.

The Lispy interpreter handles the core features you would expect: it can define variables, create functions, make decisions with if-statements, and do math. The whole thing is so compact because Norvig stripped away everything that is not essential, leaving only the parts you need to understand how interpreters work.

Norvig then wrote a second article, "An ((Even Better) Lisp) Interpreter (in Python)", that adds more features to make the interpreter faster and easier to use in real situations. This shows a common pattern in programming: first get something working, then make it better.

You can also download lis.py, the actual working code, and run it yourself.

Why Lisp. Lisp is an unusual language because code and data look the same. If you have worked with other languages like Python or JavaScript, this probably sounds strange. But it is this sameness that makes Lisp easy to explain and build. When code and data share the same shape, you can write an interpreter for it in a way that mirrors the language itself—which is why Lisp has been the go-to teaching tool for decades.

The practical value here is wider than just Lisp. Any programmer who has built a tool with a custom language—maybe a configuration file language or a set of rules that gets evaluated—has essentially done what Norvig is explaining. Seeing the whole process fit in 100 lines forces you to confront what you actually need, versus all the complexity you probably add without thinking.

For anyone curious about how programming languages work, or who wants to understand what sits under the hood of the tools they use every day, this tutorial is a good place to start. If you want to go deeper, there are other books and projects that build on these same ideas, but Norvig's explanation is where most people should begin.