Lemon is a tiny, fast, interpreted language. This repository contains the source code for the Lemon interpreter, written in Go. The language is still in development, and the interpreter is not yet feature-complete. A peek at the REPL atm:
let message = "Hello, Lemon!";
print(message);
For more examples, check out the examples directory.
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]
- Data types: boolean, integer and string
- Variables
let name = value;
- Arithmetic operations (
+
,-
,*
,/
) - Logical operations (
!
,&&
,||
) - Functions
fn (args) { body }
- First-class functions (closures)
- Comparison operations (
==
,!=
,>
,>=
,<
,<=
) - Control structures
- if, else
if (condition) { body } else { body }
- else if branch
- switch, case
- match, when
- while, for, loop
- break, continue
- if, else
- Garbage collection
- Strings
let name = "value";
- String concatenation
"value" + "value";
- Arrays
[1, 2, 3]
- Hash maps
{ "key": "value" }
- Comments
- Error handling
- Standard library
- Modules
- Classes
- Generics
- Multithreading
To run the REPL, use the following command:
go run main.go
To build the interpreter, use the following command:
go build
Running lemon files (after building):
lemon example.mm
To run tests, use the following command:
go test <directory>