v6 Parsing: type annotations and signatures
Lesson, slides, and applied problem sets.
View SlidesLesson
v6 Parsing: type annotations and function signatures
New syntax
let x: number = 1;
fn add(a: number, b: number) -> number { return a + b; }
Type grammar
type -> simple | fnType
simple -> number | bool | string | nil
| array<type>
| map<type, type>
fnType -> fn("typeList?") -> type
Parser changes
varDeclparses optional: typeafter name.fnDeclparses param types and requires return type.- New AST nodes:
Typetree.
AST additions
Stmt.TypeAnn *Typefor variables.Stmt.ParamTypes []*TypeandStmt.ReturnType *Typefor functions.