Skip to main content
  1. Series/

Mtg-Compiler

Why compile Magic: The Gathering?

·1 min

Placeholder. This page exists to validate the site setup (layout, code highlighting, the series hub). Replace the body with the real write-up.

Magic: The Gathering has tens of thousands of unique cards, each carrying rules text written in a semi-formal natural language (“Oracle text”). A first taste of the data we are working with:

Parsing Oracle text into a typed AST

·1 min

Placeholder. This page validates Mermaid diagram rendering. Replace the body with the real write-up.

The front end turns raw Oracle text into a typed abstract syntax tree:

flowchart LR A[Oracle text] --> B[Lexer] B --> C[Tokens] C --> D[Parser] D --> E[Typed AST]

Each stage gets its own treatment: how the lexer handles reminder text and mana symbols, and how the grammar copes with the long tail of one-off templating while still producing a well-typed tree.

A symbolic, LLM-facing DSL

·1 min

Placeholder. Scaffolding for the series. Replace the body with the real write-up.

The typed AST round-trips to a compact symbolic DSL — the surface an LLM generates against, then back to an AST that is guaranteed to parse:

Modeling effect cost

·1 min

Placeholder. This page validates KaTeX math rendering. Replace the body with the real write-up.

Once a card is a typed tree, we can score it. Model a card’s cost as the sum of its effects’ costs, each weighted by how often it triggers:

mtg-compiler

·1 min

mtg-compiler turns the natural-language rules text printed on Magic: The Gathering cards — their Oracle text — into a typed AST and a symbolic, LLM-facing DSL, and back again. That representation is what makes grammar-constrained card generation possible: an LLM emits structured, valid cards instead of free-form text that may not parse or resolve.