• Stars
    star
    100
  • Rank 340,070 (Top 7 %)
  • Language
    C++
  • License
    BSD 2-Clause "Sim...
  • Created about 5 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An interpreter to learn

Autumn

Build Status codecov license platform

An easy interpreter to learn.

example

Features

  • Modern C++ style(Based on C++17)
  • Support Linux and MacOS
  • Full comments
  • Support debug in repl

example2

  • Higher-order functions supported

example3

  • Closure supported

example4

  • ...

Quick Start

Install GCC8

  • Centos
$ yum install readline-devel.x86_64
$ yum install -y devtoolset-8-toolchain
$ scl enable devtoolset-8 bash
  • Ubuntu
$ sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
$ sudo apt-get update -qq
$ sudo apt-get install -qq g++-8
$ apt-get install lib64readline-dev
$ export CXX="g++-8"
$ export CC="gcc-8"

Build & Test

$ make

Repl

  • lexer mode
$ ./autumn lexer
  • parser mode
$ ./autumn parser
  • debug in parser mode
$ DEBUG_AUTUMN=1 ./autumn parser
  • eval mode
$ ./autumn eval

Demo

An example below showing how to write quick sort.

  • You need a filter function
let filter = fn(arr, f) {
    let iter = fn(arr, accumulated) {
        if (len(arr) == 0) {
            accumulated
        } else {
            let e = if (f(first(arr))) {
                push(accumulated, first(arr));
            } else {
                accumulated
            }
            iter(rest(arr), e);
        }
    };
    iter(arr, []);
};
  • QuickSort
let quickSort = fn(arr) {
    if (len(arr) == 0) {
        return arr;
    } else {
        let head = first(arr);
        let smaller = filter(rest(arr), fn(x) { x <= head });
        let bigger = filter(rest(arr), fn(x) { x > head });
        return quickSort(smaller) + [head] + quickSort(bigger);
    }
}
let a = [4,5,3,4,6,6]
quickSort(a)

example5

Contributor

Allen.

License

This project maintained under BSD 2.

Contact

QQ Group for Autumn: 985682510 QQ Group for Linuxers: 610441700

References