Giter Site home page Giter Site logo

rlox's Introduction

Rlox

Rlox is simple language designed purely to learn how build interpreters.

Rlox is a clone of lox langauge from https://craftinginterpreters.com/ book. Lox was written in Java and C and Rlox is a clone written in Rust just for fun.

NOTE - This is work in progress. Branch tree-walk contains tree walking interpreter.

Running REPL

Currently REPL it is very basic but you can execute all of the commands from it. To run REPL just cargo run

Running Rlox code from file

cargo run -- -i path/filename.rl

Run tests

cargo t

Some example code

Compute Fibonacci

fun fib(n) {
  if (n <= 1) return n;
  return fib(n - 2) + fib(n - 1);
}

for (var i = 0; i < 20; i = i + 1) {
  print fib(i);
}

Closures

var a = "global";
{
  fun showA() {
    print a;
  }

  showA();
  var a = "block";
  showA();
}

fun test() {
  print a;
  a=a+"!";
  return a;
}

print test();

Classes and Inheritance

class Doughnut {
  cook() {
    return "Fry until golden brown.";
  }

  cookAnother() {
    return "Fry until golden.";
  }
}

class BostonCream < Doughnut {
  cookAnother() {
    var orig = super.cookAnother();
    return orig + " Then pipe full of custard and coat with chocolate.";
  }
}

var first = BostonCream().cook();
print first;

var second = BostonCream().cookAnother();
print second;

rlox's People

Contributors

robjsliwa avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

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.