Tolk
Table of Contents
Definition
Tolk is the Common Lisp interpreter library developed for the Advprog course. It implements a growing series of interpreters following PLAI's chapter structure, using Common Lisp / CLOS instead of Racket / plai-typed.
The name reflects its purpose: a tool for talking to (interpreting) programs.
Architecture
tolk/
src/
utils.lisp ← defmethod-bind, env/store utilities
parser-combinators.lisp ← parser combinator library
racket/
reader.lisp ← reads .rkt files
arith.lisp ← arithmetic interpreter (PLAI ch.3)
python/ ← Python subset interpreter
tests/
object-equality.lisp ← eqo structural equality
racket/arith.lisp ← arith tests
tolk.asd ← ASDF system definition
Key Abstractions
ast-node- Base CLOS class for all AST nodes.
defmethod-bind- Macro that combines
defmethodwith automatic slot binding via metabang-bind and closer-mop. See Defmethod-bind. eqo- Structural equality for AST nodes (used in tests). See fiveam.
empty-env/extend/lookup- Association-list environment utilities.
empty-store/override/fetch/new-location- Store utilities (for mutation, later chapters).
read-racket-file- Reads a
.rktfile, checks#lang racketheader, returns list of s-expressions.
Dependencies
| Library | Purpose |
|---|---|
trivia.quasiquote |
Pattern matching with quasiquote |
fare-quasiquote |
Quasiquote patterns in trivia |
named-readtables |
Activates the fare-quasiquote readtable |
metabang-bind |
Slot binding (bind, bind-slots) |
closer-mop |
MOP introspection (for defmethod-bind) |
fiveam |
Unit testing |
iterate |
Iteration (iter) |
smug |
Parser combinators |
str |
String utilities |
Workflow for adding a new interpreter
- Open
src/{name}.lisp; defineuiop:define-package, export symbols. - Add
(:file "{name}")totolk.asd. - Add
tests/{name}.lisp. - Add
(:file "{name}")to test system intolk.asd. - Run
(asdf:test-system :tolk).
In This Cluster
| Page | Summary |
|---|---|
| Tolk Arith | The arithmetic interpreter (PLAI ch.3) |
| Tolk Python Language | Python fragment covered by the parser |
| Tolk Python AST | AST class hierarchy for Python |