## A Short Course in CompilersThese lectures are designed for a 10-session class. It is assumed that the students know MATLAB and elementary mathematics. The planned lecture format is an hour of lecture followed by an hour of in-class lab work. The details follow. If a project is going to be attempted, it should be done simultaneously. ## Lecture 1 (overheads)- Hello, Course Objectives, Schedule (10 min)
- A very simple compiler (5 min)
- Getting a personal copy of xcom. (10 min)
- Learning X (25 min)
## Lab 1- Students as QE (5 min)
- Read the X Reference Manual (10 min)
- Practice Writing X and
Running
**xcom**(25 min) - Using xcom flags for dumps and traces (10 min)
## Lecture 2 (overheads)- OO Programming Model (5 min)
- Structure of xcom (10 min)
- Grammars for programming languages (35 min)
## Lab 2- Changing the xcom Cfg object (10 min)
- Look at the Cfg tables (20 min)
- Look at intermediate Cfg output (20 min)
## Lecture 3 (overheads)- Changing the xcom Lexer (10 min)
- Lexing a programming language (10 min)
- Regular Expressions (10 min)
- Regular Expression Grammars (20 min)
## Lab 3-
Try many examples like
`>> xcom -lexDump x:=1` - Add a unit test to testLexer.m (30 min)
- Add abs to X (in X.cfg) (20 min)
- Challenge: write a faster lexer. Hint: use MATLAB profiler.
## Lecture 4 (overheads)## Lab 4-
Try many examples like
`>> xcom -parseTrace x:=1`
`>> xcom -parseTrace -bottomUp x:=1` - Add a unit test to testParser.m (20 min)
- Add abs to X (in Parser.m) (30 min)
- Challenge: compare speeds of bottom up vs. top down parsing
## Lecture 5 (overheads)- Syntax Trees (20 min)
- Changing the xcom symbol table (10 min)
- Symbol Tables (20 min)
## Lab 5-
Try many examples like
`>> xcom -treeTrace x:=1`
`>> xcom -treeTrace -noAST x:=1` -
Try many examples like
`>> xcom -symTrace x:=1` - Add a unit test to testTree.m (5 min)
- Add a unit test to testSymbols.m (15 min)
- Adding abs to X (in Symbols.m) (30 min)
- Challenge: Rewrite Symbols.m so that it uses hash lookup.
## Lecture 6 (overheads)- Machine Language (20 min)
- Runtime (20 min)
- Changing Runtime (5 min)
`>> xcom -interactive x/pi.x`(5 min)- Changing the Intel emulator (5 min)
## Lab 6-
Try many examples like
`>> xcom -asmTrace x:=1`
`>> xcom -asmTrace -exeTrace x:=1` - Add abs to X (in AsmX86.m) (15 min)
- Add a unit test to testAsmX86.m (20 min)
- Add a unit test to testEmulate.m (20 min)
- Challenge: Implement AsmA64.m
## Lecture 7 (overheads)- Emitting CPU Instructions (40 min)
- Changing the xcom code emitter (10 min)
## Lab 7-
Try many examples like
`>> xcom -asmTrace -emitTrace x:=1` - Add a unit test to testEmitX86.m (20 min)
- Add abs to X (in EmitX86.m) (30 min)
- Challenge: Implement EmitA64.m (Intel 64-bit)
## Lecture 8 (overheads)- Synthesis of Sequential Semantics (30 min)
- Changing the xcom generator (10 min)
- Summary: the Big Picture (10 min)
## Lab 8-
Try many examples like
`>> xcom -asmTrace -emitTrace -genTrace x:=1` - Add a unit test to testGenerator.m (20 min)
- Add abs to X (in Generator.m) (30 min)
## Lecture 9 (overheads)- Tradeoffs between interpreters, JITs and production compilers (20 min)
- Conventional Optimization Strategies (30 min)
## Lab 9- Implement Constant Folding for X as a peephole
## Lecture 10- Finite Automata (20 min)
- LR Parsing (30 min)
## Final Exam |