Coder Social home page Coder Social logo

gengjiawen / monkey-rust Goto Github PK

View Code? Open in Web Editor NEW
43.0 2.0 5.0 4.83 MB

A dancing with interpreter and compiler

License: MIT License

Rust 31.65% CSS 3.14% HTML 3.82% JavaScript 58.53% EJS 0.24% Shell 0.86% TypeScript 1.78%
monkey-programming-language monkey rust interpreter compiler learning-by-doing

monkey-rust's Introduction

monkey-rust

Rust Gitpod ready-to-code monkey-interpreter npm version

An interpreter for the Monkey programming language written in Rust

The Monkey Programming Language

What’s Monkey?

Monkey has a C-like syntax, supports variable bindings, prefix and infix operators, has first-class and higher-order functions, can handle closures with ease and has integers, booleans, arrays and hashes built-in.

Official site is: https://monkeylang.org/. It's has various implementation languages :).

There is a book about learning how to make an interpreter: Writing An Interpreter In Go. This is where the Monkey programming language come from.

Features

  • Split packages to make everything minimum
  • REPL: A Read-Eval-Print-Loop (REPL) for Monkey tokenizer, parser, evaluator, compiler
  • location info for ast
  • test for every module
  • Wasm: A WebAssembly target, thus run monkey on browser is directly supported.
  • bytecode viewer from source

AST Online playground

https://astexplorer.net/#/gist/e23a81ce309e8fcffe95ddd1b5661061/01d0b4b078304ddd9639eae9f4e6d342e2b9d075

Compiler playground

https://gengjiawen.github.io/monkey-rust/

Instruction

Build and test

$ cargo build
$ cargo test

monkey-rust's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar gengjiawen avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

monkey-rust's Issues

monkey examples

// Integers & arithmetic expressions...
let version = 1 + (50 / 2) - (8 * 3);

// ... and strings
let name = "The Monkey programming language";

// ... booleans
let isMonkeyFastNow = true;

// ... arrays & hash maps
let people = [{"name": "Anna", "age": 24}, {"name": "Bob", "age": 99}];

// User-defined functions...
let getName = fn(person) { person["name"]; };
getName(people[0]); // => "Anna"
getName(people[1]); // => "Bob"

// and built-in functions
puts(len(people))  // prints: 2

let fibonacci = fn(x) {
  if (x == 0) {
    0
  } else {
    if (x == 1) {
      return 1;
    } else {
      fibonacci(x - 1) + fibonacci(x - 2);
    }
  }
};

// `newAdder` returns a closure that makes use of the free variables `a` and `b`:
let newAdder = fn(a, b) {
    fn(c) { a + b + c };
};
// This constructs a new `adder` function:
let adder = newAdder(1, 2);

adder(8); // => 11

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.