From a778dbd8e81ac02db4171b68fc2ac59fc0eb344d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Wed, 3 Feb 2021 22:02:47 +0100 Subject: Start work on the languge spec --- SPEC.md | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 SPEC.md diff --git a/SPEC.md b/SPEC.md new file mode 100644 index 0000000..d0aa7be --- /dev/null +++ b/SPEC.md @@ -0,0 +1,106 @@ +# Sylt-lang +----------- +The language specification, also known as "the less fun" document. + +For goals and the like, see the README.md file. + +## The syntax by example + +I choose to include programs here, that should be valid +in Sylt programs if all goes to plan. + +```sylt +a := 1 +b : int = a +print(b) // 1 +``` +Here we can see variable declaration, types and +the calling of simple functions. + +### Definition statement +```sylt +a := 1 // Define a to be 1, automatically infers int as type. +b : int = 1 // Define b to be 1, explicitly as int. +c : int = 0.4 // A compilation error, since types don't match. + +// The definition of a function, that takes +// one argument and returns an integer value. +d := fn a: int -> int { + ret a + 1 +} + +// Destructuring a tuple is allowed, after the definiton +// e = 1, f = 2, g = 3. +// If the number of variables doesn't match the length +// of the tuple, that would raise a compilation error. +e, f, g := (1, 2, 3) + +q := 1 +q := 1 // You are not allowed to re-declare variables + +z := 1 +{ + z := z // This is allowed since this inner z is a differnt variable. +} +``` + +### If-statements +```sylt +// Basic if-statements +if some_boolean_value { + do_on_true() +} + +// With else statement +if some_boolean_value { + do_on_true() +} else { + do_on_false() +} + +// If-else statements +if some_boolean_value { + do_on_true() +} else if some_other_value { + do_on_second_true() +} +``` + +### For-loops +```sylt +// 'Normal' For-loop +// Would print numbers 0-9 +for i := 0, i < 10, i++ { + print(i) +} + +// 'Enhanced' For-loop +// Would print the numbers 1, 2, 3 and 4 +// More precisely, all in the collection +// specified after the 'in' keyword. +for i in (1, 2, 3, 4) { + print(i) +} + +// 'Infinite' For-loop +// The loop would run forever, or until +// a piece of control flow causes it to jump +// out of the loop. Here we use 'break'. +for { + print(1) + break; +} + +// 'After-doer' +// Any form of code can be placed +// after an arrow, this will be run AFTER +// each cycle. +for -> { + +} -> { + print(1) + break; +} + +``` + -- cgit v1.2.1 From 635ea8b5c5c16be2780e6aa1fdb7baa8c6d46783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Thu, 4 Feb 2021 11:55:34 +0100 Subject: add more to the spec --- SPEC.md | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/SPEC.md b/SPEC.md index d0aa7be..f05ac9c 100644 --- a/SPEC.md +++ b/SPEC.md @@ -29,6 +29,10 @@ d := fn a: int -> int { ret a + 1 } +// Constant +a :: 1 +a = 2 // This is illegal + // Destructuring a tuple is allowed, after the definiton // e = 1, f = 2, g = 3. // If the number of variables doesn't match the length @@ -91,16 +95,45 @@ for { break; } -// 'After-doer' -// Any form of code can be placed -// after an arrow, this will be run AFTER -// each cycle. -for -> { - -} -> { - print(1) - break; +``` + +### Functions +All functions are values. +```sylt +// Declare and create the function +f :: fn { + print "A" } +// Semantically equivalent +f() +f! +// Declare and create the function +f :: fn a:int -> int { + print a + ret a + 1 +} +// Semantically equivalent +f 1 +f(1) + +// Closures exist +q := 1 +g :: fn -> int { + ret q // Here the variable 'q' is captured +} +q = 2 +print g! // prints 2 + +// Supports heigher order functions +h :: fn -> fn -> int { + ret fn -> int { ret 2 } +} +print h()() // prints 2 ``` +### Special syntax +```sylt + // The unreachable statement, it should never be executed +1 <=> 1 // Asserts equality, so the program crashes if 1 != 1 +``` -- cgit v1.2.1 From d9a6df3fc4d9ab596a76aadb07dacd7205fb06de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 5 Feb 2021 19:13:42 +0100 Subject: rename and fix gramer --- DESIGNDOC.md | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ SPEC.md | 139 -------------------------------------------------------- 2 files changed, 145 insertions(+), 139 deletions(-) create mode 100644 DESIGNDOC.md delete mode 100644 SPEC.md diff --git a/DESIGNDOC.md b/DESIGNDOC.md new file mode 100644 index 0000000..4cceb84 --- /dev/null +++ b/DESIGNDOC.md @@ -0,0 +1,145 @@ +# Sylt-lang + +The language specification, also known as the "less fun" document. + +For goals and the like, see the README.md. + +## The syntax by example + +We choose to include programs here. They should be valid in Sylt programs if all +goes to plan. + +```sylt +a := 1 +b : int = a +print(b) // 1 +``` + +Here we can see variable declaration, types and calling of simple functions. + +### Definition statement + +```sylt +a := 1 // Define a to be 1. automatically infers int as type. +b : int = 1 // Define b to be 1, explicitly as int +c : int = 0.4 // Invalid: Types don't match + +// The definition of a function that takes +// one argument and returns an integer value. +d := fn a: int -> int { + ret a + 1 +} + +// Constant +a :: 1 +a = 2 // Invalid + +// Destructuring a tuple is allowed. After the definiton we have: +// e = 1, f = 2, g = 3. +// +// The number of variables need to match the length of the tuple. +e, f, g := (1, 2, 3) +h, i := (1, 2, 3) // Invalid + +q := 1 +q := 1 // Invalid: You are not allowed to re-declare variables + +z := 1 +{ + z := z // Valid: The inner z is a different variable +} +``` + +### If-statements + +```sylt +// Basic if-statement +if some_boolean_value { + do_on_true() +} + +// With else-statement +if some_boolean_value { + do_on_true() +} else { + do_on_false() +} + +// If-else-statements +if some_boolean_value { + do_on_true() +} else if some_other_value { + do_on_second_true() +} +``` + +### For-loops + +```sylt +// 'Normal' for-loop +// Prints the numbers 0-9 +for i := 0, i < 10, i++ { + print(i) +} + +// 'Enhanced' for-loop +// Iterates over the collection after 'in'. +// This example prints the numbers 1, 2, 3 and 4 in order. +for i in (1, 2, 3, 4) { + print(i) +} + +// 'Infinite' for-loop +// The loop will run forever, or until +// a piece of control flow causes it to jump +// out of the loop. Here we use 'break'. +for { + print(1) + break; +} + +``` + +### Functions + +All functions are values. + +```sylt +// Declare and create a function +f :: fn { + print "A" +} +// These are semantically equivalent +f() +f! + +// Declare and create a function +f :: fn a: int -> int { + print a + ret a + 1 +} +// These are semantically equivalent +f 1 +f(1) + +// Closures exist +q := 1 +g :: fn -> int { + ret q // Here the variable 'q' is captured +} +q = 2 +print g! // prints 2 + +// Supports higher-order-functions +h :: fn -> fn -> int { + ret fn -> int { ret 2 } +} +print h()() // prints 2 +``` + +### Special syntax + +```sylt + // The unreachable statement. If it is executed the program halts. +1 <=> 1 // Asserts equality. If the assert fails the program halts. +``` diff --git a/SPEC.md b/SPEC.md deleted file mode 100644 index f05ac9c..0000000 --- a/SPEC.md +++ /dev/null @@ -1,139 +0,0 @@ -# Sylt-lang ------------ -The language specification, also known as "the less fun" document. - -For goals and the like, see the README.md file. - -## The syntax by example - -I choose to include programs here, that should be valid -in Sylt programs if all goes to plan. - -```sylt -a := 1 -b : int = a -print(b) // 1 -``` -Here we can see variable declaration, types and -the calling of simple functions. - -### Definition statement -```sylt -a := 1 // Define a to be 1, automatically infers int as type. -b : int = 1 // Define b to be 1, explicitly as int. -c : int = 0.4 // A compilation error, since types don't match. - -// The definition of a function, that takes -// one argument and returns an integer value. -d := fn a: int -> int { - ret a + 1 -} - -// Constant -a :: 1 -a = 2 // This is illegal - -// Destructuring a tuple is allowed, after the definiton -// e = 1, f = 2, g = 3. -// If the number of variables doesn't match the length -// of the tuple, that would raise a compilation error. -e, f, g := (1, 2, 3) - -q := 1 -q := 1 // You are not allowed to re-declare variables - -z := 1 -{ - z := z // This is allowed since this inner z is a differnt variable. -} -``` - -### If-statements -```sylt -// Basic if-statements -if some_boolean_value { - do_on_true() -} - -// With else statement -if some_boolean_value { - do_on_true() -} else { - do_on_false() -} - -// If-else statements -if some_boolean_value { - do_on_true() -} else if some_other_value { - do_on_second_true() -} -``` - -### For-loops -```sylt -// 'Normal' For-loop -// Would print numbers 0-9 -for i := 0, i < 10, i++ { - print(i) -} - -// 'Enhanced' For-loop -// Would print the numbers 1, 2, 3 and 4 -// More precisely, all in the collection -// specified after the 'in' keyword. -for i in (1, 2, 3, 4) { - print(i) -} - -// 'Infinite' For-loop -// The loop would run forever, or until -// a piece of control flow causes it to jump -// out of the loop. Here we use 'break'. -for { - print(1) - break; -} - -``` - -### Functions -All functions are values. -```sylt -// Declare and create the function -f :: fn { - print "A" -} -// Semantically equivalent -f() -f! - -// Declare and create the function -f :: fn a:int -> int { - print a - ret a + 1 -} -// Semantically equivalent -f 1 -f(1) - -// Closures exist -q := 1 -g :: fn -> int { - ret q // Here the variable 'q' is captured -} -q = 2 -print g! // prints 2 - -// Supports heigher order functions -h :: fn -> fn -> int { - ret fn -> int { ret 2 } -} -print h()() // prints 2 -``` - -### Special syntax -```sylt - // The unreachable statement, it should never be executed -1 <=> 1 // Asserts equality, so the program crashes if 1 != 1 -``` -- cgit v1.2.1 From 4305d8074dad8713e5ac0c855ec93898473a5222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 5 Feb 2021 19:14:51 +0100 Subject: yikes --- DESIGNDOC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESIGNDOC.md b/DESIGNDOC.md index 4cceb84..702851b 100644 --- a/DESIGNDOC.md +++ b/DESIGNDOC.md @@ -6,7 +6,7 @@ For goals and the like, see the README.md. ## The syntax by example -We choose to include programs here. They should be valid in Sylt programs if all +We choose to include programs here. They should be valid Sylt programs if all goes to plan. ```sylt -- cgit v1.2.1