MIT 6.035 Computer Language Engineering — Spring 2021
Course link: https://github.com/6035/sp21
This repository contains a TypeScript implementation of a compiler built as part of MIT 6.035 (Computer Language Engineering), Spring 2021. The course covers the design and implementation of compilers for higher-level programming languages, including scanning, parsing, semantic analysis, intermediate representation, code generation, and optimization.
The compiler targets the Decaf language and generates x86-64 assembly.
Analyzes issues associated with the implementation of higher-level programming languages. Covers fundamental concepts, functions, and structures of compilers, the interaction of theory and practice, and the use of tools in building software. Includes a multi-person project on compiler design and implementation.
- Prerequisites: 6.004, 6.031
- Level: Undergraduate
- Units: 4-4-4
mit-6.035-sp21/
├── src/ # TypeScript compiler source code
│ ├── main.ts # Compiler entry point
│ ├── scanner/ # Lexical analysis (scanner/tokenizer)
│ ├── parser/ # Syntax analysis (parser)
│ ├── ir/ # Intermediate representation
│ ├── asm/ # x86-64 assembly generation
│ ├── interpreter/ # Interpreter for testing
│ ├── core/ # Core utility functions
│ └── types/ # Type definitions
├── sp21/ # Course materials for Spring 2021
│ ├── phase-1/ # Scanner/parser project spec
│ ├── phase-2/ # Semantic analysis project spec
│ ├── phase-3/ # Code generation project spec
│ ├── phase-4/ # Dataflow analysis project spec
│ ├── phase-5/ # Optimization project spec
│ └── materials/ # Lecture slides, handouts, and problem sets
├── notes/ # Personal study notes and assembly references
├── references/ # Reference materials
└── fa18/ # Additional materials from Fall 2018 offering
The compiler is built incrementally across five phases:
| Phase | Description |
|---|---|
| Phase 1 | Scanner and parser (individual project) |
| Phase 2 | Semantic analysis |
| Phase 3 | Unoptimized x86-64 code generation |
| Phase 4 | Dataflow analysis and optimization |
| Phase 5 | Advanced optimizations (register allocation, loop opts, etc.) |
yarn installyarn compileyarn debug src/main.ts -- <options>yarn testyarn lint- Lexical Analysis: Regular expressions, finite automata, scanning
- Parsing: Top-down (LL) and bottom-up (shift-reduce/LR) parsing
- Semantic Analysis: Type checking, symbol tables, scope resolution
- Intermediate Representation (IR): Three-address code, control flow graphs
- Code Generation: x86-64 assembly, calling conventions, stack frames
- Program Analysis: Dataflow analysis, reaching definitions, liveness
- Optimization: Loop optimizations, constant folding, dead code elimination
- Register Allocation: Graph coloring, linear scan
- Advanced Topics: Instruction scheduling, parallelization
Modern Compiler Implementation in Java (Tiger Book) Andrew W. Appel and Jens Palsberg — Cambridge University Press, 2002
ISC