An upper-level course
for CS majors on formal languages theory and compilers.

Topics (subject to revision): regular expressions; finite automata; context-free grammars; predictive parsing; LR parsing; abstract syntax; type systems and type-checking; stack layout and activation records; intermediate representations; control-flow graphs; static-single assignment (SSA) form; dataflow/liveness analysis; register allocation; garbage collection/runtimes; the LLVM compiler infrastructure. Over the course of the semester, students will implement a full functioning compiler for a small imperative programming language, targeting LLVM. The course involves a significant amount of programming.

Topics (subject to revision): regular expressions; finite automata; context-free grammars; predictive parsing; LR parsing; abstract syntax; type systems and type-checking; stack layout and activation records; intermediate representations; control-flow graphs; static-single assignment (SSA) form; dataflow/liveness analysis; register allocation; garbage collection/runtimes; the LLVM compiler infrastructure. Over the course of the semester, students will implement a full functioning compiler for a small imperative programming language, targeting LLVM. The course involves a significant amount of programming.

**Lecture**: Tuesday, Thursday 1:30–2:50 p.m.,
ARC 221

**Professor**: Gordon Stewart (gstewart@ohio.edu)

**TA**: Sam Merten (sm137907@ohio.edu)

**Office Hours**: Monday, Thursday 11:00
a.m.–12:00 p.m. (Stocker 355), or by appointment

**Lab Hours**: the Mondays before assignments are due, 3:15—4:30 p.m., Stocker 307A

**Piazza**: Course Page, Signup

- Been exposed to the fundamentals of formal languages and compilers theory—as outlined in the topics listed above—and will have applied many of these fundamental ideas to build their own working compiler
- Learned the basics of, and gained some facility with, the functional programming language OCaml
- Had some fun along the way!

**Modern Compiler Implementation in ML.**Andrew W. Appel. Available for free online for Ohio University students through the university library.-
**Algorithms, Languages, Automata & Compilers: A Practical Approach.**Maxim Mozgovoy. The relevant chapters of this book will be available (one at a time) through Blackboard.

Periodically I may assign additional supplementary (optional but recommended) readings from resources such as

- Real World OCaml (abbreviated RWO in the syllabus below)
- the OCaml language manual
- the OCaml Batteries Included documentation
- the LLVM reference manual
- Types and Programming Languages (TAPL)

In addition to biweekly homework assignments, there will be a midterm exam (Week 7, approximately 15% of your grade) and a final (Week 15, approximately 30%). The biweekly homeworks are worth approximately 40%. We'll have weekly quizzes every Tuesday (with probability 1/3, 5%). Participation and attendance at lecture are worth 10%.

Blackboard will be used only to report grades and to post lecture notes. Up-to-date information on all other aspects of the course (assignment due dates, etc.) will be posted either on this website or on the Piazza page or both.

Introduction to compilers and functional programming in OCaml.

Reading: Appel 1; OCaml Manual: Core Language

Homework: A0: Intro. to OCaml.
Due Tuesday, 1/19

More functional programming: polymorphism, higher-order
functions, algebraic datatypes and pattern-matching.

Supplemental Reading: RWO I.1, OCaml Pervasives Library (reference)

Homework: A1: Functional
Programming in OCaml.
Due Tuesday, 1/26

Regular expressions, DFAs and NFAs

Reading: Appel 2; Mozgovoy 1 (available in Blackboard)

Homework: A2: Regular Expressions Re-Examined.
Due Tuesday, 2/9

Parsing cont'd, Parser generators, Menhir

Reading: Appel Sections 3.3-3.5

Homework: A3: Lexing and Parsing with ocamllex and Menhir.
Due Tuesday, 2/23

Abstract syntax trees, type systems

Reading: Appel 4, TAPL 8 (OU Library eBook)

Type systems continued.

Reading: Appel 5

Stack layout and activation records,
control-flow graphs, dominator computation, loop optimizations

Reading: Appel 6.1, Appel 7.1, Appel 18.1

Use-def, dataflow/liveness analysis,
Static Single Assignment (SSA) form,
interference graphs

Reading: Appel 10.1, Appel 19 (up to but not including 19.1)

Homework : A5: SSA.
Due Tuesday, 4/5

Intro. to runtimes, garbage collection;
mark-and-sweep collection, copying collection, reference counting,
generational collection

Reading: Appel 13, through 13.4

Homework : A6: LLVM.
Due Tuesday, 4/19

Garbage collection contd.,
runtime representations of objects, of functions
(closures), of polymorphic variables

Reading: Appel 14.1-14.3 (objects), Appel 16.3 (polymorphism)

Register allocation

Reading: Appel 11 through 11.3

- Up to 24 hours late: no deduction, for a max 2 late homeworks per student across the entire semester
- Homeworks later than 24 hours, or from students who have already turned in 2 late homeworks, will receive 0 points.

You **may** discuss the homework with other students in
the class, but only after you've attempted the problems on your own
first. If you do discuss the homework problems with others, write the
names of the students you spoke with, along with a brief summary of
what you discussed, in a README comment at the top of each
submission. Example:

```
(*
README Gordon Stewart, Assn #1
```

I worked with X and Y. We swapped tips regarding the use of pattern-matching
in OCaml. *)

However, **under no circumstances** are you permitted
to share or directly copy code or other written homework material,
except with course instructors. The code and proofs you turn in must
be your own. Remember: homework is there to give *you* practice in
the new ideas and techniques covered by the course; it does you no
good if you don't engage!

In general, students in EECS courses such as this one should adhere to the Russ College of Engineering and Technology Honor Code, and to the OU Student Code of Conduct.