# Statements

Statements define the program itself and what it will execute. Statements are a collection of what the language can do, these include for instance: expressions, functions and control flow.

statement =
  expression_statement |
  declaration |
  type_specification |
  comment |
  block |
  body |
  parameters |
  parameter |
  function |
  return ;

See expression for details about expressions.
See functions for details about functions.
See control flow for details about control flow like choice and loops.

# Expressions

An expression is also a statement as some expressions can be used inline, like the assignment expression.

# EBNF Notation

expression_statement = expression ;

See expression for details about expressions.

# Example

// "foo" has been declared beforehand

foo = 2

// An expression used as an statement

# Declaration

To work with variables you need to declare them first. A declaration exists of three parts. The first is the type of variable to declare: a var or val An optional type specification can be added after the var/val keyword to specify the type. When this is left out it will try to infer the type based on the givin expression. The last part of a declaration is the expression. When no value is needed and only the variable, the expression should be resolved as an identifier. When you need to assign a value to the variable the expression should resolve in an assignment expression.

# EBNF Notation

declaration = "var" | "val" , ( [ ":" , name ] , expression | ":" , name , expression  ) ;

# Example

val foo = 'string'
var: Integer bar = 64
val baz = 7 * 8

See variables for details about variables.
See expression for details about expressions.

# Type specification

Used to specify the type of a function or variable. This is in some cases optional as the compiler tries to infer the type when possible. In some cases it is mandatory to specify the type like in parameters.

# EBNF Notation

type_specification = ":" , name ;

# Example

val: string foo
val: Integer bar = 12

fun: string baz {
  return 'Hello World'
}

fun: string qux(name: string) {
  return 'Hello $name'
}

# Comment

Comments can be optionally parsed by the parser. This is for future use when comments can contain references to the actual code to describe certain features of said code (like JSDoc (opens new window)).

# EBNF Notation

comment = comment_token ;

# Example

val foo = true // This is an comment

# Block

A block statement is a collection of statements. This can contain any valid statement for the scope the block is used in.

# EBNF Notation

block = { statement } ;

# Body

A body is the same as a block except that a body statements requires the curly brackets to be included in the statement.

# EBNF Notation

body = "{" , { statement } , "}" ;

# Parameters

Used for passing variables or data to a function. It contains its parenthesis and a collection of parameters.

# EBNF Notation

parameters = "(" , { parameter } , ")" ;

# Example

fun: string foo(name: string, age: integer){
  return '$name is $integer years old!'
}

// (name: string, age: integer)
// This part of the function is the parameter statement

# Parameter

A parameter is a used inside the parameters statement to define a set of parameters. A paramater has a name and mandatory type specification. The last part of the paramater statement is an optional comma token. When there is more then one parameter the comma is mandatory. when there is only one parameter or on the last parameter the comma is optional. This is also known as a trailing comma and is supported for parameters.

# EBNF Notation

parameter = name , type_specification , [ "," ] ;

# Example

fun: string foo(name: string, age: integer){
  return '$name is $integer years old!'
}

// name: string,
// age: integer
// These two parts of the function are parameters

fun: string bar(name: string, age: integer,){
  return '$name is $integer years old!'
}

// name: string,
// age: integer,
// These are the same as stated above but age now has an trailing comma

# Function

A function statement is a complex statment to declare a function an consists of several parts some of which are optional (See functions).

First is the fun keyword, after that is an optional type specification. A type specification on a function mandates that the function returns a value from all paths. After that the function name should be declared. Then an optional statment for the parameters. Lastly the function body.

# EBNF Notation

function = "fun" , [ type_specification ] , name , [ parameters ] , body ;

# Example

fun foo {
    // Do something
}

fun bar(firstName: string, lastName: string) {
   // Do something
}

fun: string baz(firstName: string, lastName: string) {
   val greet = 'Hello' + firstName + lastName
   return greet
}

See functions for details about functions.

# Return

Used for exiting a function or returning a value from a function. It consist of the return keyword and an optional expression that could be returned

# EBNF Notation

return = "return" , [ expression ] ;

# Example

fun foo() {
   return
}

fun bar() {
   val a = 12
   return
   val b = a * 2
}

// val b = a * 2
// This part will never be executed

fun: string baz() {
   return 'Hello World'
}

fun: string qux() {
   return 12 * 4 + 2
}