A C implementation of the Lox programming language, as described in the book Crafting Interpreters by Robert Nystrom.
To build and run this project, you will need:
- A C compiler (e.g.,
gccorclang) - CMake (version 3.10 or higher)
make(or another build system supported by CMake)
Follow these steps to build the project from the command line:
-
Create a build directory:
mkdir build cd build -
Generate the build files with CMake:
cmake ..
-
Compile the project:
make
After a successful build, the Clox executable will be located in the build directory.
You can run Clox in two modes: REPL (interactive) or by executing a script file.
To start the interactive REPL, run the executable without any arguments:
./CloxType Lox code and press Enter to execute it. Press Ctrl+D (or Ctrl+C) to exit.
To execute a Lox script file, provide the path to the file as an argument:
./Clox path/to/script.loxThe project includes several test files in the tests/ directory organized by feature (e.g., classes, functions). Many tests include a script file and a corresponding .expected file containing the expected output.
To run a test and manually verify its output:
./Clox tests/classes/classInheritanceTestCompare the printed output with the content of tests/classes/classInheritanceTest.expected.
Alternatively, use ctest from the build directory to run the basic tests configured in CMake:
ctestsrc/: Contains the C source and header files for the interpreter.tests/: Contains test scripts and expected output files.CMakeLists.txt: Configuration for the CMake build system.