Skip to content
/ lox Public

Implementation of the programming language Lox. Based on the book "Crafting Interpreters" by Robert Nystrom.

Notifications You must be signed in to change notification settings

nicolayro/lox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lox Programming Language - Crafting Interpreters

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.

Project Overview

  • 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.

Language Overview

Simple Hello, World program:

print "Hello, World";

Features

  • 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.

Clox

Compiler of the Lox progamming language, written in C.

Usage

Compile source code (from clox directory):

make

You can now run the compiler with:

./clox

Jlox

Interpreter of the Lox programming language, written in Java.

Installation

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!

Usage

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.

Program flow

The interpreter is structured in the following way, from source code to execution:

flow.png|50

Tests

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

About

Implementation of the programming language Lox. Based on the book "Crafting Interpreters" by Robert Nystrom.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages