All Projects → wadackel → Rs Monkey Lang

wadackel / Rs Monkey Lang

Licence: mit
Monkey Programming Language written in Rust.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Rs Monkey Lang

Monkey Rust
An interpreter for the Monkey programming language written in Rust
Stars: ✭ 174 (+117.5%)
Mutual labels:  lexer, parser, interpreter
Lioness
The Lioness Programming Language
Stars: ✭ 155 (+93.75%)
Mutual labels:  lexer, parser, interpreter
Mico
Mico ("Monkey" in catalan). Monkey language implementation done with C++. https://interpreterbook.com/
Stars: ✭ 19 (-76.25%)
Mutual labels:  lexer, parser, interpreter
Cub
The Cub Programming Language
Stars: ✭ 198 (+147.5%)
Mutual labels:  lexer, parser, interpreter
Syntax Parser
Light and fast 🚀parser! With zero dependents. - Sql Parser Demo added!
Stars: ✭ 317 (+296.25%)
Mutual labels:  lexer, parser
Exprtk
C++ Mathematical Expression Parsing And Evaluation Library
Stars: ✭ 301 (+276.25%)
Mutual labels:  lexer, parser
Sh
A shell parser, formatter, and interpreter with bash support; includes shfmt
Stars: ✭ 4,343 (+5328.75%)
Mutual labels:  parser, interpreter
Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (+431.25%)
Mutual labels:  lexer, parser
MonkeyLang.jl
"Writing an Interpreter in GO" and "Writing a Compiler in GO" in Julia.
Stars: ✭ 30 (-62.5%)
Mutual labels:  interpreter, lexer
Verible
Verible is a suite of SystemVerilog developer tools, including a parser, style-linter, and formatter.
Stars: ✭ 384 (+380%)
Mutual labels:  lexer, parser
Minigo
minigo🐥is a small Go compiler made from scratch. It can compile itself.
Stars: ✭ 456 (+470%)
Mutual labels:  lexer, parser
Swiftpascalinterpreter
Simple Swift interpreter for the Pascal language inspired by the Let’s Build A Simple Interpreter article series.
Stars: ✭ 270 (+237.5%)
Mutual labels:  lexer, interpreter
pascal-interpreter
A simple interpreter for a large subset of Pascal language written for educational purposes
Stars: ✭ 21 (-73.75%)
Mutual labels:  interpreter, lexer
Craftinginterpreters
Repository for the book "Crafting Interpreters"
Stars: ✭ 4,298 (+5272.5%)
Mutual labels:  parser, interpreter
aria
Expressive, noiseless, interpreted, toy programming language
Stars: ✭ 40 (-50%)
Mutual labels:  interpreter, lexer
Php Parser
🌿 NodeJS PHP Parser - extract AST or tokens (PHP5 and PHP7)
Stars: ✭ 400 (+400%)
Mutual labels:  lexer, parser
Goawk
A POSIX-compliant AWK interpreter written in Go
Stars: ✭ 995 (+1143.75%)
Mutual labels:  parser, interpreter
Logos
Create ridiculously fast Lexers
Stars: ✭ 1,001 (+1151.25%)
Mutual labels:  lexer, parser
Csstree
A tool set for CSS including fast detailed parser, walker, generator and lexer based on W3C specs and browser implementations
Stars: ✭ 1,121 (+1301.25%)
Mutual labels:  lexer, parser
fayrant-lang
Simple, interpreted, dynamically-typed programming language
Stars: ✭ 30 (-62.5%)
Mutual labels:  interpreter, lexer

rs-monkey-lang

CircleCI

Monkey Programming Language written in Rust.

What's Monkey?

The Monkey Programming Language

The official Monkey logo

Monkey is a programming language designed to learn interpreters.
It's came from Writing An Interpreter In Go.

Try Monkey!

with REPL

REPL Screenshot

$ git clone https://github.com/wadackel/rs-monkey-lang.git
$ make repl

with Online Playground

Playground Screenshot

Working with Wasm!! Awesome 🐶
https://wadackel.github.io/rs-monkey-lang/

Documentation

I created the document with reference to Writing An Interpreter In Go.

⚠️ Please note that there may be some mistakes.

Table of Contents

Summary

  • C-like syntax
  • variable bindings
  • integers and booleans
  • a string data structure
  • an array data structure
  • a hash data structure
  • arithmetic expressions
  • built-in functions
  • first-class and higher-order functions • closures

Syntax overview

An example of Fibonacci function.

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

fibonacci(10);

If

It supports the general if. else exists, butelse if does not exist.

if (true) {
  10;
} else {
  5;
}

Operators

It supports the general operations.

1 + 2 + (3 * 4) - (10 / 5);
!true;
!false;
+10;
-5;
"Hello" + " " + "World";

Return

It returns the value immediately. No further processing will be executed.

if (true) {
  return;
}
let identity = fn(x) {
  return x;
};

identity("Monkey");

Variable bindings

Variable bindings, such as those supported by many programming languages, are implemented. Variables can be defined using the let keyword.

Format:

let <identifier> = <expression>;

Example:

let x = 0;
let y = 10;
let foobar = add(5, 5);
let alias = foobar;
let identity = fn(x) { x };

Literals

Five types of literals are implemented.

Integer

Integer represents an integer value. Floating point numbers can not be handled.

Format:

[-+]?[1-9][0-9]*;

Example:

10;
1234;

Boolean

Boolean represents a general boolean types.

Format:

true | false;

Example:

true;
false;

let truthy = !false;
let falsy = !true;

String

String represents a string. Only double quotes can be used.

Format:

"<value>";

Example:

"Monkey Programming Language";
"Hello" + " " + "World";

Array

Array represents an ordered contiguous element. Each element can contain different data types.

Format:

[<expression>, <expression>, ...];

Example:

[1, 2, 3 + 3, fn(x) { x }, add(2, 2), true];
let arr = [1, true, fn(x) { x }];

arr[0];
arr[1];
arr[2](10);
arr[1 + 1](10);

Hashes

Hash expresses data associating keys with values.

Format:

{ <expression>: <expression>, <expression>: <expression>, ... };

Example:

let hash = {
  "name": "Jimmy",
  "age": 72,
  true: "a boolean",
  99: "an integer"
};

hash["name"];
hash["a" + "ge"];
hash[true];
hash[99];
hash[100 - 1];

Function

Function supports functions like those supported by other programming languages.

Format:

fn (<parameter one>, <parameter two>, ...) { <block statement> };

Example:

let add = fn(x, y) {
  return x + y;
};

add(10, 20);
let add = fn(x, y) {
  x + y;
};

add(10, 20);

If return does not exist, it returns the result of the last evaluated expression.

let addThree = fn(x) { x + 3 };
let callTwoTimes = fn(x, f) { f(f(x)) };

callTwoTimes(3, addThree);

Passing around functions, higher-order functions and closures will also work.

Built-in Functions

You can use 6 built-in functions 🚀

puts(<arg1>, <arg2>, ...): void

It outputs the specified value to stdout. In the case of Playground, it is output to console.

puts("Hello");
puts("World!");

len(<arg>): Intger

For String, it returns the number of characters. If it's Array, it returns the number of elements.

len("Monkey");
len([0, 1, 2]);

first(<arg>): any

Returns the element at the beginning of Array.

first([0, 1, 2]);

last(<arg>): any

Returns the element at the last of Array.

last([0, 1, 2]);

rest(<arg>): Array

Returns a new Array with the first element removed.

rest([0, 1, 2]);

push(<arg1>, <arg2>): Array

Returns a new Array with the element specified at the end added.

push([0, 1], 2);

Enjoy Monkey 🐵 !


License

MIT © wadackel

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].