Skip to main content
back to projects

Pika Language Interpreter

tree-walking interpreter for a small dynamically typed language, written in go from scratch. built to actually understand parsing and evaluation.

GoInterpretersParsing

Pika is a tree-walking interpreter for a small dynamically typed language, written in Go from scratch. Built following Thorsten Ball's Writing An Interpreter In Go — no parser generator, no library shortcuts, every layer hand-rolled.

Related writing: i built my own interpreter and it's kinda cool.

the pika repl — print("Hello World!") evaluated live, with the project's ascii banner

why build a language

"How does a programming language work?" is one of those questions that has confident answers everywhere on the internet and somehow still feels like a black box until you write one. Building a tiny one demystifies the whole stack: lexing, parsing, evaluation, scope, closures.

what's implemented

A complete lexer, parser, and tree-walking evaluator supporting:

  • Math and comparison expressions with the standard operators (+, -, *, /, <, >, ==, !=)
  • let bindings with proper lexical scoping
  • First-class functions with closures and higher-order patterns
  • Conditionals with if/else expressions and explicit return
  • Data types: integers, booleans, strings, arrays, hash maps
  • Built-ins: len, first, last, rest, push
javascript
let makeCounter = fn() { let count = 0; return fn() { count = count + 1; return count; }; }; let counter = makeCounter(); counter(); // 1 counter(); // 2

what i learned

The interpreter itself is the easy part once you have a clean AST. The hard problem is parsing — every weird thing about precedence, associativity, and ambiguity in real languages is a parser problem in disguise. After this project, reading a language spec stopped feeling like reading magic.