Skip to content

rapiz1/clox

Repository files navigation

clox

Lox(well, not really) Interpreter in C++

Background

This is a learning project for Crafting interpreters.

I'm not actully implementing the authentic Lox. I adopted it according to my likes.

Lox is a language that is very similar to C, but with dynamic types. Let's see an example.

// calculate the greatest common divisor
function gcd(a, b) {
  if (b == 0) return a;
  while (a >= b) a = a - b;
  return gcd(b, a);
}

print gcd(99, 121);
assert gcd(99, 121) == 11;

After implementing basic functions for clox, I moved out to a C compiler, cppc, which is actually a fork of clox, but with lots of cleaning up and improvement.

The visitor pattern used here can be improved, and it's properly done in cppc.

Roadmap

  • basic lexer
  • basic parser
  • +,-,*,/,=,==,!=,<,>,<=,>=,(,)
  • +=, -=, *=, /=
  • support ++, --. but no ----a bullshit! theses ops return rvalue
  • print statement
  • expr statement
  • var declartion
  • block scoping
  • for, while block
  • branch
  • assert statement
  • testing the language with itself (built-in assert)! see ./tests
  • no continue! i'm lazy
  • break
  • function
  • return (can run gcd now!)
  • error recover
  • no local function or closure! i don't like it

Releases

No releases published

Packages

No packages published