diff --git a/README.md b/README.md index 0ff8512..b88e431 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The Sabre compiler emits JavaScript, until the language has matured sufficiently fn main() { let num = 10 - print(fib(num)) + println(fib(num)) } fn fib(n) { diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 04c9d13..103df1d 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -5,3 +5,4 @@ - [Hello World!](./introduction/hello-world.md) - [Common language concepts](./concepts/SUMMARY.md) - [Variables](./concepts/variables.md) + - [Data Types](./concepts/datatypes.md) diff --git a/docs/concepts/datatypes.md b/docs/concepts/datatypes.md new file mode 100644 index 0000000..5bb6bc0 --- /dev/null +++ b/docs/concepts/datatypes.md @@ -0,0 +1,61 @@ +# Datatypes + +> **Note:** Due to the fact that Sabre currently emits javascript, static types are not needed, as of yet. They will however be introduced soon, once a statically typed backend is used. + +## The Integer type + +The `integer` datatype represents a number. The JavaScript backend interprets any integer as a `Number` type. + +``` +fn main() { + let sum = 1 + 2 + println("1 + 2 is ", sum) +} +``` + +``` +$ sabre build main.sb -o main.js +$ node main.js +1 + 2 is 3 +``` + +## The String type + +A string is a sequence of characters. + +``` +fn main() { + let name = "Jon" + println("Hello " + name) +} +``` + +``` +$ sabre build main.sb -o main.js +$ node main.js +Hello Jon +``` + +## The Array type + +Arrays represent a sequence of values. They can hold any number of values of a specific type. + +> **NOTE:** Currently, there is no type-checking involved when creating arrays. There will be, once a type system is in place, so don't get too attached to mixing and matching element types. ;) + +``` +fn main() { + let fruits = ["Banana", "Apple", "Pineapple"] + + for fruit in fruits { + println(fruit) + } +} +``` + +``` +$ sabre build main.sb -o main.js +$ node main.js +Banana +Apple +Pineapple +``` diff --git a/docs/concepts/variables.md b/docs/concepts/variables.md index 5dc73fc..322424d 100644 --- a/docs/concepts/variables.md +++ b/docs/concepts/variables.md @@ -9,7 +9,7 @@ To declare a variable, the `let` keyword is used. fn main() { let x = 10 let y = 5 - print(x + y) + println(x + y) } ``` diff --git a/docs/introduction/hello-world.md b/docs/introduction/hello-world.md index 4b0b118..7a73a63 100644 --- a/docs/introduction/hello-world.md +++ b/docs/introduction/hello-world.md @@ -21,7 +21,7 @@ Now open the main.sb file you just created and enter the following code: ``` fn main() { - print("Hello, world!") + println("Hello, world!") } ``` diff --git a/examples/fib.sb b/examples/fib.sb index 557d65c..683b902 100644 --- a/examples/fib.sb +++ b/examples/fib.sb @@ -1,6 +1,6 @@ fn main() { let num = 10 - print(fib(num)) + println(fib(num)) } fn fib(n) { diff --git a/examples/greeter.sb b/examples/greeter.sb index 1888a78..c27bb4e 100644 --- a/examples/greeter.sb +++ b/examples/greeter.sb @@ -1,5 +1,5 @@ fn main() { - print(greet("World")) + println(greet("World")) } fn greet(name) { diff --git a/examples/hello_world.sb b/examples/hello_world.sb index 061cd6f..36c1789 100644 --- a/examples/hello_world.sb +++ b/examples/hello_world.sb @@ -1,3 +1,3 @@ -fn main(n) { - print("Hello World") +fn main() { + println("Hello World") } diff --git a/examples/leapyear.sb b/examples/leapyear.sb index 483923b..add3e31 100644 --- a/examples/leapyear.sb +++ b/examples/leapyear.sb @@ -10,8 +10,8 @@ fn main() { let ly = divisibleBy4 && divisibleBy100 if ly || divisibleBy400 { - print("Leap year") + println("Leap year") } else { - print("Not a leap year") + println("Not a leap year") } } \ No newline at end of file diff --git a/examples/playground.sb b/examples/playground.sb index dc5f7a7..9f41721 100644 --- a/examples/playground.sb +++ b/examples/playground.sb @@ -1,5 +1,5 @@ fn main() { let x = 10 x = 5 - print("Hello World!") + println("Hello World!") }