当前位置:网站首页>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 .
边栏推荐
- The relationship between the size change of characteristic graph and various parameters before and after DL convolution operation
- Volatile instruction rearrangement and why instruction rearrangement is prohibited
- Kotlin函数
- struct MySQL
- JDBC -- extract JDBC tool classes
- 10 minute fitness method reading notes (2/5)
- Resnet+attention project complete code learning
- Redis highly available sentinel cluster
- Average lookup length when hash table lookup fails
- Principle of universal gbase high availability synchronization tool in Nanjing University
猜你喜欢

Ecplise development environment configuration and simple web project construction

Interviewer: is acid fully guaranteed for redis transactions?

Pytoch uses torchnet Classerrormeter in meter

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

JDBC -- use JDBC connection to operate MySQL database

Master-slave mode of redis cluster

前几年外包干了四年,秋招感觉人生就这样了..

The evolution of mobile cross platform technology

Redis highly available sentinel cluster

Get data from the database when using JMeter for database assertion
随机推荐
SENT协议译码的深入探讨
Average lookup length when hash table lookup fails
JDBC exercise - query data encapsulated into object return & simple login demo
Learn JVM garbage collection 05 - root node enumeration, security points, and security zones (hotspot)
Full text search of MySQL
Ecplise development environment configuration and simple web project construction
About LDA model
C language structure is initialized as a function parameter
Redis highly available sentinel mechanism
ZABBIX agent2 monitors mongodb templates and configuration operations
Sqoop import and export operation
Annotation problem and hidden Markov model
Docker configures redis and redis clusters
Experimental design - using stack to realize calculator
How to design an interface?
Cypher syntax of neo4j graph database
VoneDAO破解组织发展效能难题
[HDU 2096] 小明A+B
Distributed solution - Comprehensive decryption of distributed task scheduling platform -xxljob
Learn the memory management of JVM 03 - Method area and meta space of JVM
