Add to chapter 8
This commit is contained in:
parent
a1039d88c4
commit
c599d846f5
@ -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]`.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user