- 1、本文档共117页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
CS 1352 Principles of Compiler Design — Unit - 2 — — Syntax
Unit-2 : Syntax Analysis * goto operation If I is a set of LR(1) items and X is a grammar symbol (terminal or non-terminal), then goto(I,X) is defined as follows: If A ? ?.X?,a in I then every item in closure({A ? ?X.?,a}) will be in goto(I,X). * Unit-2 : Syntax Analysis * Construction of The Canonical LR(1) Collection Algorithm: C is { closure({S’?.S,$}) } repeat the followings until no more set of LR(1) items can be added to C. for each I in C and each grammar symbol X if goto(I,X) is not empty and not in C add goto(I,X) to C goto function is a DFA on the sets in C. * Unit-2 : Syntax Analysis * A Short Notation for The Sets of LR(1) Items A set of LR(1) items containing the following items A ? ?.?,a1 ... A ? ?.?,an can be written as A ? ?.?,a1/a2/.../an * Unit-2 : Syntax Analysis * Canonical LR(1) Collection -- Example S ? AaAb I0: S’ ? .S ,$ I1: S’ ? S. ,$ S ? BbBa S ? .AaAb ,$ A ? ? S ? .BbBa ,$ I2: S ? A.aAb ,$ B ? ? A ? . ,a B ? . ,b I3: S ? B.bBa ,$ I4: S ? Aa.Ab ,$ I6: S ? AaA.b ,$ I8: S ? AaAb. ,$ A ? . ,b I5: S ? Bb.Ba ,$ I7: S ? BbB.a ,$ I9: S ? BbBa. ,$ B ? . ,a S A B a b A B a b to I4 to I5 * Unit-2 : Syntax Analysis * Canonical LR(1) Collection – Example2 S’ ? S 1) S ? L=R 2) S ? R 3) L? *R 4) L ? id 5) R ? L I0:S’ ? .S,$ S ? .L=R,$ S ? .R,$ L ? .*R,$/= L ? .id,$/= R ? .L,$ I1:S’ ? S.,$ I2:S ? L.=R,$ R ? L.,$ I3:S ? R.,$ I4:L ? *.R,$/= R ? .L,$/= L? .*R,$/= L ? .id,$/= I5:L ? id.,$/= I6:S ? L=.R,$ R ? .L,$ L ? .*R,$ L ? .id,$ I7:L ? *R.,$/= I8: R ? L.,$/= I9:S ? L=R.,$ I10:R ? L.,$ I11:L ? *.R,$ R ? .L,$ L? .*R,$ L ? .id,$ I12:L ? id.,$ I13:L ? *R.,$ to I6 to I7 to I8 to I4 to I5 to I10 to I11 to I12 to I9 to I10 to I11 to I12 to I13 id S L L L R R R id id id R L * * * * I4 and I11 I5 and I12 I7 and I13
文档评论(0)