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
Use the go-lox.sh
script to build and run the interpreter.
Run programs with:
$ ./go-lox.sh run [file]
# 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
# 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)