※递归下降法:

简而言之,就是比如文法是

S→T,T→FM, F→+M,M→a


用伪代码表示这个文法

则首先要写 procedure S

BEGIN

T;

END

然后写 procedure T

BEGIN

F;

M;

END

Procedure F

BEGIN

+M;

END

Procedure M

BEGIN

匹配a

END

这样的过程是递归下降的过程。递归下降方法仅表示一种思路,没有特别的

※LL(1)预测分析法:

第一个L表示从左到右扫描输入串

第二个L表示最左推导

1表示分析时每步只需向前查看一个符号

How to identify whether a grammar is LL(1), LR(0) or SLR(1)?

If you have no FIRST/FIRST conflicts and no FIRST/FOLLOW conflicts, your grammar is LL(1).

An example of a FIRST/FIRST conflict:

S -> Xb | Yc
X -> a
Y -> a

By seeing only the first input symbol a, you cannot know whether to apply the production S -> Xb or S -> Yc, because a is in the FIRST set of both X and Y.

An example of a FIRST/FOLLOW conflict:

S -> AB
A -> fe | epsilon
B -> fg

By seeing only the first input symbol f, you cannot decide whether to apply the production A -> fe or A -> epsilon, because f is in both the FIRST set of A and the FOLLOW set of A (A can be parsed as epsilon and B as f).

Notice that if you have no epsilon-productions you cannot have a FIRST/FOLLOW conflict.

2.

X → Yz | a

Y → bZ | ε

Z → ε

To check if a grammar is LL(1), one option is to construct the LL(1) parsing table and check for any conflicts. These conflicts can be

  • FIRST/FIRST conflicts, where two different productions would have to be predicted for a nonterminal/terminal pair.

  • FIRST/FOLLOW conflicts, where two different productions are predicted, one representing that some production should be taken and expands out to a nonzero number of symbols, and one representing that a production should be used indicating that some nonterminal should be ultimately expanded out to the empty string.

  • FOLLOW/FOLLOW conflicts, where two productions indicating that a nonterminal should ultimately be expanded to the empty string conflict with one another.

Let's try this on your grammar by building the FIRST and FOLLOW sets for each of the nonterminals. Here, we get that

FIRST(X) = {a, b, z}
FIRST(Y) = {b, epsilon}
FIRST(Z) = {epsilon}

We also have that the FOLLOW sets are

FOLLOW(X) = {$}
FOLLOW(Y) = {z}
FOLLOW(Z) = {z}

From this, we can build the following LL(1) parsing table:

    a    b    z   $
X   a    Yz   Yz
Y        bZ   eps
Z             eps

Since we can build this parsing table with no conflicts, the grammar is LL(1).

To check if a grammar is LR(0) or SLR(1), we begin by building up all of the LR(0) configurating sets for the grammar. In this case, assuming that X is your start symbol, we get the following:

(1)
X' -> .X
X -> .Yz
X -> .a
Y -> .
Y -> .bZ(2)
X' -> X.(3)
X -> Y.z(4)
X -> Yz.(5)
X -> a.(6)
Y -> b.Z
Z -> .(7)
Y -> bZ.

From this, we can see that the grammar is not LR(0) because there are shift/reduce conflicts in states (1) and (6). Specifically, because we have the reduce items Z → . and Y → ., we can't tell whether to reduce the empty string to these symbols or to shift some other symbol. More generally, no grammar with ε-productions is LR(0).

However, this grammar might be SLR(1). To see this, we augment each reduction with the lookahead set for the particular nonterminals. This gives back this set of SLR(1) configurating sets:

(1)
X' -> .X
X -> .Yz [$]
X -> .a  [$]
Y -> .   [z]
Y -> .bZ [z](2)
X' -> X.(3)
X -> Y.z [$](4)
X -> Yz. [$](5)
X -> a.  [$](6)
Y -> b.Z [z]
Z -> .   [z](7)
Y -> bZ. [z]

Now, we don't have any more shift-reduce conflicts. The conflict in state (1) has been eliminated because we only reduce when the lookahead is z, which doesn't conflict with any of the other items. Similarly, the conflict in (6) is gone for the same reason.

转载于:https://blog.51cto.com/11259454/1769146

