crlox

Version, currently main branch1 version
  • main branchlatestJun 29, 2021

github.com/Raelr/crlox

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

1 stars
0 dependents
License: not declared

Installation

# Add this to your shard.yml
dependencies:
  crlox:
    github: Raelr/crlox
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

This shard.yml declares only a name and a version: no Crystal constraint, no dependencies, no targets and no executables. It is a plain library with nothing to build.

Dependencies

This version declares no dependencies.

README

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"