Aspen

A toy programming language

Basics

Comments

Aspen uses C style comments.

// this is a line comment

/*
    this block comment
    can span multiple lines
*/

Printing

All output in Aspen is done through the print statement.

print "Hello, world!";
There is no way to read input in an Aspen program.

Variables

Variables are declared with the let keyword.

let n i64;
let foo string;

Aspen is statically typed, every variable must be annotated with a type. In the example above, n is a variable of type i64, a 64 bit integer and foo has type string.

There is no type inference in Aspen, every variable must be declared with a type.

All variables must be declared with a type

let name = "Arun Muthu";

name has been annotated with the type string

let name string = "Arun Muthu";

Reserved Keywords

Here is the list of keywords reserved by Aspen.

else for fn void if print return true false let while i64 u64 bool string double

Blocks

Similar to how parenthesis group multiple expressions into one big expression, a block groups multiple statements into one big statement. A block creates a local scope, variables declared inside a block will only be visible inside the block.

{
    let greeting string = "こんにちは";
    print greeting;
}
let welcome string = greeting + " Jordan."; // error, greeting is out of scope

Blocks always appear after an if, while or for statement.

if (12*12 > 100) {
    print "12*12 is greater than 100.";
}

Operators

PrecedenceOperatorDescriptionAssociates
1fn() () type()Function call, Grouping, Type castLeft
2! -Not, NegationRight
3/ * %Divide, Multiply, ModulusLeft
4+ -Add, SubtractLeft
5&Bitwise andLeft
6^Bitwise xorLeft
7|Bitwise orLeft
8> >= < <=ComparisonLeft
9== !=Equals, Not equalLeft
10&&Logic andLeft
11||Logic orLeft
12=AssignmentRight