<!doctype html>
Compiler theory
Compiler theory Overview
1, the compiler concepts:
- From the high-level language -> Process object code (assembly language or machine code)
2, the structure of the compiler:
-
Analysis portion / distal end (front end) -> associated with the source language
- Lexical analysis lexical unit stream >>
- >> parsing parse tree parse tree
- Semantic analysis syntax tree >>
- Intermediate code generating intermediate representation >>
- Machine independent code optimization
-
Integrated part / back-end (back end) -> associated with the target language
- Target code generation target machine language >>
- Machine-dependent code optimization target machine language >>
3, lexical analysis
-
main mission:
-
Scan source -> the identification of each word -> determining the type of word -> the recognized word into the machine represented (i.e.: means lexical token)
-
token: <Do Species Code: attribute value>
-
Type the word Other species Species do not code Keyword if, etc. The term one yards Identifier Variables, arrays, procedure ...... Multi-word one yards constant Multi-word one yards Operators Arithmetic operators: + -
relational operators:> <==
Logical operators: & ||!The term one yard
a type one yardsDelimiter ;{}()=…… The term one yards
-
-
4, parsing
- Concept: The parser Parser token from the lexical analyzer output, the identification of various types of phrases constructed parse tree parse tree
5, semantic analysis
-
main mission:
-
Attribute-information collection identifier - >>> stored in the symbol table Symbol Table in
- 种属 kind
- Type type
- Storage location, length
- value
- Scope
- Information parameters and return values
-
Semantic checks:
- Or process variables without declaration will use
- ...... repeated statement
- Arithmetic component type mismatch (error or casts)
-
6、中间代码生成
-
中间表示形式:
-
三地址码Three-address Code
-
三地址指令的表示形式:
-
三元式
-
间接三元式
-
四元式
-
-
语法结构树/语法树Syntax Tree
-
7、目标代码生成:
-
中间表示形式作为输入,映射到目标语言
- 重要作用:为程序变量使用分配寄存器
8、代码优化
- 等价程序变换,使其运行快,占内存少。