编译原理课件PPT 第4章.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
编译原理课件PPT 第4章

CHAPTER 4 SYNTAX ANALYSIS Section 5 LR parsers 16、Construction of the canonical LR parsing table Input. An augmented grammar G` Output. The canonical LR parsing table functions action and goto for G` Method. (1) Construct C={I0,I1,…In}, the collection of sets of LR(1) items for G`. (2) State i is constructed from Ii. The parsing actions for state i are determined as follows: CHAPTER 4 SYNTAX ANALYSIS Section 5 LR parsers 16、Construction of the canonical LR parsing table Method (2) a) If [A???a?,b] is in Ii and goto(Ii,a)= Ij, then set ACTION[i,a]=“Shift j”, here a must be a terminal. b) If [A??? ,a]?Ii, A!=S`,then set ACTION[i,a]=rj; j is the No. of production A?? . c) If [S`??S,$]is in Ii, then set ACTION[i,$] to “accept” CHAPTER 4 SYNTAX ANALYSIS Section 5 LR parsers 16、Construction of the canonical LR parsing table Method (3) The goto transitions for state i are determined as follows: if goto (Ii,A)= Ij, then goto[i,A]=j. (4) All entries not defined by rules 2 and 3 are made “error” (5) The initial state of the parser is the one constructed from the set of items containing [S`?? S,$]. If any conflicting actions are generated by the above rules, we say the grammar is not LR(1). state Action goto c d $ S C 0 S3 S4 1 2 1 acc 2 S6 S7 5 3 S3 S4 8 4 r3 r3 5 r1 6 S6 S7 9 7 r3 8 r2 r2 9 r2 CHAPTER 4 SYNTAX ANALYSIS Section 5 LR parsers 16、 Construction of the canonical LR parsing table Notes: 1)Every SLR(1) grammar is an LR(1) grammar 2)The canonical LR parser may have more states than the SLR parser for the same grammar. CHAPTER 4 SYNTAX ANALYSIS Section 5 LR parsers 17、LALR(lookahead-LR) 1)Basic idea Merge the set of LR(1) states having the same core Notes: (1)When merging, the GOTO sub-table can be merged without any conflict, because GOTO function just relies on the core (2) When merging, the ACTION sub-table can also be merged without any conflicts, but it may occur the case of merging of error and shift/redu

文档评论(0)

me54545 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档