Skip to content

mukifera/go-lox

Repository files navigation

go-lox

An interperter for the Lox programming language, written in Go.

Currently suppports:

  • Arithmetic operators +, -, *, \
  • Comparision operators >, >=, <, <=
  • Equality operators ==, !=
  • Grouping with ()
  • Variable declarations with var
  • Print statements with print
  • Code blocks with localized variable scopes {}

Check run_tests.yaml for example programs

Usage

Use the go-lox.sh script to build and run the interpreter.

Run programs with:

$ ./go-lox.sh run [file]

Plumbing commands

Tokenization

# input-file.lox
({*.,+*});

# tokenize the input file
$ ./go-lox.sh tokenize input-file.lox
LEFT_PAREN ( null
LEFT_BRACE { null
STAR * null
DOT . null
COMMA , null
PLUS + null
STAR * null
RIGHT_BRACE } null
RIGHT_PAREN ) null
SEMICOLON ; null
EOF  null

Parsing and expression generation

# input-file.lox
var x = 5 + 1;
print x;

# parse the input file
$ ./go-lox.sh parse input-file.lox
(var (= x (+ 5 1)))
(print x)

About

A programming language interpreter written in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published