Skip to content

kolaowalska/loxxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

193 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fine-interpreter-szkita

overview and purpose

loxxy is a high-fidelity tree-walk interpreter for the lox programming language, written entirely in go.

language & interpreter features

the project implements a full suite of modern language features and navigates through the standard pipeline of lexical analysis, parsing, semantic analysis, and interpretation.

core implementation

  • 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

advanced semantics

  • 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 via super calls

structure tour d'horizon

the architecture is structured chronologically by compiler phase to maximize modularity and exploit go's innate package system

  1. scanning (src/scanning/) - lexical analysis
  2. parsing (src/parsing/) - syntax analysis
  3. representation (src/representation/) - syntax tree node definitions, i.e. expressions and statements
  4. resolving (src/resolving/) - semantic analysis
  5. evaluation (src/evaluation/) - runtime environment
  6. testing (tests/, src/testutils/) - tests and utilities for the testing pipeline

quick start

prerequisites

  • Go version 1.26.1 or higher

installation

  1. clone the repository to your local machine
  2. build the binary
git clone https://github.com/kolaowalska/loxxy.git
cd loxxy
go build -o loxxy main.go

usage

loxxy can be used in REPL mode or script execution mode.

  • interactive REPL: run
./loxxy

to start a prompt, for example

> var greeting = "feeling... foxxy ;)";
> print greeting;
feeling... foxxy ;)
  • script execution: run
./loxxy path/to/script

to execute a .lox file.

testing

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

Coverage

About

a simple tree-walk lox interpreter implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages