All Projects → gaufung → Monkey

gaufung / Monkey

Licence: mit
An Interpreter In Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Monkey

Designpatterns
🔑Elements of Reusable Object-Oriented Software🔓is a software engineering book describing software design patterns. The book's authors are Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides with a foreword by Grady Booch.
Stars: ✭ 134 (-17.28%)
Mutual labels:  interpreter
Lawvere
A categorical programming language with effects
Stars: ✭ 142 (-12.35%)
Mutual labels:  interpreter
Eval
Eval is a lightweight interpreter framework written in Swift, evaluating expressions at runtime
Stars: ✭ 157 (-3.09%)
Mutual labels:  interpreter
Gomacro
Interactive Go interpreter and debugger with REPL, Eval, generics and Lisp-like macros
Stars: ✭ 1,784 (+1001.23%)
Mutual labels:  interpreter
Emacs Cl
Common Lisp implemented in Emacs Lisp.
Stars: ✭ 140 (-13.58%)
Mutual labels:  interpreter
Janet
A dynamic language and bytecode vm
Stars: ✭ 2,216 (+1267.9%)
Mutual labels:  interpreter
Kinx
Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
Stars: ✭ 134 (-17.28%)
Mutual labels:  interpreter
Cling
The cling C++ interpreter
Stars: ✭ 2,322 (+1333.33%)
Mutual labels:  interpreter
Wisp
A light lisp written in C++
Stars: ✭ 141 (-12.96%)
Mutual labels:  interpreter
Shentong
A Haskell implementation of the Shen programming language.
Stars: ✭ 155 (-4.32%)
Mutual labels:  interpreter
Jssms
JavaScript Sega Master System & Game Gear dynamic recompiling emulator.
Stars: ✭ 136 (-16.05%)
Mutual labels:  interpreter
Sosml
The Online Interpreter for Standard ML, written in TypeScript.
Stars: ✭ 138 (-14.81%)
Mutual labels:  interpreter
Forge
A lightweight, elegant scripting language with built-in Rust-FFI.
Stars: ✭ 153 (-5.56%)
Mutual labels:  interpreter
Brew.js
[WIP] C++ high-level JavaScript API for Nintendo 3DS/Switch
Stars: ✭ 136 (-16.05%)
Mutual labels:  interpreter
S
the s shell
Stars: ✭ 158 (-2.47%)
Mutual labels:  interpreter
Szl
A lightweight, embeddable scripting language
Stars: ✭ 134 (-17.28%)
Mutual labels:  interpreter
Javo
🚀 A sandboxed VM any Java developer can afford
Stars: ✭ 144 (-11.11%)
Mutual labels:  interpreter
Wain
WebAssembly implementation from scratch in Safe Rust with zero dependencies
Stars: ✭ 160 (-1.23%)
Mutual labels:  interpreter
Metalang99
A functional language for C99 preprocessor metaprogramming
Stars: ✭ 152 (-6.17%)
Mutual labels:  interpreter
Lioness
The Lioness Programming Language
Stars: ✭ 155 (-4.32%)
Mutual labels:  interpreter

Monkey

A interpreter language implementation in Go.

1 Introduction

Write an Interpreter in Go source code.

中文翻译 PDF

Monkey interpreter language which is implemented Go language. After typing monkey in terminal, you get into the monkey programming language.

$ ./monkey
Hello $Username! This is Monkey programming language!
Feel free to type in commnd
Enter "exit()" or CTRL+C to quit command interface
>>>

2 Syntax

2.1 Definition

using let as keyword, each line ends with ;.

>>>let a = 3;
>>>let b = 1;
>>>a+b
4

2.2 Arithmetic operations

monkey supports all basic arithmetic operation of int. int type is represented by int64.

>>> let a = 3;
>>> let b = 1;
>>> a + b
4
>>> a - b
2
>>> a * b
4
>>> a / b
3

2.3 Builtin containers

monkey contains two builtin containers: array and map.

  • array

array is a list which organizes items by linear sequence. But types of items can be different from each other.

>>> let a = [1, 2.3, "array"];
>>> a
[1, 2.3, array]
>>> let b = push(a, "another");
>>> b
[1, 2.3, array, another]
  • map

map is treated as key-value container. please attention to that only boolean, int and string types can be used as key.

>>> let a = {"name":"moneky", true:1, 7:"sevent"};
>>> a
{name: monkey, true: 1, 7: seven}
>>> a["name"]
monkey
>>> a[true]
1
>> a[7]
seven
>>>let b = set(a, 8, "eight");
>>> b
{name: moneky, true: 1, 7: sevent, 8: eight}

2.4 Builtin functions

  • len

yield the length of builtin containers.

  • first

yield the first element of array.

  • last

yield the last element of array.

  • rest

yield an array which excludes the first element.

  • push

push an elements into the array.

  • set

insert key value pair into the map

  • puts

print literal value of objects.

2.5 Function

monkey use fn as the definition of function. Apart from regular function using, monkey also includes high order function.

>>>let add = fn(a, b) { return a + b;};
>>> add(1,2)
3
>>>let addTwo = fn(a,b, f) { return 2 + f(a, b);};
>>>addTwo(1,2, add)
5

2.5 If-else statements

monkey supports if-else statements.

>>> let max = fn(a, b) { if (a > b) { return a;} else { return b; } };
>>> max(1, 2)
2

2.6 For-loop statements

monkey support for-loop statement.

>>> let sum = fn(x) { let i = 1; let sum = 0; for (i < x) { let sum = sum + i; let i = i+1; } return sum; };
>>> sum(100)
4950
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].