nonsensation

Table of Contents

Introduction

Getting Started

Installation

Hello World

Lexical & Grammer

Character Set
Character:
    any Unicode character
End of File (EOF)
EndOfFile:
    end-of-file
    \0
End of Line
EndOfLine:
    \n
    EndOfFile
White Space
Space:
    ;
    \t

WhiteSpace:
    Space
    Space WhiteSpace
Comments
Comment:
    LineComment

LineComment:
    # Characters EndOfLine

Characters:
    Character
    Character Characters

Compilation Stages

Lex -> Parse -> Binding & Type Resolution -> Prerun

Comments

Keywords, Reserved Identifiers & Literals

Keywords

Contextual Keywords

Keyword Literals

true false null nul undefined nan nil inf

Types

Fundamental Types

Name Equivalent in C Default Initialization Description
bool bool false Boolean type (true or false)
void void -  
i8 int8_t 0  
i16 int16_t 0  
i32 int32_t 0  
i64 int64_t 0  
u8 unt8_t 0  
u16 unt16_t 0  
u32 unt32_t 0  
u64 unt64_t 0  
f32 float 0.0  
f64 double 0.0  
isize intptr_t null  
usize uintptr_t null  
type object  

User-Defined Types

Classes

Datatypes

Enumerations

Builtin Types

In the core module:

Arrays

Ranges & Slices

Literals

Numeric Literals

Integer Literals

var x1 = 0
var x2 = 0xff        # hexadecimal literal
var x3 = 0c001       # octal literal
var x4 = 0b10101010  # binary literal

Decimal Literals

Digit Seperators

The underscore _ can be used to separate digits in numeric literals:

var x = 1_000_000_000
var x = 0xffff_1234_c0de
var x = 1'000'000'000
var x = 0xffff'1234'c0de

String Literals

Character Literals

The defer Statement

Syntax:

DeferStatement : defer Expression
               | defer BlockStatement
               ;

Defers the execution of the expression or blockstatement until the end of the current scope. Expressions will be evaluated in reversed declaration order:

defer print( "1" )
defer print( "2" )
defer {
    print( "3" )
    print( "4" )
}

Will result in:

3
4
2
1

Pattern Matching - The match Expression/Statement

Pattern Matching can be used both: as a stand alone statement and also as an expression e.g. in an return statement or variable assignment.

Syntax:

MatchStatementExpression :
    match variableExpression
    {}
        | DiscardIdentifier => Statement 
        }
               ;

If no binary operator is given in the PatternExpressionClause, the value of the input expression is compared via operator ==.

Examples

Simple example, matching enum or integer-like values:

match x {
    MyEnum.A => print( "Enumeration" )
          42 => print( "Integer" )
}

Matching a range of integers:

match x {
    in 1 to 10 => print( "Value in Range 1 to 10 is {x}" )
}

Matching characters:

match x {
    "A" => print( "Character A" )
    in "A" to "Z" => print( "Character in Range A to Z was {x}" )
}

Matching multiple patterns, separated by a comma:

match x {
    in "a" to "z" ,
    in "A" to "Z" => print( "Multiple pattern" )
}

Multiple statements in a Blockstatement:

match x {
    # Multiple statements in a Blockstatement
    MyEnum.B => {
            print( "multiple" )
            print( "statements" )
        }
}

Matching null:

match x {
    null => print( "null" )
}

The default/match-any/wildcard case.

TODO: Should almost always be the last case. OR: Is evaluated as last (else-branch) regardless of declaration order.

match x {
     _ => print( "default, match-any, wildcard" )
}

Jumping to other patterns using goto and a label-attribute:

match x {
    # Jump to another pattern using goto:
    MyEnum.C => goto MyEnum.A

    # Declare a label with an attribute on a pattern:
    MyEnum.D @label "catdog" => print( "label" )

    # Jump to a label:
    MyEnum.D => goto "catdog"
}

TODO Matching against a type pattern:

match x {
    is MyType => print( "" )
}

TODO

  • type-pattern-matching:
    • handle most derived cases first
    • compiler error, when wrong order
    • what to do when multiple inheritance?
  • @partial attribute to mark match as non exhaustive (match-any case required)
    • is this even needed? (think of cases)
    • make it either:
      • exhaustive
      • require default
  • match any non-null variable (c# uses {})
  • match Property:
    • C#: if( value is { Length: 2 } val ) // matches non null with property of .Length = 2 See

Expression-Statements

var x = a ? b : c ? d : e

var x = when a then b
        elif c then d
        else e

var value = if a do b
       else if c do d
       else e

var x = a ?? b ?? c

var x = when a != null then a
        elif b != null then b
        else c

Basic Blocks

Variable Declarations

Function Declarations

Type Declarations

Statements

Types Of Stamements

Selection Statements
Branch to different sections of the code, based on one or multiple conditions.
Expression Statements
Definition
Iteration Statements
Definition
Jump Statements
aefsd

Declaration Statements

Expression Statements

Selection Statements

The if-Statement

The match-Statement

Iteration STatements

The loop-Statement

The for-Statement

Jump Statements

The return-Statement

The break-Statement

The continue-Statement

The yield-Statement

The defer-Statement

The Expression-Statement

The Global-Statement

The Block-Statement