diff --git a/compiler/chapter_2.md b/compiler/chapter_2.md index feb1eb9..86d7e8e 100644 --- a/compiler/chapter_2.md +++ b/compiler/chapter_2.md @@ -405,7 +405,7 @@ while (token !== null) { ## Exercises -1. Implement the operators: `-`, `*`, `/`, `(`, `)`, `.`, `,`, `;`, `[`, `]`, `!=`, `<`, `>`, `<=` and `>=`. +1. Implement the operators: `-`, `*`, `/`, `(`, `)`, `.`, `,`, `:`, `;`, `[`, `]`, `!=`, `<`, `>`, `<=`, `>=` and `->`. 2. Implement the keywords: `true`, `false`, `null`, `or`, `and`, `not`, `loop`, `break`, `let`, `fn` and `return`. 3. \* Implement single line comments using `//` and multiline comments using `\*` and `*\` (\*\* extra points if multiline comments can be nested, eg. `/* ... /* ... */ ... */`). 4. \* Reimplement integers such that integers are either `0` or start with `[1-9]`. diff --git a/compiler/chapter_8.md b/compiler/chapter_8.md index 9c15744..3dda944 100644 --- a/compiler/chapter_8.md +++ b/compiler/chapter_8.md @@ -11,9 +11,30 @@ For a type checker to be able to determine all the types of all values, the prog We'll need explicit typing for the following types: null, int, string, bool, array, struct and function. +We want to be able to specify types in let-statements and fn-statements, like the following. + +```rs +let a: int = 5; + +fn add(a: int, b: int) -> int { /*...*/ } ``` + +For array and function types, we also want to specify details like contained type, return type and parameter types, like the following. + +```rs +let op: fn(int, int) -> int = add; + +let values: [int] = array(); ``` + + +### Parsing parameters + +Both function definitions and let-statements use parameters. + +### Parsing functions + ## Types in AST ```ts