⚡ ZIG ALCHEMY DIFFICULTY: Adept Behavioral

The Interpreter: Lexicon of the Ancients

Given a language, define a representation for its grammar along with an interpreter.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Lexicography
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// BLAZING-FAST ZIG ALCHEMY //
const std = @import("std");

pub const Context = struct {
    vars: std.StringHashMap(u32),
};

pub const Expression = struct {
    vtable: *const VTable,
    pub const VTable = struct {
        evaluate: *const fn (self: *Expression, ctx: *Context) u32,
    };
    pub fn evaluate(self: *Expression, ctx: *Context) u32 {
        return self.vtable.evaluate(self, ctx);
    }
};

To speak with the stars, one must parse their dead languages. The Lexicon of the Ancients defines syntax trees where every node acts as an Expression. Evaluating the root node walks the tree, transmuting symbolic arcane grammar into raw executable Zig routines.

Runic Tags: #interpreter #behavioral #zig #grammar