当前位置:网站首页>First set and follow set in vernacular
First set and follow set in vernacular
2022-06-12 14:59:00 【George Sumu】
FIRST Set
It can be understood as the starting symbol of the current non terminal character ( Terminator ) Set of
Solution :
step :
1. if X->a…, The Terminator a Join in FIRST(X) in ;
2. if X->e , The Terminator e Join in FIRST(X) in (e It means an empty set );
3. if X->BCD…E, Will First(B) All the elements ( Except for the empty set ) Join in First(X), And then test First(B), if First(B) There is no empty set in , namely e, Then stop , If it exists, it is directed to B View behind , take First(C) All elements in ( Except for the empty set ) Join in First(X), And then test First(C) If there e… straight In the end , if E All previous nonterminal First The set contains e, ... is detected E when , take First(E) Also joined First(X), if First(E) contains e, Will e Join in First(X).
The first two are easy to understand , The third explanation is : A paragraph of grammar , If the preceding nonterminal symbol cannot deduce an empty set , Then the terminator generated by the following non terminator will never become the first character of grammar , Therefore, it is necessary to consider the case of empty sets .
give an example :
Grammar, for example :
- S→ABc
- A→a|ε
- B→b|ε
First Set method :
All opening symbols or possible symbols that can be derived from non terminating symbols ε, But the beginning symbol is required to be the ending symbol . Such a question A Can be derived a and ε, therefore FIRST(A)={a,ε}; Empathy FIRST(B)={b,ε};S Can be derived aBc, You can also deduce bc, You can also deduce c, therefore FIRST(S)={a,b,c}
FOLLOW Set
about Follow Set , We can understand it as the current candidate ( Right style ) The set of summary symbols that appear after the non terminator of .
Solution :
step :
1. Grammar start symbol S, Set up # On FOLLOW(S) in ;
2. For production :A->aBC, Empty set will be removed e Of First(C) Join in Follow(B) in ;
3. For production :A->aB perhaps A->aBC,( among C Empty strings can be derived ,C=>*e), Will Follow(A) Join in Follow(B) in .
Follow(B) yes B The character set after the end of the string , stay A->aBC Under the situation of ,B Push the character set after the end of the string , That is to say C Push out the set of characters at the beginning of the string , namely First(C) Remove from e Set .
A->aB , that A Push the character set after the end of the string , And B Push the character set after the end of the string , If it is equivalent, you can put Follow(A) Assign a value to Follow(B).
give an example :
Grammar, for example :
- S→ABc
- A→a|ε
- B→b|ε
Follow The solution of set :
The closing symbol or... Immediately following it #. But grammar identifiers contain #, When asking, we should also consider ε. The specific method is to find out all the production formulas containing the symbols you require , See which works . Follow(S)={#}
As required A Of Follow Set Generative formula :S→ABc A→a|ε , But only S→ABc Useful . Follow in A The ending symbol of the next year is FIRST(B)={b,ε}, When FIRST(B) The element of is ε when , Follow in A The symbol after is c, therefore Follow(A)={b,c} Empathy Follow(B)={c}
summary
First
for example :A->aB | CD
This includes the composition First(A) In two cases :
1. Start with Terminator , Of course, put this terminator in A Of First in
2. Start with a non Terminator , The first C Of First Put it in A Of First in , Look again if C Of First If you have time in your spare time D Of First Put it in A Of First in , If D If you're free, go back and so on
skill :First Generally look from bottom to top . If you want to find A Of First, We are looking for A The definition of , namely A The formula on the left , Look at his right and look for .
Follow
Such as S->(L) | aL | LC
look for Follow Three situations of : First in the candidate ( On the right ) The non terminator was found in , Such as L( Note that there is only one definition in this example , But find Follow To see all non terminators on the right )
1. If L To the right of is the Terminator , Then this terminator is added L Of Follow
3. If L To the right of is a non Terminator , So take this non Terminator First Remove the empty space L Of Follow in
3. If L At the end , that ,’->' The symbol on the left Follow Become L Of Follow
4. Another thing to note : The beginning of the symbol Follow To add ‘#’
skill :Follow Generally look from top to bottom . If you want to find L Of Follow, To find the right side of the equation L, Then come to L Of Follow, This is related to First Is different .
References used in this article 1
References used in this article 2
I would like to thank the above two predecessors .
边栏推荐
- ROS 中 boost::bind( ) 的使用
- C 数据类型
- Serialization and deserialization mechanism in terms of games
- NETCORE combined with cap event bus to realize distributed transaction - message (2)
- Selenium advanced
- [writeup]buu SQL course1[entry level]
- Scala下载及IDEA安装Scala插件(保姆级教程超详细)
- 能链智电登陆纳斯达克:贝恩是股东 成中国充电服务第一股
- Open Chinese path file in C language
- 【Instant】1. Equivalent to date class 2 Represents a moment
猜你喜欢

JUnit test suite method sorting (method 2 is not easy to use)

Wild pointer understanding
![[LDA] rough version notes of EM variational reasoning [to be improved](/img/de/4b028e77694297db05a2d6b6589276.png)
[LDA] rough version notes of EM variational reasoning [to be improved
![[wp][入门]攻防世界-game](/img/07/1ea54d14ba3caca25a68786d5be4a6.png)
[wp][入门]攻防世界-game
![[wechat applet] 2 Environmental preparation](/img/8d/7bb68ca7d10751a6e992a53c5eff4a.jpg)
[wechat applet] 2 Environmental preparation

左对齐,右对齐,随机数,goto,比较输出bool

ROS 中 boost::bind( ) 的使用

SQL cross database injection

C string
![[wechat applet] 3 The first wechat applet](/img/40/1571c11363e72f5a1e932586a1f240.jpg)
[wechat applet] 3 The first wechat applet
随机推荐
Module VIII
Industrial end: a new battlefield of 618
程序构造和解释之第一章习题
【LocalDate LocalTime LocalDateTime】1. Using immutability to achieve thread safety 2 Current date, current time, current date time 3 Since the time zone is not considered, you need to add 8 hours to th
3D reconstruction system | L3 incremental motion recovery structure (incremental SFM)
Scala下载及IDEA安装Scala插件(保姆级教程超详细)
【LDA】基础知识笔记——主要是AE、VAE
[system. Currenttimemillis()] current timestamp: the number of milliseconds that have elapsed since the current system time was 0:00:00 on January 1, 1970
Yiwei lithium energy plans to raise 9billion yuan: liujincheng and luojinhong jointly subscribe for 6billion yuan of layout Optical Valley
Serialization and deserialization mechanism in terms of games
Wild pointer understanding
USART (rs232422485), I2C, SPI, can, USB bus
PHPstudy建站提示hosts文件可能不存在或被阻止打开,同步hosts失败怎么解决
The igatewayloadbalancer interface implements routing. Otherwise, it follows Sid routing
掌门教育被强制退市:上市仅一年时间 软银CMC损失惨重
How to add WWW to the domain name
ROS中tf学习笔记
MAT的安装和使用
Qiming cloud sharing | demonstrate the switch through an example of the matter protocol to control the light on and off through the matter protocol
junit测试套件方法整理(方法二不太好用)