Compilers aren’t magic, so let’s build one in Swift
summary
Claims that compilers aren’t magic and builds a working compiler in Swift for a tiny BASIC‑like language called bitsy, implementing a BASIC‑like "bitsy" language with integer-only variables, loop/break/conditionals, and comment handling. Walks through a hand‑rolled tokenizer → recursive‑descent parser → Swift codegen pipeline, shows token format, disambiguation of identifiers vs keywords, use of Swift pattern matching and temporary registers, and emits Swift source that is compiled with swiftc into an executable.
AI-written summary · about
chapters (25)
- 0:00Intro
- 2:33What is a compiler
- 3:36Swift as language
- 5:52What have we learned
- 6:43Target language
- 10:16Choose language to target
- 10:28Know how to write
- 11:14Read source characters
- 11:54Tokenization
- 12:50Language Elements
- 13:56Implement commending
- 14:31Integer
- 15:08Keyword
- 16:26Tokenizer
- 18:29Whitespace
- 20:41Tokens
- 21:05Processing tokens
- 21:19Parse
- 24:52Block
- 27:11Break
- 28:33Code Generation
- 30:18Code Generation Animation
- 31:49Code Generation Explanation
- 35:34Resources
- 37:34Outro
related talks
31mBuilding a Programming Language in Swift
27mSwiftSyntax: for good and evil
21mUnlock the Potential of Swift Code Generation
19mBuild-a-Binary
49mState of Swift Internals: Swift 4 & 5
28mSwiftly Swift manipulation... with Swift
22mImproving Swift Tools with libSyntax
33mMaking Your Own Tools Using SwiftSyntax
