Skip to content

Commit 4716d8a

Browse files
committed
github: readme, license, travis
Signed-off-by: Furkan <furkan.turkal@hotmail.com>
1 parent b39c3ff commit 4716d8a

4 files changed

Lines changed: 175 additions & 1 deletion

File tree

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: rust
2+
rust:
3+
- 1.43.0
4+
- stable
5+
- nightly
6+
sudo: false
7+
env:
8+
global:
9+
- RUSTFLAGS="--deny warnings"
10+
- RUST_BACKTRACE=1
11+
- CARGO_INCREMENTAL=0
12+
script:
13+
- cargo test --all
14+
- cargo build
15+
notifications:
16+
email:
17+
on_success: never

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "tl"
2+
name = "Monkey"
33
version = "0.1.0"
44
authors = ["Furkan <furkan.turkal@hotmail.com>"]
55
edition = "2018"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Furkan Türkal
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# Monkey
2+
3+
[![Build](https://travis-ci.org/Dentrax/Monkey.svg?branch=master)](https://travis-ci.org/Dentrax/Monkey)
4+
5+
**Yet another Monkey interpreter implementation in Rust, based on Thorsten Ball's [Writing An Interpreter In Go](https://interpreterbook.com/) book.**
6+
7+
## Features
8+
* AST
9+
* Tokenizer
10+
* Parser
11+
* Lexer
12+
* Evaluator
13+
* Builtin Functions
14+
* Read–Eval–Print Loop
15+
16+
## Usage
17+
18+
### Test
19+
20+
```rust
21+
cargo test --all
22+
```
23+
24+
### Run
25+
26+
```rust
27+
cargo run
28+
```
29+
30+
```bash
31+
Monkey Interpreter v0.1.0
32+
>>> "Hello, " + "World!"
33+
Hello, World!
34+
>>>
35+
```
36+
37+
## Examples
38+
39+
### Functions
40+
41+
```rust
42+
[1, 2 * 2, 3 + 3]
43+
```
44+
45+
46+
### Function Call
47+
48+
```rust
49+
let identity = fn(x) { x; }; identity(7); //7
50+
```
51+
52+
```rust
53+
let add = fn(a, b) { a + b };
54+
let sub = fn(a, b) { a - b };
55+
let applyFunc = fn(a, b, func) {
56+
func(a, b)
57+
};
58+
applyFunc(10, 2, sub); //8
59+
```
60+
61+
### If
62+
63+
64+
```rust
65+
if (x < y) { z } else { w }
66+
```
67+
68+
### Nested If
69+
70+
```rust
71+
if (2 > 1) { if (3 > 1) { return 7; } return 0; }
72+
```
73+
74+
### HashMap
75+
76+
```rust
77+
{"one": 0 + 1, "two": 10 - 8, "ten": 50 / 5}
78+
```
79+
80+
### Arrays
81+
82+
```rust
83+
let arr = [1, 2 * 2, 3 + 3] //arr[1 + 1] => returns 6
84+
```
85+
86+
### Operator Precedence
87+
88+
```rust
89+
3 + 4 * 5 == 3 * 1 + 4 * 5 //((3 + (4 * 5)) == ((3 * 1) + (4 * 5)))
90+
```
91+
92+
### Error Handlers
93+
94+
```rust
95+
if (10 > 1) { if (10 > 1) { return true + false; } return 1; } //unknown operator: BOOLEAN + BOOLEAN
96+
```
97+
98+
```rust
99+
let newAdder = fn(x) { fn(y) { x + y } }; let addTwo = newAdder(2); x //identifier not found: x
100+
```
101+
102+
## Complete Example
103+
104+
### Builtin
105+
106+
```rust
107+
let map = fn(arr, f) {
108+
let iter = fn(arr, accumulated) {
109+
if (len(arr) == 0) {
110+
accumulated
111+
} else {
112+
iter(rest(arr), push(accumulated, f(first(arr))));
113+
}
114+
};
115+
iter(arr, []);
116+
};
117+
let a = [1, 2, 3, 4];
118+
let double = fn(x) { x * 2 };
119+
map(a, double);
120+
```
121+
122+
### HashMap
123+
124+
```rust
125+
let people = [{"name": "Alice", "age": 24}, {"name": "Anna", "age": 28}];
126+
let getAge = fn(person) { person["name"]; };
127+
return getAge(people[0]) + getAge(people[1]);
128+
```
129+
130+
## TODO
131+
- [ ] Impl Compiler
132+
- [ ] Impl VM
133+
134+
## License
135+
136+
MIT License ([LICENSE](LICENSE)).

0 commit comments

Comments
 (0)