Skip to content
Lesson 2 of 13

Step 1 of 5 · Reading · ~1 min

Read

Reader & S-Expressions

Parse to AST

After tokenizing, parse the token stream into nested lists (the Lisp AST is just a tree of nested lists).

python

That's it. The recursive descent is trivial because Lisp's grammar is essentially just nested lists.

Example:

(* (+ 1 2) (- 5 3))
parses to
['*', ['+', 1, 2], ['-', 5, 3]]

The AST is just nested Python lists. No fancy AST node classes. This is the homoiconicity advantage — code lives as a data structure your interpreter already understands.

Round-trip: a print function (unparse) walks the tree and outputs (...) text. Read → Parse → Eval → Print → REPL.

Up nextEval: Numbers & SymbolsEvaluator

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…