Skip to content

tomlin7/lemon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Lemon Programming Language

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:

repl

Hello, Lemon!

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]

Features

  • 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
  • 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

Usage

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>

About

The Lemon Programming Language. Minimalist, fast, dynamic.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages