Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vpukhanov/go-monkey-interpreter
An interpreter for simple Monkey language (written in Go)
https://github.com/vpukhanov/go-monkey-interpreter
Last synced: 8 days ago
JSON representation
An interpreter for simple Monkey language (written in Go)
- Host: GitHub
- URL: https://github.com/vpukhanov/go-monkey-interpreter
- Owner: vpukhanov
- Created: 2019-06-25T17:55:56.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-05T04:22:50.000Z (about 5 years ago)
- Last Synced: 2024-06-21T08:07:26.413Z (5 months ago)
- Language: Go
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Monkey Language Interpreter
Monkey is a language that supports:
- integers
- booleans
- strings
- arrays
- hashes
- prefix-, infix- and index operators
- conditionals
- global and local bindings
- first-class functions
- return statements
- closuresThis example interpreter is written in Go, using the materials of the [Writing An Interpreter In Go](https://interpreterbook.com) book.
## Example of Monkey Code
```
let name = "Monkey";
let age = 1;
let inspirations = ["Scheme", "Lisp", "JavaScript", "Closure"];
let book = {
"title": "Writing An Interpreter In Go",
"author": "Thorsten Ball"
};let printBookName = fn(book) {
let title = book["title"];
let author = book["author"];
puts(author + " - " + title);
}printBookName(book);
// => prints: "Thorsten Ball - Writing An Interpreter In Go"let fibonacci = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};let map = fn(arr, f) {
let iter = fn(arr, accumulated) {
if (len(arr) == 0) {
accumulated
} else {
iter(rest(arr), push(accumulated, f(first(arr))));
}
};iter(arr, []);
};let numbers = [1, 1 + 1, 4 - 1, 2 * 2, 2 + 3, 12 / 2];
map(numbers, fibonacci);
// => returns: [1, 1, 2, 3, 5, 8]
```## Running the REPL
To run the REPL (run-eval-print loop) interpreter, run
go run main.go
## Running the Tests
To run automated tests in all of the packages, run
go test ./...