Skip to content
← projects

ELV.

A high-level, dynamic, functional programming language — built from scratch to learn how language runtimes work, and playable right here in your browser.

source on github

Live REPL

elv — repl

How it works

  1. 01

    Lexer

    Source text is scanned into a stream of tokens.

  2. 02

    Parser

    A recursive-descent parser builds an AST from the tokens.

  3. 03

    Interpreter

    A tree-walking evaluator executes the AST directly.

Language reference

Semicolons

; ends expressions and declarations.

var a = 10;
a + b;

Variables

var declares a binding; multi-assignment supported.

var a = 10;
var a, b = 1;

Primitives

Four primitive types — number, string, boolean, nil.

var n = 10;
var s = "name";
var t = true;
var z = nil;

Comments

Anything between ## and #/.

## this is
a comment #/

Loops

A single for loop construct.

for (var i = 0; i < 10; i = i + 1) [
  print(i);
]

Conditions

if / if-else.

if (a > 5) [
  ## ... #/
] else [
  ## ... #/
]

Operators

Binary and unary — arithmetic, comparison, logical.

a + b;  a - b;  a * b;  a / b;
a > b;  a == b;  a != b;
a & b;  a | b;  !a;  -a;

Functions

First-class — pass and return functions. def to define, ret to return.

def apply(f, x) [ ret f(x); ]