Skip to content

Instantly share code, notes, and snippets.

@natescode
Last active September 25, 2019 18:33
Show Gist options
  • Save natescode/36ca23f74441701ce378e1a552fd7f5e to your computer and use it in GitHub Desktop.
Save natescode/36ca23f74441701ce378e1a552fd7f5e to your computer and use it in GitHub Desktop.
Silicon / Sigil Language Definition

Si

Comments

// Single Line

/*
    Multi-Line

    Comment
*/

Keywords

@package Main

@if @true {
    // ...code...
}

Variables

// Let is for constants
// Strings are immutable unless you use 
@let name @str : "John"    
@let name : "John"
$name : "John"

@let age @num : 28
@let age : 18
$age : 18


$$MAX : 10

Sigils

@ - Keywords

@@ - Annotations

$ - Let Declaration

$$ - Var Declaration

^ - Nominal Type prefix

~ - Structural Type prefix

! - Mutable variable or method suffix Like convention in Ruby except this is enforced by the compiler.

// Mutable string
@str! 

// Method mutates passed data. Compiler enforces that at least one parameter is passed by reference and modified for functions and that at least a field or property is modified for methods.
#Reverse! arr

# - Method Call prefix

#Add 1,3

_ - Placeholder

[0:_]

@for ;_ < 10; {

}

a, _ : #GetTwoValues

? - Optional suffix (Like Nullable)

@num?

@let Div? $a $b : $b = 0 ? @nil : $a / $b 

Types

Silicon / Sigil is a strongly statically typed language with a very strong but flexible type system. You'll rarely see types explicitly declared as the compiler does type inference (but not auto conversion).

Silicon uses type hierarchies / unions to simplify the type system (making it run as an interpreted language quiet well too).

@num - signed integer Union of int(8|16|32|64|128) and float(32|64|128). Unlike C unions only the memory size of the used type. Generic Union or Dynamic Union. Like how we can declare an array of arbitrary size.

@nat - natural number uint(8|16|32|64|128)

@str - immutable string supports Unicode

@str! - mutable string supports Unicode

@bool - boolean @true | @false. Alias for @Bits(1).

@char - UTF-8 /16 and Unicode support. Alias for uint8 / uint16 but with different Nominal type which then has different methods / operators associated with it as well.

@bits - An arbitrarily sized continuous block of bits (Like Cell in Scheme)

Keywords

All keywords are prepended with the @ sigil.

Loop keywords

when inside loops there are some keywords that are just syntatical sugar for commonly used statements.

for $i range arr { ##Print arr[i+1]
// ^ could be written as the following ##Print $$next }

@next -> arr[i+1] @previous -> arr[i-1] @first -> arr[0] @last -> arr[len(arr)-1]

@darilrt
Copy link

darilrt commented Sep 23, 2019

The goals for my lang are, make the c programming more readable, i use the python syntax and compile to c, is like statically typed python but add enum, switch, pointers, memory allocations, templates. For c add class, methods, package structures, auto type detection like go-lang :=, lambdas, for eachs, and more features of others langs.

The first version of compiler is writted in python, haven't finished it yet.
Then i will write in slex (is the name of my lang)

Currently the lang compile but lack features.

I have simple document about syntax: Slex doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment