Matchbox 0.2

Statements

Matchbox 0.2 supports variable declarations, assignments, function definitions, expression statements, and return statements.

Variable Declarations and Definitions

A variable declaration tells the compiler that a variable exists. It gives the variable's name and type, and the type tells Matchbox how much memory to reserve for the variable:

var count int

A variable definition also gives the variable an initial value:

var total = 0
var limit int = 10

Every definition is inherently a declaration, but not every declaration is a definition. A declaration without an initializer still reserves the memory required by its type, but it must be assigned before it is read.

Assignments

An assignment stores a value in an existing variable:

var count = 0
count = 1
count += 2

Compound arithmetic assignments are listed in Operators. Assignment does not produce a value and cannot be nested inside another expression.

Function Definitions

A function definition introduces a callable name:

func square(value int) int {
    return value * value
}

The definition must appear before its calls.

Matchbox 0.2 does not have separate function declarations or prototypes. A function name is introduced by the full definition, including its body.

Expression Statements

An expression can be used as a statement. Function calls are the most useful example:

print(42)
exit()

The result of a value-producing expression statement is discarded.

Return Statements

A return statement ends the current function and requires an integer expression:

return result

An empty return is not supported. A function that reaches its closing brace without returning a value produces 0.

Separating Statements

Statements are normally separated by line breaks. A semicolon is required between multiple statements on the same line:

var a = 10; var b = 20

Prefer one statement per line for readability.