No description
  • Zig 97.1%
  • Nix 2.9%
Find a file
2026-07-04 00:24:18 +03:00
src Eval infix expressions 2026-07-04 00:24:18 +03:00
.envrc Init zig and build on save 2026-06-11 00:05:40 +03:00
.gitattributes Init zig and build on save 2026-06-11 00:05:40 +03:00
.gitignore Init zig and build on save 2026-06-11 00:05:40 +03:00
build.zig Add Integer eval 2026-07-01 20:41:09 +03:00
build.zig.zon Init zig and build on save 2026-06-11 00:05:40 +03:00
flake.lock Init zig and build on save 2026-06-11 00:05:40 +03:00
flake.nix Add build flake 2026-06-13 12:33:12 +03:00
LICENSE Initial commit 2026-06-10 22:14:01 +03:00
README.md Upade readme 2026-06-18 00:39:55 +03:00

monkey — Monkey Language Interpreter in Zig

A lexer, parser, and REPL for the Monkey programming language, implemented in Zig following Thorsten Ball's "Writing An Interpreter In Go".

Status

Component Milestone
Tokenizer / Lexer Full Monkey token set, keyword lookup, two-char operators (==, !=)
Parser let statements, structured error reporting (no heap allocs per error)
AST Tagged unions (Statement / Expression) — no vtables, no interface casting
REPL Reads from stdin, tokenizes and prints tokens (zig build repl)

Quick start

# Run all tests
zig test src/Interpreter/Parser.zig
zig test src/Interpreter/Lexer.zig
zig test src/Interpreter/Ast.zig
zig test src/Interpreter/Token.zig

# Or use the build system
zig build test

# Run the REPL
zig build repl

# Check compilation (all packages)
zig build check

Project structure

src/Interpreter/
  Token.zig     — Token type, Type enum, keyword lookup (StaticStringMap)
  Lexer.zig     — Character-by-character tokenizer
  Ast.zig       — AST types: Program, Statement (tagged union), Identifier, LetStatement
  Parser.zig    — Recursive-descent parser, structured error collection
  Repl.zig      — Interactive read-eval-print loop
src/main.zig    — Stub entry point (not wired to interpreter)
build.zig       — Data-driven package registration, one loop for test + check steps

Design notes

  • Tagged unions for ASTStatement / Expression are union(enum), not Go-style interfaces or Zig vtables. The fixed set of node types means no runtime dispatch.
  • Allocation-free parse errors — parser errors store Token.Type values directly, no allocPrint per error. The ErrorFmt struct uses the {f} format specifier for custom display.
  • Borrowed literalsToken.literal slices into the original source input. No string copies during lexing.
  • Build loopbuild.zig uses std.meta.fields over a Packages named struct to register every module, its test artifact, and its check executable in a single comptime loop.
  • Zig 0.16 conventionsArrayList is unmanaged by default (allocator passed per-operation), toOwnedSlice returns right-sized allocations, pub fn format with two args responds to the {f} specifier.

The above was AI generated