Skip to content
poxel6Public

About

A lox interpreter written in C by me. https://craftinginterpreters.com

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

 

History

27 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clox, a Lox interpreter written in C from scratch with zero dependencies.

Based on the fantastic book Crafting Interpreters.

CLOX

Language Features:


  • 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

Deviations from the Book


under construction...

Build


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/script
make 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.

Examples


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.

About

A lox interpreter written in C by me. https://craftinginterpreters.com

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages