1.1 Minilang Syntax

Types

Minilang contains three types: int for representing integers, bool for representing truth values and void for denoting lack of type.

type int | bool | void

Literals

There are literals for representing Boolean and integer values.

literal boolean‑literal | integer‑literal
boolean‑literal true | false
integer‑literal digit‑sequence
digit‑sequence [0-9]+

Identifiers

A Minilang identifier can contain non-ASCII letters also. Minilang source files are expected to be UTF-8 encoded for this to work.

identifier Unicode identifier

Expressions

The grammar productions

determine the precedence levels of the minilang operators in the order of decreasing precedence.

primary‑expression literal | identifier | ( expression )
postfix‑expression primary‑expression ( ( expression‑list? ) )*
expression‑list expression ( , expression )*
unary‑expression unary‑op unary‑expression | postfix‑expression
unary‑op + | - | !
multiplicative‑expression unary‑expression (multiplicative‑op unary‑expression )*
multiplicative‑op * | / | %
additive‑expression multiplicative‑expression (additive‑op multiplicative‑expression )*
additive‑op + | -
relational‑expression additive‑expression (relational‑op additive‑expression )*
relational‑op < | > | <= | >=
equality‑expression relational‑expression (equality‑op relational‑expression )*
equality‑op == | !=
expression equality‑expression

Statements

There are statements for sequence, choice and repetition, and for creating and assigning variables.

statement if‑statement | while‑statement | return‑statement | compound‑statement | construction‑statement | assignment‑statement
if‑statement if ( expression ) statement ( else statement )?
while‑statement while ( expression ) statement
return‑statement return expression?
compound‑statement { statement* }
construction‑statement type identifier = expression ;
assignment‑statement identifier = expression ;

Functions

Minilang functions can take parameters, do simple computations and return a result.

function type identifier ( parameter‑list? ) compound‑statement
parameter‑list parameter ( , parameter )*
parameter type identifier

Source Files

A minilang source file consists of a sequence of functions.

source‑file function*