Code Monkey home page Code Monkey logo

oxa's Introduction

oxa

interpreted, object-oriented programming language. Interpreter written 100% in rust

Table of contents

Info

oxa is my first language. I took inspiration from this book, which I definitely recommend to anyone interested in writing new languages (or better understanding how computer languages work). The book uses Java to implement an interpreter for a language named LOX, which I have used as a blueprint for writing oxa.

oxa is very similar (although not identical) to LOX. Considering Rust and Java are very different languages, I had to change some things quite a bit to better suite the implementation language. Additionally, oxa also supports import statements (syntax being identical to Python), lists (along with bracket operator for indexing) and some native functions for dealing with user input, file I/O and time.

Examples

Hello world program

print "Hello World!"; 

fibonacci sequence

fun fib(x) {
  if x == 1 or x == 0 {
    return x;
  }
  return fib(x-1) + fib(x-2);
}

var x = input();
print fib(x);

a bit more complex example

class Triple {
  fun init(self, a, b, c) {
    self.a = a;
    self.b = b;
    self.c = c;
    return self;
  }
  
  fun sum(self) {
    return self.a + self.b + self.c;
  }
}

var max = 0;
var objects = list(Triple(1, 2, 3), Triple(4, 5, 6), Triple(7, 8, 9));
objects.add(Triple(10, 20, 30));

for obj in objects {
  if max < obj.sum() {
    max = obj.sum();
  }
}

print max; // prints 60

Future Plans

Since oxa is my hobby project which I started to mainly learn Rust and improve my knowledge of programming languages, I want to continue adding new features to the language. But my next main goal would be turning the interpreter into a bytecode compiler.

oxa's People

Contributors

ach113 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

lesterbogran

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.