# SJTU Compiler Principles

## Course Introduction

- Offered by: Shanghai Jiao Tong University
- Prerequisites: Basic Computer Systems, Data Structures and Algorithms, Programming Fundamentals
- Programming Language: C++
- Course Difficulty: 🌟🌟🌟🌟
- Class Hour: 150 hours

The Compiler Principles course at Shanghai Jiao Tong University aims to implement a compiler for the Tiger language. In this course, you will learn about lexical analysis, grammar analysis, semantic analysis, escape analysis, activation records (stack frames), LLVM IR, liveness analysis, register allocation, garbage collection, object-oriented programming, functional programming, and many other topics. Similar to the Compiler Principles course at Peking University, this course offers you a great deal of freedom. The test programs will only check the correctness of the assembly code you output and will not impose any restrictions on the specific design of your compiler. You will need to build your own compiler step by step from scratch.

In this course, you will learn how to use frameworks such as `flexc++`, `Bisonc++`, and `LLVM`, and enhance your debugging skills through practice. The theoretical part of the course is taught by teachers from the IPADS Laboratory at Shanghai Jiao Tong University.

## Course Resources

- Course Website: <https://ipads.se.sjtu.edu.cn/courses/compilers/index.shtml>
- Slides: See the course website
- Framework Code: <https://ipads.se.sjtu.edu.cn:2020/compilers-2024/compilers-2024> (If unable to access, you can use other similar and maintained repositories, such as <https://gitee.com/east-china-normal-university_ttb_cs/tiger-compiler-25sp>)
- Course Textbook: "Tiger Book" (Modern Compiler Implementation in C) <https://ipads.se.sjtu.edu.cn/courses/compilers/textbook/TigerBook-English.pdf>
- 2 Quizzes + 6 Labs
    - Lab 1: Straight-line Program Interpreter
    - Lab 2: Lexical Analysis
    - Lab 3: Parsing
    - Lab 4: Type Checking
    - Lab 5
        - Part 1: Escape Analysis and Translation
        - Part 2: Tiger Compiler without Register Allocation
    - Lab 6: Register Allocation