当前位置:网站首页>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
边栏推荐
- Prefer composition to inheritance
- Kubernetes introduction to mastery - ktconnect (full name: kubernetes toolkit connect) is a small tool based on kubernetes environment to improve the efficiency of local test joint debugging.
- MFC obtains local IP (used more in network communication)
- Distinction between pointer array and array pointer
- Unity创建超写实三维场景的一般步骤
- Core concepts of rest
- VeraCrypt文件硬盘加密使用教程
- Grafana 分享带可变参数的链接
- 如何在BNB鏈上創建BEP-20通證
- [H264] hevc H264 parsing and frame rate setting of the old version of libvlc
猜你喜欢
Zero cost, zero foundation, build profitable film and television applet
antd dropdown + modal + textarea导致的textarea光标不可被键盘控制问题
MySQL syntax collation (2)
An idea of rendering pipeline based on FBO
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (VII)
指针数组与数组指针的区分
Pdf reference learning notes
Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)
[报告] Microsoft :Application of deep learning methods in speech enhancement
MFCC: Mel频率倒谱系数计算感知频率和实际频率转换
随机推荐
一个简单的(基于redisson的)分布式同步工具类封装
The difference between underline and dot of golang import package
Easy mock local deployment (you need to experience three times in a crowded time. Li Zao will do the same as me. Love is like a festival mock)
Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
Use test of FFT and IFFT library functions of TI DSP
Class loading process of JVM
Electron入门教程4 —— 切换应用的主题
山大网安靶场实验平台项目—个人记录(四)
Main differences between go and PHP
Machine learning catalog
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
@Mapperscan and @ mapper
【webrtc】Add x264 encoder for CEF/Chromium
Speex Wiener filter and rewriting of hypergeometric distribution
Translation of audio signal processing and coding: Preface
FFT物理意义: 1024点FFT就是1024个实数,实际进入fft的输入是1024个复数(虚部为0),输出也是1024个复数,有效的数据是前512个复数
Application of DCT transform
Strange problems in FrameLayout view hierarchy
Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
对普通bean进行Autowired字段注入