The Interpreter Codex
Evaluating expressions in a domain-specific esoteric language.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Linguistics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
module InterpreterPattern where
open import Data.Nat
data Expr : Set where
Lit : ℕ → Expr
Add : Expr → Expr → Expr
eval : Expr → ℕ
eval (Lit n) = n
eval (Add e1 e2) = eval e1 + eval e2
The Interpreter Codex
To command archaic alien artifacts, we must speak their language. The Interpreter Codex defines an Abstract Syntax Tree (AST) and the arcane semantics to map it to reality.
The Dependent Runes
This pattern is the very soul of languages like Agda. We write deeply typed inductive graphs (Expr) and mathematically sound evaluators (eval).
Runic Tags:
#agda
#interpreter
#ast