package

github.com/Raelr/crlox

main / published Jun 29, 2021 / repository

An implementation of the `lox` interpreter in `crystal`.

Crystal CI

crlox

An implementation of the lox interpreter in crystal.

Summary

crlox is an attempt to re-implement jlox, a programming language designed and implemented by Robert Nystrom. This repository follows Nystrom's amazing book: crafting compilers, and re-interprets their java compiler into crystal. This repository is entirely experimental is expected to be a means to learn the basics of compilers and interpreters.

Setup

Setting the project up is quite simple.

  1. Make sure you have crystal installed. If not, follow the steps on the official crystal website!.
  2. Clone the repository:
$ git clone https://github.com/Raelr/crlox.git 
  1. In the project's root folder, run the following:
$ shards init
$ shards install
  1. Once complete, run the compiler using the following:
$ crystal run src/crlox.cr -- "assets/test.lox"

You can also write you own Lox code and pass in the file's location. We just provided a sample file for your convenience.

The project can also be tested using:

$ crystal spec

Generating AST Tree Files

An AST file definition can be generated by running the following command:

$ crystal run src/tool/generate_ast.cr

This will generate a file called expr.cr which contains all relevant Expression classes. You can specify a location for the file to be generated by providing a path after the command:

$ crystal run src/tool/generate_ast.cr -- "your/desired/path"

API