Writing a simple Lisp interpreter in Rust

David Delassus
24 min readMar 2, 2023

Lisp is a family of multi-paradigm programming languages (functional, procedural, reflective, …), which can be similar to Lambda Calculus. The name stands for “list processing”.

The syntax is based on the concept of S-Expression (short for: Symbolic Expression). The code is therefore organized in a tree-like data structure. In Lisp, code is data, and data is code.

In this article, we will write a very simple (non standard?) Lisp interpreter in Rust. This will be a great way to explore the Rust ecosystem, and what it can do for us, language designers.

The interpreter will be split in 3 parts:

  • the frontend, to parse S-Expressions
  • the backend, to evaluate the S-Expressions
  • the REPL, to provide a simple CLI to execute Lisp code

NB: All the code present in this article is available in this repository:

Part 1: Parsing S-Expressions

Lisp usually defines 3 types of data:

  • atoms: symbols, numbers, booleans
  • strings: delimited by double-quotes
  • lists: delimited by parenthesis

--

--