Tiny Language — Lexer, Parser, and Interpreter in One File
Type code on the left, see it run on the right. Real lexer + recursive descent parser + tree-walking interpreter — closures and all — in one HTML file.
What this is
Split-pane: a syntax-highlighted code editor on the left, a console on the right, a single-line REPL across the bottom. Pre-loaded examples — FizzBuzz, recursive Fibonacci, in-place quicksort, a closure-based counter factory, list flattening — selectable from a dropdown. Press Run (or Ctrl+Enter) and the source goes through a hand-rolled lexer, a recursive-descent parser with Pratt-style precedence climbing, and a tree-walking interpreter with proper lexical scoping. Errors print with stack traces that include line numbers and the deepest call frame. The REPL inherits the editor's last-run global environment, so after running quicksort you can poke at the result.
Why this is mind-blowing
Most "build your own language" tutorials are book-length. This is the entire compiler chain — tokens, AST, evaluator, runtime, error handling — in one HTML file you can fork in an afternoon. Closures truly close over their defining environment. Functions are first-class values. The trace is real. Languages stop feeling magical the day you can read every byte of one.
Single-file tiny programming language. Lexer + recursive descent parser + tree-walking interpreter in pure JS. Syntax: variables, math, if/else, while, functions, print, lists, closures. Split-pane UI: editor with syntax highlighting on left, console on right. Pre-loaded examples (fizzbuzz, fibonacci, quicksort). Bottom REPL for line-by-line eval.
Paste this into Claude, Cursor, or Copilot. Change one thing that matters to you.
What I learned shipping it
- Lexical scoping is just chained Env objects: every function captures the Env it was defined in, not the one it's called in. Get that one detail right and closures, recursion, and counter factories all just work.
- Pratt-style precedence climbing makes operator precedence trivial — one parser function handles all binary ops with a precedence table.
- A REPL that shares the editor's last-run global env turns a toy interpreter into a real exploratory tool — run quicksort, then poke at the resulting array from the prompt.