Skip to content

campierce/cslox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cslox

A tree-walk interpreter for the Lox programming language, written in C#, based on Crafting Interpreters.

Lox is a small, dynamically-typed language with C-like syntax, first-class functions, and object-oriented features. This particular implementation extends the base language with a built-in list class.

Example

class Fib {
  // returns a function that generates Fibonacci numbers
  generator() {
    var seq = list();
    fun next() {
      var n = seq.length();
      if (n < 2) {
        seq.add(n);
      } else {
        seq.add(seq.get(n - 1) + seq.get(n - 2));
      }
      return seq.get(n);
    }
    return next;
  }
}

var next = Fib().generator();
for (var i = 0; i < 7; i = i + 1) {
  print next();
}
// 0, 1, 1, 2, 3, 5, 8

Usage

Requires .NET 9.

Build with make publish or equivalent, then:

./cslox               # start the REPL
./cslox script.lox    # run a script
./cslox -p script.lox # print the AST (works in REPL mode too)

About

A Lox interpreter in C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors