A computer programming language interpreter written in Rust

Overview

Ella lang

Welcome to Ella lang! Ella lang is a computer programming language implemented in Rust.

Checkout the interactive online playground here.

Language features

Basics

Here is the most basic hello world program:

println("Hello World!");

Yep! That's it. Don't forget to add the semicolon (;) character at the end.

Variables

One can also store values inside variables:

let name = "Ella";
println("Hello " + name + "!");

This should print Hello Ella! to the console.

Of course, other types exist as well.

let number = 1;
let float = 1.5;
let boolean = true; // or false

Expressions can also be assigned to variables

// same as let computed = 2;
let computed = 10 / 5;

or

let x = 10;
let y = x / 5; // should evaluate to 2

Functions

Like almost every other programming language, Ella supports defining and calling functions (aka methods in some languages):

fn greet() {
    println("Hello World!");
}
greet(); // prints Hello World!

Functions can also take parameters:

fn greet(name) {
    println("Hello " + name + "!");
}
greet("Luke"); // prints Hello Luke!

Functions can return results:

fn double(x) {
    return x * 2;
}

Results are returned using a return statement.

Expressions

As seen earlier, Ella includes expressions.

Expressions can include arithmetic operators with the appropriate precedence...

1 + 2 * 3 // parsed as 1 + (2 * 3)

(Note that addition operator, +, works both on numbers and on strings. On numbers, + is simply math addition; with strings, + performs string concatenation.)

reference variables...

foo + 10

include function calls (with arguments)...

double(10) + 2

and even reference functions (higher order functions)...

fn my_function() { ... }
my_function // reference to a function (not a function call)

Higher order functions and closures

In Ella, functions are also variables. This means we can pass functions to other functions as arguments. Example:

// This function applies the function f on g
fn apply(f, x) {
    return f(x);
}
fn double(x) {
    return x * 2;
}
apply(double, 2); // should evaluate to 4

Closures are also supported. Example:

/// This function combines f and g into a single function
fn compose(f, g) {
    fn inner(x) {
        return f(g(x));
    }
    return inner;
}
fn add_one(x) { return x + 1; }
fn double(x) { return x * 2; }
let func = compose(add_one, double); // func adds one and than doubles the result
func(3); // evaluates to (3 + 1) * 2 = 8

Functions can also be expressed using lambda syntax. Example:

let f = fn() { return 2; }
f(); // evaluates to 2

Lambda allows inline function creation and thus improves ergonomics.

Control flow

Ella supports structured control flow via if/else and while (for is still being implemented).

Branching is achieved via if and else. The else block is optional.

if condition {
    // do something
} else {
    // do something else
}

Note that unlike other languages, the if and else blocks must be surrounded with { and } brackets. This prevents the infamous "goto fail" incident as well as not requiring parenthesis around the condition. It is more aesthetic and easier to differentiate between control flow statements and function calls.

Looping is achieved via the while statement.

while condition {
    // repeat something
}

If condition is false since the very beginning, the loop will never execute.

Built-in functions

Ella includes some built-in functions that are defined in Rust:

  • print(x) - Prints a value x to the console. Not available in playground.
  • println(x) - Prints a value x to the console followed by a new line (\n character).
  • readln() - Reads a new line from stdin and returns a string. Not available in playground.
  • assert(value) - Asserts a certain condition is true. Uses Rust's assert! macro under the hood and will panic if fail. Not available in playground.
  • assert_eq(value) - Asserts two values are equal. Uses Rust's assert_eq! macro under the hood and will panic if fail. Not available in playground.
  • is_nan(num) - Returns true if the number is NaN. Returns false otherwise. Note that this is the only way to check if a number is NaN.
  • parse_number(str) - Parses a string into a floating point number or NaN if invalid.
  • clock() - Returns a floating point number representing the number of seconds since the Unix epoch. Useful for simple benchmarks.
  • str(value) - Converts any value into a string.

This list of features is non exhaustive. More features are currently being implemented. Thanks for checking out this project!

You might also like...
Lisp dialect scripting and extension language for Rust programs

Ketos Ketos is a Lisp dialect functional programming language. The primary goal of Ketos is to serve as a scripting and extension language for program

Rhai - An embedded scripting language for Rust.

Rhai - Embedded Scripting for Rust Rhai is an embedded scripting language and evaluation engine for Rust that gives a safe and easy way to add scripti

Interpreted language developed in Rust

Xelis VM Xelis is an interpreted language developed in Rust. It supports constants, functions, while/for loops, arrays and structures. The syntax is s

A rusty dynamically typed scripting language
A rusty dynamically typed scripting language

dyon A rusty dynamically typed scripting language Tutorial Dyon-Interactive Dyon Snippets /r/dyon Dyon script files end with .dyon. To run Dyon script

Source code for the Mun language and runtime.

Mun Mun is a programming language empowering creation through iteration. Features Ahead of time compilation - Mun is compiled ahead of time (AOT), as

Scripting language focused on processing tabular data.
Scripting language focused on processing tabular data.

ogma Welcome to the ogma project! ogma is a scripting language focused on ergonomically and efficiently processing tabular data, with batteries includ

A safe-against-invalid-input version of wren.io, written in Rust.

safe_wren A nearly-complete implementation of the Wren language (wren.io) in Rust. The original https://github.com/wren-lang/wren from wren.io is refe

A Python compiler targeting JS, implemented in Rust.

A Python compiler targeting JavaScript, implemented in Rust.

 Diplo is a script runner and dependency manager made in rust mainly for Deno.
Diplo is a script runner and dependency manager made in rust mainly for Deno.

Diplo is a script runner and dependency manager made in rust mainly for Deno. Documentation Tricked.pro/diplo Installing - windows installer Features

Owner
Luke Chu
I enjoy coding and gaming.
Luke Chu
Implementation of Immix Mark-Region Garbage collector written in Rust Programming Language.

libimmixcons Implementation of Immix Mark-Region Garbage collector written in Rust Programming Language. Status This is mostly usable library. You can

playX 34 Dec 7, 2022
REPL for the Rust programming language

Rusti A REPL for the Rust programming language. The rusti project is deprecated. It is not recommended for regular use. Dependencies On Unix systems,

Murarth 1.3k Dec 20, 2022
Oxide Programming Language

Oxide Programming Language Interpreted C-like language with a Rust influenced syntax. Latest release Example programs /// recursive function calls to

Arthur Kurbidaev 113 Nov 21, 2022
The hash programming language compiler

The Hash Programming language Run Using the command cargo run hash. This will compile, build and run the program in the current terminal/shell. Submit

Hash 13 Nov 3, 2022
🍖 ham, general purpose programming language

?? ham, a programming language made in rust status: alpha Goals Speed Security Comfort Example fn calc(value){ if value == 5 { return 0

Marc Espín 19 Nov 10, 2022
A small programming language created in an hour

Building a programming language in an hour This is the project I made while doing the Building a programming language in an hour video. You can run it

JT 40 Nov 24, 2022
The Loop programming language

Loop Language Documentation | Website A dynamic type-safe general purpose programming language Note: currently Loop is being re-written into Rust. Mea

LoopLanguage 20 Oct 21, 2022
Stackbased programming language

Rack is a stackbased programming language inspired by Forth, every operation push or pop on the stack. Because the language is stackbased and for a ve

Xavier Hamel 1 Oct 28, 2021
A static, type inferred and embeddable language written in Rust.

gluon Gluon is a small, statically-typed, functional programming language designed for application embedding. Features Statically-typed - Static typin

null 2.7k Dec 29, 2022
sublingual: toy versions of existing programming languages

sublingual: toy versions of existing programming languages This is a collection of toy languages created by taking much "larger" languages (e.g. Rust)

Eduard-Mihai Burtescu 20 Dec 28, 2022