UP | HOME

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 defmethod with 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 .rkt file, checks #lang racket header, 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

  1. Open src/{name}.lisp; define uiop:define-package, export symbols.
  2. Add (:file "{name}") to tolk.asd.
  3. Add tests/{name}.lisp.
  4. Add (:file "{name}") to test system in tolk.asd.
  5. Run (asdf:test-system :tolk).

Sources

Related

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