Git Product home page Git Product logo

tunalang's Introduction

The Tuna Programming Language

banner

A dynamically typed, interpreted programming language.

latest tag (SemVer) latest release (SemVer) License Go Version Test Status Issues

Supported Platforms

Windows Support MacOSX Support Linux Support

Overview

Tuna is a dynamically typed, interpreted programming language. This project is heavily inspired by and derived from the books 'Writing An Interpreter in Go' & 'Writing A Compiler in Go' by Thorsten Ball and the Monkey programming language.

As of v1.0, the language is fully functional as interpreter and supports functionality such as

  • Simple data types - Integers, Strings and Booleans.
  • Compound data types - Lists and Maps.
  • Prefix, Infix and Index operations.
  • Conditional and Return statements.
  • Global and Local variable bindings.
  • First-class functions and Closures.
  • Simple Built-In functions.

Usage

The only way to use Tunalang currently is through the REPL (this will change).

  1. Install Tunalang .
  2. Run tunalang to start the Tuna REPL.
  3. Code Away!

Installation

From Binary

  1. Download the binary for the target platform from the latest release. All Tunalang releases are available here.
  2. Save the binary to a directory of choice.
  3. Add the path to that directory to the PATH environment variable.
  4. Tunalang is now install and can be invoked using the tunalang command.

Note: If a binary is not availabe for your platform. Raise an issue or install from source. Any platform that is supported by the Go runtime will support Tuna.

From Source

Installing from source requires an installation of Git and Go v1.16+. An installation of Make is useful but not necessary. Make for Windows is available on Chocolatey and can be installed with choco install make.

  1. Clone the repository and change directory into it.
git clone https://github.com/manishmeganathan/tunalang.git 
cd tunalang
  1. Compile and Install the binary.

If the make command is available, run the following.

make install

Otherwise, run this.

go install .
  1. Tunalang is now install and can be invoked using the tunalang command. Some platform might require a manual configuration for the Go binary source to be added to path.

Components

The Lexer

The lexer converts string inputs into lexicological token that can be parsed. It is defined in lexer package along with the definitions for the lexicological tokens used in Tuna.

The Parser

The parser is a top-down recursive descent parser that is often called a Pratt parser. It is defined in parser package. Its role is to converts the tokens generated by the lexer into an Abstract Syntax Tree. The nodes of the AST are defined in the syntaxtree package.

The Evaluator

The evaluator is a tree-walking evaluator implemented in the evaluator package that recursively walks down the AST and evaluates it into objects that are defined by object package.

The REPL

The read-eval-print loop accepts an input and interprets/evaluates it on the fly and prints the output. It is the primary interface to interact with the Tuna programming language.

Examples

let name = "Tunalang";
let inspirations = ["Monkey", "Rust", "Wren"];

let data = {
    "name": name,
    "version": "v1.0.0"
};

let printdata = fn(data) {
    let name = data["name"];
    let version = data["version"];

    puts(name + " - " + version);
};

printdata(book);
# => prints: "Tunalang - v1.0.0"
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]

Future Development

  • Unicode Lexer [#1]
  • Macro System [#6]
  • Bytecode Compiler and Virtual Machine (Tuna v2)

tunalang's People

Contributors

manishmeganathan avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

topport

tunalang's Issues

Add support for Unicode/UTF-8 characters

The current lexical model only supports ASCII characters. Adding UTF-8 support includes

  • The Lexer should read characters as runes instead of bytes.
  • Must account for a larger cursor window and refactoring cursor incrementation accordingly

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.