当前位置:网站首页>Compilation principle reading notes (1/12)
Compilation principle reading notes (1/12)
2022-07-05 12:43:00 【NLP journey】
The first 1 Chapter Introduction
1.1 What is a compiler
Compiler is the translator of programming language , Translate the code written in high-level programming language into machine code that the machine can execute .
1.2 The compilation process and the structure of the compiler
1.2.1 Compilation process overview
The typical compilation process is divided into lexical analysis 、 Syntax analysis 、 Semantic analysis 、 Intermediate code generation 、 Code optimization and object code generation 6 Stages .
- Lexical analysis
Read the source program from left to right , Recognize the words one by one , Such as identifier 、 Reserved words 、 operator 、 Boundary symbol, etc .- Syntax analysis
On the basis of lexical analysis, the word sequence is decomposed into various grammatical phrases , Like the procedure 、 sentence 、 Expression etc. . You can generate a syntax tree in the form of a table .- Semantic analysis
Semantic analysis is to check whether the source program has semantic errors , Collect type information for the code generation phase .- Intermediate code generation
Intermediate code is a simple structure 、 A well-defined system of notation , There are two important design principles : Easy to generate and translate into object code . Many translation programs use an approximation “ Three address instructions ” Of “ Quaternion ” In the middle of the code , In the form of ( Operator , Operands 1, Operands 2, result ).- Code optimization
Change and transform the intermediate code , The purpose is to make the generated object code more efficient . Such as the deletion of common subexpressions 、 The intensity is weakened 、 Cycle optimization, etc .- Target code generation
Transform the intermediate code into absolute instructions or relocatable instruction code or assembly instruction code on a specific machine . This stage is related to hardware system structure and instruction meaning .
The division of the above stages is a typical logical division , Not all of them are needed in the actual program .
1.2.2 The structure of the compiler
In addition to the above six components of the compiler , There are also forms management and error handling procedures , These two procedures are similar to the above 6 All stages are related .
The table processing program is equivalent to a small database , Store all kinds of data in the whole compiler processing process of the program .
1.2.3 Combination of compilation stages
The compilation process can be divided into front-end and back-end , The work of the front end mainly depends on the source language and has nothing to do with the target machine . The back end refers to the work that depends on the target machine and generally does not depend on the source language .
It is similar to the separation of front end and back end in software development , So the same front end , Equipped with multiple backend , You can generate multiple machine languages for one language .
1.3 Interpreter and some software tools
1.3.1 Interpretation procedure
The interpreter does not need to translate the source program into object code before running . Its working mode is to acquire one by one 、 Analyze and execute source program statements , There will be results immediately after the implementation , Suitable for interactive working .
python It's interpretive language , and java、C All compiled languages .
The interpretation of the program is very slow , Sometimes the interpretation of a high-level language source program is slower than running an equivalent machine code program 100 times . When running speed is very important , It cannot be explained . in addition , The space cost of interpreting language is also great .
The advantage of interpretation language is that the program written is easy to debug .
1.3.2 Software tools for processing source programs
Structured editor of language
Debugging tools for language programs
Program formatter
Language program testing tools
Program understanding tools
Conversion tools between high-level languages
These tools are found in many integrated development environments .
1.4 PL/0 Language compiler system
PL/0 The language compilation system will PL/0 The source program language is transformed into class P-code Target language . The programming language of this compiler given in this book is C Language .
Yes PL/0 And the class P-code I don't know much about the language . Baidu said PL/0 yes pascal A subset of .
1.4.1 PL/0 Language compilation system composition
PL/0 The language compilation system consists of two parts: compiler and interpreter , Known as PL/0 Compilers and classes P-code Interpretation procedure .PL/0 Language program is PL/0 The compiler converts to an equivalent class P-code Program , When the compiler ends normally ,PL/0 The language compilation system will call the interpreter , Explain and execute the generated target program .
PL/0 The compiler of is not directly programming machine code , Instead, it is compiled into a class P-code Code , This class P-code The code needs to be interpreted by the interpreter before it can be executed .
1.4.2 PL/0 Language
PL/0 What's important about language Pascal A subset of .
In practice , The syntax description of program languages often adopts an extended barks paradigm (EBNF) To describe .
ENBF It describes program syntax , It is also the rule that the language constructor follows .
1.4.3 class P-code Language
class P-code Languages can be regarded as classes P-code Assembly language of virtual machine .
class P-code Virtual machine is a simple machine with pure Trestle Structure , There is a stack memory , Yes 4 Control registers .
class P-code Data storage and arithmetic and logic operations during program operation are carried out at the top of the stack . class P-code The instruction format of the virtual machine is as follows :
F L A
F Represents the opcode of an instruction ;L: The function represents the hierarchical difference between the reference layer and the declaration layer , If it doesn't work, set it to 0; A: Different instructions have different meanings .
class P-code Similar to assembly language . Operate directly on the register .
1.4.4 PL/0 compiler
PL/0 The compiler adopts the compilation process of single pass scanning , By lexical analysis program 、 Parser and code generator 3 An independent process .PL/0 The compiler takes the semantic analysis program as the core , When the grammar analysis needs to read words, it calls the lexical analysis program , When grammatical and semantic analysis correctly generates the target code of the corresponding language component , Just call the code generator .
1.4.5 PL/0 Driver code of language compilation system
The so-called driver code , Is the main function of the program , Connect the various parts of the compiler in series in the main function .
边栏推荐
- NLP engineer learning summary and index
- Take you hand in hand to develop a service monitoring component
- 激动人心!2022开放原子全球开源峰会报名火热开启!
- Get data from the database when using JMeter for database assertion
- Hexadecimal conversion summary
- Learn JVM garbage collection 05 - root node enumeration, security points, and security zones (hotspot)
- Seven polymorphisms
- 10 minute fitness method reading notes (3/5)
- IPv6与IPv4的区别 网信办等三部推进IPv6规模部署
- Leetcode-1. Sum of two numbers (Application of hash table)
猜你喜欢

Resnet+attention project complete code learning

Ecplise development environment configuration and simple web project construction

Implementing Yang Hui triangle with cyclic queue C language

The evolution of mobile cross platform technology

OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首

MySQL transaction

从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks

Database connection pool & jdbctemplate

Flutter2 heavy release supports web and desktop applications

VoneDAO破解组织发展效能难题
随机推荐
Pytoch implements tf Functions of the gather() function
只是巧合?苹果 iOS16 的神秘技术竟然与中国企业 5 年前产品一致!
Learn JVM garbage collection 02 - a brief introduction to the reference and recycling method area
Why learn harmonyos and how to get started quickly?
Distributed solution - distributed lock solution - redis based distributed lock implementation
10 minute fitness method reading notes (3/5)
PXE启动配置及原理
Detailed steps for upgrading window mysql5.5 to 5.7.36
信息服务器怎么恢复,服务器数据恢复怎么弄[通俗易懂]
One article tells the latest and complete learning materials of flutter
Resnet+attention project complete code learning
ZABBIX monitors mongodb templates and configuration operations
ZABBIX 5.0 - LNMP environment compilation and installation
10 minute fitness method reading notes (2/5)
激动人心!2022开放原子全球开源峰会报名火热开启!
Sqoop import and export operation
Clear neo4j database data
MySQL storage engine
Take you hand in hand to develop a service monitoring component
Database connection pool & jdbctemplate
