当前位置:网站首页>Fundamentals of programming language (2)
Fundamentals of programming language (2)
2022-04-23 19:43:00 【flysh05】
3. Basic principles of compiler
The function of the compiler is to translate the source program written in a high-level language into an equivalent target program ( Assembly language Speech or machine language ). The working process of compiler is divided into 6 Stages , As shown in the figure below :
Lexical analysis : Is the first stage of the compilation process paragraph . The task of this stage is from left to right Read character by character into the source program , That is to scan the character stream constituting the source program Then recognize the word according to the word formation rules ( Also known as single A word or symbol ).
Syntax analysis : Is a logical phase of the compilation process . The task of grammar analysis is to combine word sequences into various types on the basis of lexical analysis Grammatical phrases , Such as “ Program ”,“ sentence ”, “ expression ” wait . The parser judges the source Whether the program is structurally correct
Semantic analysis : Is a logical phase of the compilation process . The task of semantic analysis is to analyze the structurally correct source program Conduct a review of a context sensitive nature , Conduct type review . Such as type matching 、 The divisor of division is not 0 etc. . It is also divided into static semantic errors ( It can be found in the compilation stage ) And dynamic semantic errors ( Can only be issued at run time present ).
Intermediate code and object code generation : Intermediate code is generated according to semantic analysis , Need optimized Links , Finally generate executable object code . The purpose of introducing intermediate code is to optimize the code independent of the machine . The commonly used intermediate code has suffix ( Reverse Polish )、 Ternary form ( Three address codes )、 Quaternions and trees . Three questions need to be considered ( One is how to generate shorter object code ; The second is how to make full use of Computing Registers in the machine , Reduce the number of accesses to the storage unit ; The third is how to make full use of computer instructions Characteristics of the system , To improve the quality of object code ).
To master the above three expressions , In fact, it is three kinds of traversal of trees , Generally, the normal expression is middle order traversal Infix expression , Construct a tree based on it , Then according to the requirements of the topic, find the prefix or suffix .
Simple solution : The suffix expression starts from left to right , First put the expression in parentheses , Then add the operators to the brackets of this level in turn .
3. Grammar defines
A formal grammar is an ordered quadruple G=(V,T,S,P), among :
1)V: non-terminal . Not part of language , Not the end result , Can be understood as placeholder .
2)T: Terminator . Is an integral part of language , Is the end result .V⌒T=θ
3)S: Start character . Is the beginning symbol of language .
4)P: Generative formula . The rule of replacing a nonterminal with a Terminator . Form like α->β
Terminator : final result , Other elements cannot be derived .
non-terminal : Can deduce other elements .
Generative formula : That is, the formula of the terminator derived from the non Terminator .
Closure , The concept is as follows , Generally, the closure can be 0 The case of is substituted into the operation :
Regular closure :A+=A1UA2UA3U…UAn U…( That is, the combination of all powers ).
Closure :A*=A0UA+( On the basis of regular closure , add A0={ε}).
for example a={a,aa,aaa,…,ε}, and (ab)*={ab,abab,ababab,.,ε}
4. Grammar type
5. Normal form
For the alphabet ∑, The normal expression on it and the normal set it represents can be recursively defined as follows .
(1) ε It's a normal form , It represents a collection L( ε)={ ε}.
(2) if a yes ∑ Characters on , be a It's a normal form , The normal set it represents is {a}.
(3) If normal r and s Represent normal set respectively L and L(s), be :
①r|s It's normal , Represents a collection L U L(s).
②r·s It's normal , Represents a collection LL(s).
③r’ It's normal , Represents a collection (L(r)).
④ It's normal , Represents a collection L.
6. Finite automaton
Deterministic finite automata and uncertain finite automata : Enter a character , Look yes Whether we can get the only successor , If you can , Is certain , Otherwise, it is uncertain if multiple successors are obtained
7. Grammar analysis method
Top down parsing : Leftmost inference , From left to right . A given grammar G And source program string r. from G The start sign of S set out , By way of anti Use production to replace the non terminator in the sentence pattern ( deduction ), Gradually deduce r.
Recursive descent thought : The principle is to use recursive calls between functions to simulate the top-down construction process of syntax tree , It's a top-down Grammar analysis method .
Bottom up parsing : Rightmost derivation , right to left . Start with the given input string , Keep looking for substrings and grammar G A certain property in Life style P Match the candidates of , And use P Replace the left part of ( reduction ) And , Gradually reduce to the starting symbol S.
Move into conventional thinking : A stack setting , Move the input symbols into the stack one by one , When the top of the stack forms the right part of a production , Just use the left to Instead of , It's called reduction . Obviously , The idea is to deduce the left from the right , Therefore, it is the core idea of bottom-up grammar analysis .
版权声明
本文为[flysh05]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231941311726.html
边栏推荐
- Comment créer un pass BEP - 20 sur la chaîne BNB
- A simple (redisson based) distributed synchronization tool class encapsulation
- 【webrtc】Add x264 encoder for CEF/Chromium
- @MapperScan与@Mapper
- The textarea cursor cannot be controlled by the keyboard due to antd dropdown + modal + textarea
- Application of DCT transform
- 山大网安靶场实验平台项目-个人记录(五)
- Pit encountered using camera x_ When onpause, the camera is not released, resulting in a black screen when it comes back
- Decompile and get the source code of any wechat applet - just read this (latest)
- Kibana reports an error server is not ready yet. Possible causes
猜你喜欢
Openharmony open source developer growth plan, looking for new open source forces that change the world!
[报告] Microsoft :Application of deep learning methods in speech enhancement
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(五)
Unity创建超写实三维场景的一般步骤
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
基于pytorch搭建GoogleNet神经网络用于花类识别
Prefer composition to inheritance
Class loading mechanism
Lottery applet, mother no longer have to worry about who does the dishes (assign tasks), so easy
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(八)
随机推荐
C6748 software simulation and hardware test - with detailed FFT hardware measurement time
MFC obtains local IP (used more in network communication)
Go recursively loops through folders
MySQL syntax collation (3)
Zero cost, zero foundation, build profitable film and television applet
MySQL数据库 - 单表查询(二)
一个简单的(基于redisson的)分布式同步工具类封装
Unity创建超写实三维场景的一般步骤
php参考手册String(7.2千字)
如何在BNB鏈上創建BEP-20通證
MySQL practical skills
深度学习——特征工程小总结
Understanding various team patterns in scrum patterns
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)
山大网安靶场实验平台项目-个人记录(五)
Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)
MySQL数据库 - 单表查询(三)
Executor、ExecutorService、Executors、ThreadPoolExecutor、Future、Runnable、Callable
Speex维纳滤波与超几何分布的改写
Distinction between pointer array and array pointer