/programming-language-development:language-design-parsing-and-typesfrom programming-language-development
Reference for designing a language or building a compiler front end: syntax, lexing, parsing (recursive descent, Pratt, LR), error recovery, CST vs AST, name resolution, modules, and type systems (inference, unification, traits, generics, ownership).
Ships in programming-language-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Part 1 of 5 of the Programming Language Development reference (plugin
programming-language-development), covering §0–§4. Sibling skills:language-irs-optimization-and-backends(§5–§7),language-runtimes-interpreters-and-jits(§8–§9),language-diagnostics-tooling-and-evolution(§10–§14),language-development-reference(§15–§20). Section numbers are shared across the set; a reference written as §N →skillpoints into that sibling skill.Currency: Verified August 2026. See §17 →
language-development-referencefor the currency snapshot and what goes stale first.
How to read this. Reference, not tutorial. Sections are independent. Three markers:
- [DURABLE] — theory, algorithms, or a lesson every language implementation has independently learned. Does not expire.
- [VERSIONED] — depends on a specific toolchain, standard, or project's current state. Verify against its docs.
- [CONTESTED] — competent language designers disagree, publicly and permanently. Both cases given.
⚠️ GOTCHA boxes mark the design mistakes that are cheap to make on day one and impossible to undo on day one thousand.
The framing that organizes everything below: a language is a set of promises you can never take back. Syntax you can deprecate. Semantics you cannot. Every hard decision in this document is really the question "what am I willing to be permanently responsible for?" — and the languages people love and the languages people resent are distinguished mostly by how carefully their designers answered it early.
SOURCE TEXT
│ LEXER ─────────── tokens (+ trivia, spans) §2
│ PARSER ────────── CST/AST (+ error recovery) §2
▼
FRONT END
│ NAME RESOLUTION ─ bind identifiers to declarations; modules, scopes §3
│ TYPE CHECKING ─── inference, coercion, trait/class resolution §4
│ SEMANTIC ANALYSIS ─ borrow/effect/exhaustiveness/definite-assignment §4.7
▼
MIDDLE END
│ LOWER to IR ───── SSA / CPS / ANF; desugar; monomorphize §5
│ OPTIMIZE ──────── inline, constant-fold, DCE, GVN, LICM, vectorize §6
▼
BACK END
│ INSTRUCTION SELECTION ─ IR → target instructions §7
│ REGISTER ALLOCATION ─── virtual → physical registers §7.3
│ SCHEDULING / EMISSION ─ object code, debug info §7
▼
RUNTIME + LINK ───── GC, scheduler, FFI, unwinding, dynamic loading §8
[DURABLE] The two most consequential structural decisions are made before you write a line of the pipeline:
language-irs-optimization-and-backends) Every serious compiler ends up with
at least three levels. Deciding this late means rewriting everything.language-diagnostics-tooling-and-evolution) A compiler designed as a batch
source-to-binary pipeline cannot be turned into a responsive language server without
substantial rearchitecture. Design for incrementality from day one or accept that you
will do it twice.| Asked about... | Go to |
|---|---|
| Should this be a language at all? Design philosophy, trade-offs | §1 |
| Lexing, parsing, grammars, error recovery, syntax design | §2 |
| Scopes, modules, imports, name resolution | §3 |
| Type systems, inference, generics, traits, effects, ownership | §4 |
| IR design — SSA, CPS, ANF, MLIR, lowering | §5 → language-irs-optimization-and-backends |
| Optimization passes and where they belong | §6 → language-irs-optimization-and-backends |
| Code generation, instruction selection, register allocation, backends | §7 → language-irs-optimization-and-backends |
| Runtime: memory management, GC, concurrency, FFI, exceptions | §8 → language-runtimes-interpreters-and-jits |
| Interpreters, bytecode VMs, JIT | §9 → language-runtimes-interpreters-and-jits |
| Error messages and diagnostics | §10 → language-diagnostics-tooling-and-evolution |
| Incremental compilation, IDE, LSP | §11 → language-diagnostics-tooling-and-evolution |
| Testing, fuzzing, formal verification | §12 → language-diagnostics-tooling-and-evolution |
| Standard library, ecosystem, tooling | §13 → language-diagnostics-tooling-and-evolution |
| Evolution, versioning, governance, deprecation | §14 → language-diagnostics-tooling-and-evolution |
| "Don't do this" | §15 → language-development-reference |
| "Which approach is better?" | §16 → language-development-reference (contested) |
| "Is this still current?" | §17 → language-development-reference |
| Books, papers, people | §18 → language-development-reference |
Answer these before implementation; each one propagates through the whole pipeline.
| Question | Options | Downstream consequences |
|---|---|---|
| Static or dynamic typing? | Static, dynamic, gradual | Determines whether the type checker is a phase or a runtime |
| Memory management? | Manual, RAII/ownership, refcount, tracing GC, region/arena | The single largest runtime-design driver (§8.1 → language-runtimes-interpreters-and-jits) |
| Compiled or interpreted? | AOT, JIT, bytecode VM, tree-walk, transpile | Determines the whole back end |
| Generics: monomorphize or erase? | Monomorphize (C++, Rust), erase (Java, Go pre-1.18), dictionary-pass (Haskell, Swift) | Code size vs. compile time vs. runtime cost (§4.5) |
| Concurrency model? | Threads+locks, async/await, actors, CSP, STM, structured concurrency | Colours your entire function type system (§8.3 → language-runtimes-interpreters-and-jits) |
| Mutability default? | Mutable, immutable, controlled | Affects optimization opportunity enormously |
| Nullability? | Nullable-by-default, option types, non-null-by-default | Tony Hoare's "billion-dollar mistake." Option types are the settled answer for new languages |
| Error handling? | Exceptions, result types, error returns, panics | Interacts with every ABI and FFI decision (§8.4 → language-runtimes-interpreters-and-jits) |
| Metaprogramming? | None, macros (hygienic or not), reflection, compile-time execution, templates | Determines whether your compiler is also an interpreter (§4.8) |
[DURABLE] Syntax is the least important part of a language and the part people argue about most. That said, it is the interface, and interfaces matter:
(a)*b ambiguity (cast or multiply? depends on whether a is a
type) is the canonical example.⚠️ GOTCHA — significant whitespace and tabs. If you choose indentation-sensitive syntax, you must specify the tab/space interaction exactly, at the lexer level, in version one. Python took until Python 3 to make mixing an error, and it caused real bugs for a decade.
⚠️ GOTCHA — reserve keywords generously. Adding a keyword later breaks every program using it as an identifier. Languages handle this with contextual keywords (complexity), editions (Rust — §14.2 →
language-diagnostics-tooling-and-evolution), or just breaking people. Reserve more than you need on day one.
Convert characters to tokens. The parts people underestimate:
é
and é are different identifiers), and bidirectional-override characters, which are a
security issue: the "Trojan Source" attack uses them to make source read differently
to a human than to the compiler. Reject or warn on bidi control characters in source.| Approach | Notes |
|---|---|
| Recursive descent + Pratt | The overwhelming choice of production compilers (GCC, Clang, rustc, Go, TypeScript, V8). Hand-written, readable, arbitrary lookahead, and — decisively — excellent error recovery and error messages |
| LL(k) generators (ANTLR) | Good tooling, good for DSLs; less control over errors |
| LALR generators (yacc/bison) | Compact, fast; conflicts are famously painful to debug; poor error messages |
| GLR / Earley | Handle ambiguous grammars; slower; useful for language research and for parsing C++ |
| PEG / packrat | Unambiguous by construction (ordered choice), linear with memoization; ordered choice silently hides ambiguity, which is a footgun |
| Combinators | Elegant, great for prototypes; error messages and performance need work |
[DURABLE] Essentially every widely-used production compiler uses hand-written recursive descent, and the reason is error recovery. A generated parser gives up or produces a generic message; a hand-written one can say "you forgot a semicolon here" and continue. Since the parser's output feeds an IDE that sees broken code 100% of the time, this is not a minor consideration.
Pratt parsing (top-down operator precedence) is the right technique for expressions: each token gets a binding power, and precedence and associativity fall out of comparing them. It's about 50 lines and handles prefix, infix, postfix, and mixfix cleanly.
[DURABLE] The parser's job is not to reject bad programs. It is to produce a usable tree from bad programs, because that is the input it receives most of the time.
;, },
or start-of-declaration and resume.Bind every identifier to a declaration. Sounds simple; is not.
[DURABLE] Module systems are where languages accrete the most regret, because module semantics touch compilation units, linking, versioning, packaging, and the file system all at once. The decisions:
| Decision | Options |
|---|---|
| Unit of modularity | File, directory, explicit declaration, package |
| Import granularity | Whole module, selected names, glob |
| Visibility | Public/private, pub(crate)-style graded, explicit export lists |
| Cyclic imports | Allowed (complicates compilation order), forbidden (simplifies everything) |
| Name-to-file mapping | Implicit (Java, Python) or explicit (Rust mod, C++ modules) |
| Separate compilation | Per-file, per-module, per-package, whole-program |
[DURABLE] Forbid cyclic module dependencies if you possibly can. They force whole-program analysis, complicate incremental compilation, and are almost always a design smell in user code. Go forbids them; the ecosystem is measurably healthier for it.
⚠️ GOTCHA — C++ modules are the cautionary tale. Standardized in C++20; GCC 16.1 (April 2026) still describes its C++20 modules support as experimental, requiring
-fmodules. Six years from standardization to "still experimental" in a major implementation is what happens when a module system must interoperate with a textual-inclusion legacy. Design modules before you have a legacy, not after.
| Axis | Options |
|---|---|
| Checked when | Static, dynamic, gradual, optional |
| Inference | None, local, bidirectional, global (HM) |
| Polymorphism | Parametric (generics), ad-hoc (overloading/traits), subtype, row |
| Subtyping | None, nominal, structural, both |
| Variance | Invariant, co/contravariant, declaration-site or use-site |
| Higher-kinded | No, yes (Haskell, Scala) |
| Dependent | No, limited (const generics, refinement), full (Idris, Lean, Agda) |
| Effects | Implicit, checked exceptions, monadic, algebraic effect handlers |
| Linearity | None, affine (Rust ownership), linear, uniqueness |
Hindley–Milner (Algorithm W) — full inference for the let-polymorphic lambda calculus. Unification-based, principal types, and no annotations required anywhere. The catch: HM does not survive contact with subtyping, higher-rank types, or type classes without significant extension, and its error messages are notoriously bad — unification fails at some arbitrary point far from the actual mistake.
Bidirectional type checking — the modern default. Split into two mutually recursive
judgments: checking (Γ ⊢ e ⇐ T, "does e have type T?") and synthesis
(Γ ⊢ e ⇒ T, "what type does e have?"). Annotations at the boundaries.
Local type inference (C#, Java, Go, C++ auto) — infer variable types from
initializers and generic instantiations from arguments; require annotations on function
signatures. [DURABLE] Requiring signature annotations is a feature, not a limitation:
it makes the code self-documenting, keeps errors local, makes separate compilation
tractable, and makes the IDE's job possible.
⚠️ GOTCHA — global inference and error locality are in direct tension. With full inference, an error in one function can surface as a type error in an unrelated one. Every language with global inference eventually adds a "please annotate your top-level definitions" lint. Consider just requiring them.
unify(a, b):
a, b = resolve(a), resolve(b) # follow substitutions (union-find)
match (a, b):
(Var x, Var y) if x == y -> ok
(Var x, t) | (t, Var x) -> occurs_check(x, t); bind(x, t) ← DON'T SKIP THIS
(Con(c1, as), Con(c2, bs)) if c1 == c2 && len equal -> zip-unify
_ -> type error (report BOTH sides and the location)
The occurs check prevents binding x := List<x>, which creates an infinite type. Skip
it and your compiler hangs or stack-overflows on a program like let f = fun x -> x x.
Use union-find with path compression for the substitution or unification is
accidentally quadratic.
Levels/ranks for generalization: the naive "generalize all free variables not in the
environment" is O(n) in environment size at every let. The standard fix is Rémy's
level-based generalization — tag each type variable with the let-depth at which it was
created and generalize only those deeper than the current level. Every efficient HM
implementation does this.
The mechanism for ad-hoc polymorphism, and it comes in three flavours:
Coherence and the orphan rule. If two crates can both implement Trait for Type,
which one applies? Incoherence breaks type-directed dispatch and can break soundness.
Haskell and Rust enforce coherence via the orphan rule: you may implement a trait for
a type only if you own the trait or the type. It is the single most-complained-about rule
in Rust and it is load-bearing.
Implementation strategies: dictionary passing (pass a vtable of the implementation —
Haskell, Swift), monomorphization (generate a specialized copy — Rust static dispatch), or
vtables at runtime (dyn Trait, Go interfaces).
⚠️ Trait resolution is a solver, and solvers have performance and termination problems. Rust's trait system is expressive enough that resolution can loop or blow up exponentially. [VERSIONED] rustc has been building a next-generation trait solver for years precisely to fix long-standing soundness bugs, unblock features (implied bounds, negative impls), and improve compile times; it reached production use in coherence checking and, as of 2026, stabilization work continues alongside Polonius (the next-generation borrow checker). The lesson for a language designer: an expressive trait/instance-resolution system is a Prolog interpreter in your compiler. Budget accordingly.
[CONTESTED, and one of the genuinely load-bearing decisions.]
| Monomorphization (C++, Rust) | Erasure / dictionaries (Java, Haskell, Swift) | |
|---|---|---|
| Runtime cost | Zero — specialized code, inlinable | Indirection: boxing, vtables, dictionaries |
| Code size | Explodes — one copy per instantiation | One copy |
| Compile time | Slow — the dominant cost in large Rust and C++ builds | Fast |
| Separate compilation | Hard — need the generic body available | Clean |
| Reflection on type args | Available | Erased (Java's List<T> doesn't know T at runtime) |
| Error messages | Instantiation-time errors, often terrible (C++ templates pre-concepts) | Declaration-time errors |
Go's 1.18 generics chose a middle path (GC shape stenciling): monomorphize by representation class rather than by exact type, so all pointer-shaped types share one instantiation. This bounds code growth while keeping most of the performance.
[DURABLE] Whichever you choose, define errors at the declaration site. C++ templates famously deferred all checking to instantiation, producing the pathological error messages that concepts (C++20) exist to fix. Rust's trait bounds check the generic body against its bounds up front. This is worth real implementation effort.
Rust's contribution is proving that affine types plus region inference can eliminate memory-safety bugs at compile time with no runtime cost, in a language people actually ship. The machinery:
&T (shared, many) / &mut T (unique, one). The XOR rule — aliasing xor
mutation — is what makes the whole thing sound and is what makes it hard to learn.[VERSIONED] NLL (non-lexical lifetimes) shipped in 2018; Polonius is the next-generation formulation, designed to accept currently-rejected patterns (notably "lending iterators"). Rust's own 2026 project-goal updates describe an "alpha" Polonius being tested on CI alongside the next-gen trait solver, with worst-case slowdowns still being tracked. The honest read: borrow checking is a research area with a shipped product on top of it, and the shipped product's rules are still being refined eight years in.
Alternatives worth knowing: linear types (must use exactly once — Linear Haskell),
uniqueness types (Clean), region/arena inference (MLKit, Cyclone — the direct ancestor of
Rust's design), and Swift's ARC with ~Copyable/borrowing annotations retrofitted.
These aren't "type checking" but live in the same phase and are equally load-bearing:
The spectrum, in increasing order of power and danger:
2+2.constexpr/comptime — arbitrary evaluation at compile time (C++, Zig's
comptime, which is also how Zig does generics).[VERSIONED, and a genuinely big deal] C++26 shipped static reflection, which Herb
Sutter called "the biggest upgrade since templates" and "C++'s decade-defining rocket
engine." The ISO committee completed technical work on C++26 on 28 March 2026 in
London; the headline features are static reflection, contracts, std::execution
(sender/receiver), and a hardened standard library. GCC 16.1 (30 April 2026) already
ships reflection and contracts. Note the syntax churn as a lesson: the reflection
operator changed from ^ to ^^ during standardization, so early adopter code needed
migration.
⚠️ GOTCHA — compile-time execution means your compiler contains an interpreter, and that interpreter is a security boundary and a performance cliff. You need: a step limit (or programs won't terminate), determinism (or builds aren't reproducible), a decision about whether it can do I/O (it should not), and an answer for what it means to debug it. Zig's community discussions consistently name
comptimeas both its best feature and a significant pain point — that's the shape of this trade-off.
An active research frontier that is reaching production:
language-runtimes-interpreters-and-jits): async/await is an ad-hoc, unprincipled effect system.
This is the strongest argument for doing effects properly.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
compiler-frontend, language-design, parsing, type-systems, lexing
npx claudepluginhub the-vibey-project/vibey --plugin programming-language-development5 skills in this plugin
/language-development-referenceUse when reviewing a language or compiler design for known anti-patterns, weighing contested questions (static vs dynamic typing, monomorphization vs erasure, GC vs ownership, async/await vs green threads, LLVM or not, Safe C++ vs Profiles, sea of nodes, batteries-included standard library, formal verification's cost/benefit, how much syntax novelty), checking whether a toolchain or language-version claim is still current (snapshot verified August 2026), finding the books, papers, and primary sources, or needing the build-it-in-order checklist, numbers, and compiler-bug triage. Companion to the other programming-language-development skills./language-diagnostics-tooling-and-evolutionUse when making a language usable and durable: what a good diagnostic contains and the rules for error messages, warnings, source locations; incremental compilation and IDE support (query-based compilation, salsa-style memoization, what the LSP needs from you); the compiler test pyramid and formal verification; standard library and ecosystem design; and language evolution — backward compatibility, editions as the best mechanism we have, governance (BDFL, committees, RFC processes), and multiple implementations.