Matchbox 0.2

Syntax Overview

Matchbox source files use the .mb extension. Programs are composed of function definitions, statements, expressions, and comments. Matchbox is statically typed, so declarations, inferred variables, function parameters, and return values all have types known at compile time.

Declarations and Definitions

Variables use var. A type follows the name without a colon:

var value int
value = 42

A declaration tells the compiler that a name exists. For variables, a declaration specifies the variable's name and type, and the type determines how much memory Matchbox reserves. A definition is a declaration that also gives the variable an initial value. Every definition is inherently a declaration, but not every declaration is a definition.

Knowing these types during compilation lets Matchbox report type-related mistakes before execution and keeps the generated bytecode aligned with the values each instruction expects.

Functions place parameter types after each parameter name and the return type after the parameter list:

func identity(value int) int {
    return value
}

Because int is the only type in 0.2, these annotations can be omitted:

func identity(value) {
    return value
}

Expressions

Expressions produce integer values. They can contain literals, names, function calls, unary operators, binary operators, and parentheses:

var result = max(10 + 5, 20)

Source Order

Names are resolved in source order. Declare variables and define functions before using them.

Line Endings

Statements can be separated by line breaks without semicolons:

var a = 10
var b = 20

A semicolon separates multiple statements on the same line:

var a = 10; var b = 20

Prefer one statement per line for readability.