From a1039d88c4122a8515830fe5f1d54e4fa758b183 Mon Sep 17 00:00:00 2001 From: SFJ Date: Thu, 31 Oct 2024 14:54:16 +0100 Subject: [PATCH] Add chapter 8 --- compiler/chapter_8.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 compiler/chapter_8.md diff --git a/compiler/chapter_8.md b/compiler/chapter_8.md new file mode 100644 index 0000000..9c15744 --- /dev/null +++ b/compiler/chapter_8.md @@ -0,0 +1,31 @@ + +# Types + +We'd like to be able to compile to a relatively low level. To this end, we need to have predetermined the types of the values used in the program code. + +## Explicit types + +For a type checker to be able to determine all the types of all values, the program is required to contain the information need. That information will be dictated by the programmer, therefore the programmer needs a way to write types explicitly. We'll do this by adding types to the language. + +### Syntax + +We'll need explicit typing for the following types: null, int, string, bool, array, struct and function. + +``` +``` + +## Types in AST + +```ts +type Expr = { + // ... + valueType: ValueType, +} +``` +```ts +type Stmt = { + // ... + valueType: ValueType, +} +``` +