Add to chapter 8

This commit is contained in:
sfja 2024-10-31 22:47:37 +01:00
parent a1039d88c4
commit c599d846f5
2 changed files with 22 additions and 1 deletions

View File

@ -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]`.

View File

@ -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