Skip to content

GeneralPoxter/lox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lox++

Interpreter for the Lox language implemented in C++, with additional features.

Features

Implements vanilla Lox according to Chapters 4-13 of Crafting Interpreters by Bob Nystrom, as well as the following extra challenges:

  • Chapter 4 (Scanning):
    • C-style block comments
  • Chapter 6 (Parsing):
    • Comma operator
    • Ternary operator
    • Error productions for binary operators
  • Chapter 7 (Evaluating Expressions)
    • Type coercion for string concatenation
    • Divison by 0 error
    • Modulo operator
  • Chapter 8 (Statements and State)
    • REPL support for both expressions and statements
    • Runtime error for unassigned variables
  • Chapter 9 (Control Flow)
    • Break and continue statements
  • Chapter 10 (Functions)
    • Anonymous functions
  • Chapter 11 (Resolving and Binding)
    • Resolver error for unused local variables
    • More efficient environment representation via resolver indexing and vectors
  • Chapter 12 (Classes)
    • Static methods and fields via metaclasses
    • Getter members
  • Chapter 13 (Inheritance)
    • super keyword allows access to superclass fields in addition to methods

Usage

Build the interpreter:

make lox
  • Interpreter: ./lox [path to program file]
  • REPL: ./lox

Testing

Run the tests:

make test

Add new tests to the tests/ directory as follows:

  • [test_name].lox contains the Lox program
  • [test_name].expected contains the expected program output

About

Interpreter for the Lox language implemented in C++, with additional features

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published