Compiler Design, Lec1: Overview

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 program

6 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)内in Analogy to EnglishSyntax Analysis ExampleExamlpe

由範例可知,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(文法错误)in Analogy to EnglishSyntax Analysis ExampleExample

我们以能建出"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

5th Phase: Code Optimization

优化:用更短的程式码跑得更快Often takes the most of the compilation time

6th Phase: Code Generation

定义:转为对应target language

Whole Picture,(6 Phases整体关联图)


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章