Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dwayne/elm-monkey-interpreter
A Monkey interpreter written in Elm.
https://github.com/dwayne/elm-monkey-interpreter
elm interpreter monkey
Last synced: about 2 months ago
JSON representation
A Monkey interpreter written in Elm.
- Host: GitHub
- URL: https://github.com/dwayne/elm-monkey-interpreter
- Owner: dwayne
- Created: 2022-06-02T12:29:16.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-06-06T11:20:01.000Z (over 2 years ago)
- Last Synced: 2024-04-16T03:17:52.194Z (8 months ago)
- Topics: elm, interpreter, monkey
- Language: Elm
- Homepage: https://elm-monkey-interpreter.netlify.app/
- Size: 117 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-elm-pltd - elm-monkey-interpreter - A [Monkey](https://monkeylang.org) interpreter written in Elm. (Languages / Interpreters)
README
# Elm Monkey Interpreter ([Playground](https://elm-monkey-interpreter.netlify.app/))
A [Monkey](https://monkeylang.org/) interpreter written in
[Elm](https://elm-lang.org/).Monkey is a programming language designed by
[Thorsten Ball](https://thorstenball.com/) that is fully described in his
[interpreter](https://interpreterbook.com/) book.## Syntax
The syntax of Monkey is scattered throughout the pages of the book. However, I
extracted a [context-free grammar](grammar.ebnf) that you can use to learn the
syntax.```
let filter = fn (pred, arr) {
let iter = fn (arr, accumulated) {
if (len(arr) == 0) {
accumulated
} else {
if (pred(first(arr))) {
iter(rest(arr), push(accumulated, first(arr)))
} else {
iter(rest(arr), accumulated)
}
}
};
iter(arr, [])
};let mod = fn (a, b) {
a - a / b * b
};let isEven = fn (n) {
mod(n, 2) == 0
};filter(isEven, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
```You can also use the [parser tests](tests/Test/Monkey/Parser.elm) as a guide.
## Semantics
The semantics is defined by the [interpreter](src/Monkey/Interpreter.elm). You
can get a sense for it by reading through the extensive suite of
[interpreter tests](tests/Test/Monkey/Interpreter.elm).