stlox
is an interpreter of the Lox programming language as described in the excellent Crafting Interpreters book by Robert Nystrom. It is a tree-walk interpreter written in Smalltalk, based directly on the Java version described in the book.
Requires GNU Smalltalk, which can be installed by downloading and unpacking the latest stable/alpha version from the GNU FTP site:
# download and unpack source
wget https://alpha.gnu.org/gnu/smalltalk/smalltalk-3.2.91.tar.xz
tar -xvf smalltalk-3.2.91.tar.xz
cd smalltalk-3.2.91
# compile and install
export CFLAGS="-no-pie"
export LDFLAGS="-no-pie"
./configure
make
make install
This should create the Smalltalk interpreter gst
(and other useful tools like gst-load
for using packages) installed by default at /usr/local/bin
.
Alternatively you may find that GNU Smalltalk is available in your system's package manager.
The Lox interpreter can be installed using the provided Makefile:
git clone https://github.com/lewis-weinberger/stlox.git
cd stlox
make install
make test # optionally run tests
This will place an executable script stlox
at /usr/local/bin
(by default) which can be used to run the interpreter:
# run as interactive interpreter by passing no arguments
stlox
# read and interpret from source file by passing file path
stlox examples/helloworld.lox
There are some Lox examples in the examples subdirectory.
Following the order in the book, the following has been implemented so far:
- Scanner
- Parser
- Interpreter:
- Expressions
- Statements
- Control flow
- Functions
- Variable binding
- Classes
- Inheritance
- Tests