Git Product home page Git Product logo

clox's Introduction

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

clox's People

Contributors

rapiz1 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

watch-later

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.