⚙️ ISABELLE RUNE DIFFICULTY: Archmage Behavioral

The Interpreter

Given a formal language, define a representation for its grammar along with an interpreter that evaluates it.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Abjuration // Semantics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ISABELLE PATTERN //
theory Interpreter
  imports Main
begin

datatype expr =
    Const nat
  | Add expr expr
  | Mul expr expr

fun eval_expr :: "expr \<Rightarrow> nat" where
  "eval_expr (Const n) = n"
| "eval_expr (Add e1 e2) = eval_expr e1 + eval_expr e2"
| "eval_expr (Mul e1 e2) = eval_expr e1 * eval_expr e2"

end
Runic Tags: #isabelle #hol #abjuration #design-patterns