tags: Compiler Design
Lec1: Overview
Two Parts of a Compiler
1. Analysis(分析) part
Front end of the compilerDivide the source program(High-level language)Generate an Intermediate Representation(IR,中间语言)2. Synthesis(合成) part
Back end of the compilerGenerate the desire target program6 Phases of the Compiler
Intermediate Code Generation In Compiler Design Notes
Lexical analysis(字典、辞彙分析)
Syntax analysis(语法、句法分析)
Semantic analysis(语意分析)
Intermediate code generation(4,5阶段间IR产生)
Code optimization(最佳化)
Code generation(产生target language)
1st Phase: Lexical Analysis(辞彙分析),Scanning
同义词: analysis/ scanning/ lexing/ tokenization(把string 切为 tokens)定义: Look words up in the dictionary. 需要检查有无存在于字典(Dictionary)内


由範例可知,Lexical主旨在"Tokenize",我们可以将position的公式对照Symbol Table(符号表)切分为对应<id,1> <=> <id,2> <+> <id,3> <*> <60>,其中id为identifier(辨认字)的缩写
2nd Phase: Syntax analysis(语法分析),Parsing
同义词: Parsing(剖析)定义: Check if youre words do compose(组成) a sentence, find out the grammatically incorrect(文法错误)


我们以能建出"Syntax Tree",作为符合文法的
3rd Phase: Semantic analysis(语意分析)
定义: To understand the "meaning" of a sentence包含: Type checking,将错误的型别(Ex: int->float)作"Type Conversion"4th Phase: Intermediate Code Generation
A low-level IR will has following characters:Easy to product from syntax treeEasy to translate into the target assembly codeuse three-adress code