Formal Languages and Compilers-LL(1),FIRST and FOLLOW相关推荐

  1. Formal Languages and Compilers 笔记教程 第一章 有限自动机与正则语言 (Finite Automata and Regular Languages)

    Formal Languages and Compilers (形式语言和编译器) 的 自学笔记兼学习教程. 笔记作者介绍:大爽歌, b站小UP主 ,编程1对1辅导老师. 1 Finite Autom ...

  2. [转]CS的顶级会议和期刊

    原文地址:   http://blog.csdn.net/noter/archive/2009/08/05/4414168.aspx CS的顶级会议和期刊 SCI或SCIE收录的本学科刊物清单请登陆 ...

  3. 计算机领域的顶级会议和期刊

    SCI或SCIE收录的本学科刊物清单请登陆 http://www.isinet.com/cgi-bin/jrnlst/jloptions.cgi?PC=K 和http://www.isinet.com ...

  4. 康涅狄格大学计算机科学排名,康涅狄格大学的计算机科学排名,不可忽视的重点信息...

    原标题:康涅狄格大学的计算机科学排名,不可忽视的重点信息 康涅狄格大学(University of Connecticut,简称UCONN),是一间美国知名.全球顶尖的公立研究型大学.这间学校设立于1 ...

  5. 个人网页、博客、课程--不断更新

    论文和相关代码 :https://paperswithcode.com/ Caiming Xiong http://www.stat.ucla.edu/~caiming/ 论文,代码,博客 肖小粤的啵 ...

  6. 计算机方面的顶级会议

    原文地址:http://blog.csdn.net/ustcxjt/article/details/7075534 方便自己查看 CORE Computer Science Conference Ra ...

  7. 最全的计算机会议排名

    收集了一些计算计领域的会议,为方面后面的研究生涯!加油自己!加油 Ecnu and Fzu 先后经历了在这两个学校的学习生涯,思念Fzu的一切,珍惜Ecnu的现在 CORE Computer Scie ...

  8. 中了一篇ccf的b类会议sdm'15,要去温哥华参会。很高兴啊!!!!

    中了一篇ccf的b类会议sdm'15,要去温哥华参会.很高兴啊!!!! 序号     会议名称      会议介绍      代表领域 1 ACM SIGCOMM: ACM Conf on Commu ...

  9. 计算机相关会议排名(二)

    计算机相关会议排名(一) 计算机相关会议排名(二) 序号 会议名称 会议介绍 代表领域 1 ACM SIGCOMM: ACM Conf on Communication Architectures, ...

最新文章

  1. 使用vi/vim编辑时按ctrl-s后客户端假死解决方法
  2. github上的linux项目,克隆GitHub上项目的非Master分支
  3. 阿里P8架构师谈:分布式、集群、负载均衡、分布式数据一致性的区别与关联
  4. 搜狐畅游笔试题:1. 美丽的项链(动态规划) 2.多线程并发交替输出
  5. ulimit限制 新系统_graylog日志分析系统上手教程
  6. python自动化框架学习-pyautogui
  7. 剑指offer——面试题21:包含min函数的栈
  8. ubuntu 17.10 如何设置合盖不关机
  9. 金蝶云星空根据采购价目表写入自定义采购入库单是否价目表字段
  10. 解决无法卸载vmware bridge protocol功能,错误0×8007007E
  11. 【工控老马】OPC通讯协议解析-OPC七问
  12. 程序员应知必会的思维模型之 13 侯世达定律 (Hofstadter‘s Law)
  13. 基于特征点检测的人脸融合
  14. Kindeditor图片粘贴上传(chrome)
  15. IterNet: Retinal Image Segmentation Utilizing Structural Redundancy in Vessel Networks
  16. Unity Shader unity文档学习笔记(十七):径向模糊 实现类似冲锋时的速度感
  17. A CHAIN OF SHORT STORIES ABOUT THEIR DISTANCE(秒速五厘米)
  18. 资金申报项目管理系统 - 系统介绍篇
  19. plt.rcParams[‘axes.unicode_minus‘] = False #解决保存图像是负号‘ 这句话是什么意思?
  20. coreseek 安装

热门文章

  1. 2021-04-17 安装Ubuntu18.0.4 的深度学习训练服务器
  2. 小森生活一直服务器维护,《小森生活》怎么处理断线黑屏的问题 连接不上服务器解决办法...
  3. java jvm崩溃_IObjects java 代码导致jvm崩溃了
  4. android 手机图库获取sd卡图片,关于Android读取不同位置(drawable,asset,SDCard)的图片资源的总结...
  5. JavaScript编程知识
  6. Matlab 利用M文件产生模糊控制器
  7. 洲际的merlin怎么用_天问一号是怎么拍摄地月合影的?
  8. Spring学习6之自动装配Bean02
  9. linux tomcat 清空war,Linux下tomcat部署war包
  10. java字符串格式化:String.format()方法的使用