loxxy is a high-fidelity tree-walk interpreter for the lox programming language, written entirely in go.
the project implements a full suite of modern language features and navigates through the standard pipeline of lexical analysis, parsing, semantic analysis, and interpretation.
- tokens and lexing: thorough scanning of source text into tokens
- abstract syntax trees (ast): representation of program structure for both expressions and statements
- recursive descent parsing: a top-down parsing strategy to ensure syntactic correctness
- prefix and infix expressions: support for mathematical and logical operations
- runtime representation of objects: dynamic handling of lox values in the go environment
- code interpretation: utilizing idiomatic go type switches for ast traversal
- lexical scope: accurate block-level scoping and variable visibility
- environment chains: nested storage for variable tracking across scopes
- control flow: support for branching and looping
- functions and closures: supporting parameters and the ability to capture the surrounding lexical environment
- static variable resolution: a dedicated pass analyzing variable bindings prior to execution for error detection
- object-oriented programming: complete implementation of classes, including constructors, fields, and methods
- inheritance: support for single inheritance using the
<operator and method resolution viasupercalls
the architecture is structured chronologically by compiler phase to maximize modularity and exploit go's innate package system
- scanning (
src/scanning/) - lexical analysis - parsing (
src/parsing/) - syntax analysis - representation (
src/representation/) - syntax tree node definitions, i.e. expressions and statements - resolving (
src/resolving/) - semantic analysis - evaluation (
src/evaluation/) - runtime environment - testing (
tests/,src/testutils/) - tests and utilities for the testing pipeline
- Go version 1.26.1 or higher
- clone the repository to your local machine
- build the binary
git clone https://github.com/kolaowalska/loxxy.git
cd loxxy
go build -o loxxy main.goloxxy can be used in REPL mode or script execution mode.
- interactive REPL: run
./loxxyto start a prompt, for example
> var greeting = "feeling... foxxy ;)";
> print greeting;
feeling... foxxy ;)- script execution: run
./loxxy path/to/scriptto execute a .lox file.
the project is equipped with an extensive testing suite that utilizes a central testutils package to validate the scanner, parser, resolver, and interpreter in a unified pipeline.
the following command runs all available tests:
go test ./...the tests for specialized language features are as follows:
- classes and methods:
tests/classes_test.go - control flow:
tests/control_flow_test.go - inheritance:
tests/inheritance_test.go - function closures:
tests/functions_test.go