Interpreter and compiler implementation in Java and C based on Crafting Interpreters book. The main goal of this project is to get a better understanding of interpreters, compilers and programming languages, as well as improving general programming skills, especially in C.
- clox: Compiler implementation in C.
- jlox: Interpreter implementation in Java.
- examples/tests: Working example Lox programs, which are also used for testing.
- notes: Some thoughts along the way.
- vim: basic syntax highlighting of .lox files for vim.
Simple Hello, World program:
print "Hello, World";
- Variable declaration, assignment and reassignment.
- First-class functions
- Classes (with inheritance)
- Control-flow (if, else, while, forL)
- Addition, subtraction, multiplication and division
- Closures
- Dynamic typing
- Static variable resolution and error detection.
- Garbage collection
Example programs can be found in the examples folder.
Compiler of the Lox progamming language, written in C.
Compile source code (from clox
directory):
make
You can now run the compiler with:
./clox
Interpreter of the Lox programming language, written in Java.
Clone the repository to local machine:
git clone https://github.com/nicolayro/lox.git
Compile source code:
./compile
You're now ready to run Lox scripts!
The Java interpreter runs Lox programs. You can find some examples of these in the examples folder.
Run .lox
source code:
./run <file>
You can also run it interactively in a REPL:
./run
Use Crtl-C
to exit.
The interpreter is structured in the following way, from source code to execution:
The current test suite for this project is a simple output checker for programs in examples directory.
It compares the output of each program with the expected output, defined in the similarily named
.txt
file.
To run the tests:
./test