Skip to content
Jiří Fatka edited this page Jun 20, 2017 · 15 revisions

Literals

Literals are special immutable values. Any operation which might change the literal value means an error (e.g. 5++).

Null literal

Null literal is represented by null keyword. It's used to specify the variable have not specified value. Cannot be used in typeless context (type deduction fails).

Boolean literal

Two keywords true and false is used to specify boolean variable value. Implicitly convertible to Bool type and type deduction yields Bool type (e.g. auto value = true; // Bool).

Integer literal

Literal represented by integer literal lexical element. Implicitly convertible to Int type and type deduction yields Int type.

Float literal

Literal represented by float literal lexical element. Implicitly convertible to Float type and type deduction yields Float type.

Character literal

Literal represented by char literal lexical element. Implicitly convertible to Char type and type deduction yields Char type.

String literal

Literal represented by string literal lexical element. Implicitly convertible to String type and type deduction yields String type.

Array literal

A sequence of literals of the same type separated by comma , (U+002C) character and surrounded by square brace characters [, ]. Type deduction yields type Array<T> where T is literals type. In constant context it yields type Array<T, N> where T is same as before and N is number of elements.

      auto arr1 = [1, 2, 3, 4, 5]; // Array<int>
const auto arr2 = [1, 2, 3, 4, 5]; // Array<int, 5>

Map literal

Tuple literal

Expressions

Binary

Unary

Ternary

Paren

FunctionCall

MemberAccess

Subscript

Statements

Expr statement

Declaration statement

Compound statement

If statement

While loop

Do-while loop

For loop

Switch statement

Return statement

Declarations

Variable declaration

Declare a variable with given name for current scope. Symbol name (identifier) must be unique within declaration scope. It can be same as another symbol in parent scope but it hides the parent symbol.

The variable must have specified type and optionally initial value. Type name can be replaced by var keyword. In this case the variable can store any value. Case with auto keyword requires initializer and variable type is deduced from result of the initializer expression.

Specifier const makes variable immutable.

[ 'const' ] typename identifier [ '=' expression ] ';'
[ 'const' ] 'var' identifier [ '=' expression ] ';'
[ 'const' ] 'auto' identifier '=' expression ';'

Function declaration

Class declaration

Namespace declaration

Clone this wiki locally