Introduction

Five Phases

Make analogy between compiler and human language translator in five main phases:

  1. Recognize words Lexical analysis divides program text into “words” or “tokens”
  2. Understand sentence structure Parsing, diagram sentences into tree
  3. Understand sentence meaning Semantic analysis, compilers perform limited analysis to catch inconsistencies
  4. No strong counterpart in optimization Optimization, modify programs so they can run faster, use less memory, power, network, database access…
  5. Translate into another language Code generate, produces assembly code(usually)

Course Project: COOL compiler

COOL(Classroom Object Oriented Language) is designed to be implementable in a short time with a taste of modern programming language features including abstraction, static typing, inheritance, memory management… The strict language syntax definition can be found in Cool Manual.

Supplementary Project: min-LOOP lang compiler

The loop macro in common lisp is one of the most flexible and naturally understandable min-language that I have seen so far. In lisp, the philosophy is to let the language and program evolve together. The loop macro demonstrate this philosophy very well. In this project, we try to design and build a minor LOOP language compiler to compile loop S-expressions into common lisp into general common lisp code, i.e. trying to figure out how loop macro works. The loop macro syntax can be found on common lisp HyperSpec.