2021-03-23

CS143 Lectur...

CS143 Leture01: Overview,Note

The structure of a compiler

  1. Lexical Analysis(词法分析)
  2. Parsing(预处理)
  3. Semantic Analysis(文法分析)
  4. Optimization(优化)
  5. Code Generation(代码生成)

Lexical Analysis

  • Recognize words.

    word is the smallest unit above letters.

  • Lexical Analysis divide a string into “words” or “token”

Parsing

Parsing = Diagramming Sentences

Semantic Analysis

To understand the meaning of sentence, but meaning is too hard to a program.

Compilers perform limited semantic analysis to catch inconsistencies.

Optimization

CS243: Program Analysis and Optimization

Code Generation

A translation to another language, and typically produce assembly code.

Intermediate Representations(中间形式,a.k.a. IR)

Many compilers will perform translations between successive intermediate languages(很多编译器翻译时会使用多个中间形式.)

  • All but first and last are intermediate representations (IR) internal(内部的) to the compiler.

IRs are useful to hide the lower levels feature from higher levels.

  • registers
  • memory layout
  • raw pointers