Skip to content

A virtual machine and a tree-walk interpreter for the Lox programming language in C89 🌀

License

Notifications You must be signed in to change notification settings

jalalmostafa/clox

Repository files navigation

CLox

Build Status Build status

CLox is a cross-platform implementation of a tree-walk lox interpreter and a virtual machine in C89.

This implementation may be a little bit different than the original Lox implementation in the sense of data structures, project structure, and minor algorithmic changes. For example, both CLox modes use the same tokenizer that is available in include/tokenizer.h and src/tokenizer.c.

Next Chapter: Ch.25 Closures

How to Run

`lox.exe [--vm|--tree-walk] [filename]` or `lox.exe [--vm|--tree-walk]` to launch REPL interpreter.
    --tree-walk    runs clox in tree walk mode
    --vm           runs clox in bytecode mode (default)
    --help         shows this help text

Coding Conventions

clox source code follows Webkit Coding Convention. However, some rules are violated as follows:

  • Function Naming: clox uses the old ugly but practical function naming e.g. function_name()
  • Guards: clox uses guards instead of #pragma once
  • Macro Naming: clox uses capital letters with underscores to name macros

Build

In order to build and compile clox, you need to install CMake plus the toolchain of your choice, e.g. MSBuild with MSVC or make with gcc. After you setup CMake with your toolchain of choice, clone the repository and build the project as follows:

git clone https://github.com/jalalmostafa/clox.git
cd clox/
mkdir build && cd build
cmake ..
cmake --build .

In order to execute clox, check bin folder in project directory for binaries. Execute with --tree-walk in the arguments.

VS Code

You can also use VS Code to automate builds and run tests. Below is a table of the available tasks. If it is the first time running the project, then be sure to generate build files by running Rebuild task

Task Name Job Hotkey (default)
Build Compile source code and generate binaries Ctrl+Shift+B
Rebuild Run cmake to generate build files then run Build task
Run Read Test with Treewalk Run clox with examples/read_from_input.lox and --tree-walk in the arguments
Run Read Test with VM Run clox with examples/read_from_input.lox and --vm in the arguments

About

A virtual machine and a tree-walk interpreter for the Lox programming language in C89 🌀

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published