当前位置:网站首页>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 .
边栏推荐
- Learn JVM garbage collection 02 - a brief introduction to the reference and recycling method area
- Clear neo4j database data
- Get data from the database when using JMeter for database assertion
- [hdu 2096] Xiaoming a+b
- Learning items
- MySQL index (1)
- MySQL log module of InnoDB engine
- How can labels/legends be added for all chart types in chart. js (chartjs.org)?
- MySQL installation, Windows version
- Simply take stock reading notes (1/8)
猜你喜欢

One article tells the latest and complete learning materials of flutter

Storage Basics

Database connection pool & jdbctemplate

Iterator details in list... Interview pits

MySQL index (1)

10 minute fitness method reading notes (3/5)

The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"

Making and using the cutting tool of TTF font library

Distributed cache architecture - cache avalanche & penetration & hit rate
随机推荐
One article tells the latest and complete learning materials of flutter
GPON technical standard analysis I
Redis master-slave configuration and sentinel mode
End to end neural network
GPS數據格式轉換[通俗易懂]
Summary of C language learning problems (VS)
Detailed structure and code of inception V3
激动人心!2022开放原子全球开源峰会报名火热开启!
UNIX socket advanced learning diary -ipv4-ipv6 interoperability
Pytoch uses torchnet Classerrormeter in meter
About cache exceptions: solutions for cache avalanche, breakdown, and penetration
Take you two minutes to quickly master the route and navigation of flutter
Understand kotlin from the perspective of an architect
前几年外包干了四年,秋招感觉人生就这样了..
[HDU 2096] 小明A+B
Get the variable address of structure member in C language
Solution to order timeout unpaid
Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
Introduction to relational model theory
Correct opening method of redis distributed lock
