clox, a Lox interpreter written in C from scratch with zero dependencies.
Based on the fantastic book Crafting Interpreters.
- tokens and lexing
- Pratt parsing
- bytecode compilation
- stack-based virtual machine
- prefix and infix expressions
- runtime representation of objects
- dynamic typing
- global and local variables
- lexical scope
- control flow
- functions with parameters
- first-class functions
- closures
- upvalues
- native functions
- garbage collection
- string interning
- classes
- constructors
- fields
- methods
- this
- inheritance
- super
- method overriding
- runtime error handling
under construction...
default make variables
CFLAGS=-Wall -Wextra -Wconversion -Wsign-conversion -Wunreachable-code -Wshadow \
-Wcast-qual -Wcast-align -Wundef -Wmissing-prototypes -Wattributes -Wimplicit-int \
-Wimplicit-function-declaration -Wincompatible-pointer-types -Wint-conversion -Wmain \
-Wpointer-arith -Wpointer-sign -Wincompatible-pointer-types
OLVL=3
FILE=./main.lox
BIN=clox
FLAMEGRAPH=/path/to/flamegraph/scriptmake FILE=<filename> # to pass in a file to execute.
make FILE=./examples/basics.lox # to run basics examples.
make # to run in REPL mode.
make build # to build the binary.
make build OLVL=2 # control optimization level with OLVL
# binary name will be `clox`.
make release # to build the binary with compiler optimizations.
make release OLVL=2 # control optimization level with OLVL
# binary name will be `clox`.
make profile # builds and runs and profiles the binary.
# generates a flamegraph at:
# `target/profiler/flamegraph.svg`.
make profile OLVL=2 # control optimization level with OLVL
make debug # same as `make` but also includes debug symbols in the binary.
make warn # same as `make build` but also shows warnings.Few basic examples are provided in the example folder of this repository.
./examples/basics.lox # Basics of Lox syntax
./examples/closure.lox # How closures work in Lox.
./examples/oop.lox # How OOP looks in Lox.
./examples/fibonacci.lox # Simple and naive examples of fibonacci numbers
# and recursion in Lox.