编译原理2E全套配套课件龙书 Chapter_five(2).ppt

编译原理2E全套配套课件龙书 Chapter_five(2).ppt

ID:51619201

大小:552.00 KB

页数:98页

时间:2020-03-26

编译原理2E全套配套课件龙书 Chapter_five(2).ppt_第1页
编译原理2E全套配套课件龙书 Chapter_five(2).ppt_第2页
编译原理2E全套配套课件龙书 Chapter_five(2).ppt_第3页
编译原理2E全套配套课件龙书 Chapter_five(2).ppt_第4页
编译原理2E全套配套课件龙书 Chapter_five(2).ppt_第5页
资源描述:

《编译原理2E全套配套课件龙书 Chapter_five(2).ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、COMPILERCONSTRUCTIONPrinciplesandPracticeKennethC.Louden5.Bottom-UpParsingPARTTWOContentsPARTONE5.1OverviewofBottom-UpParsing5.2FiniteAutomataofLR(0)ItemsandLR(0)ParsingPARTTWO5.3SLR(1)Parsing[More]5.4GeneralLR(1)andLALR(1)Parsing[More]5.5Yacc:AnLALR(1)ParserGenerator[More]

2、5.6GenerationofaTINYParserUsingYacc5.7ErrorRecoveryinBottom-UpParsers[More]LR(0)ItemsofAGrammarA'→AA→(A)

3、aThisgrammarhaseightitems:A'→·AA'→A·A→·(A)A→(·A)A→(A·)A→(A)·A→·aA→a·DFAandtheLR(0)ParsingofThegrammar:A→(A)

4、a123456789ParsingstackinputAction$0$0(3$0(3(3$0(3(3a2$0(3(3A4

5、$0(3(3A4)5$0(3A4$0(3A4)5$0A1((a))$(a))$a)$))$))$)$)$$$shiftshiftshiftreduceA→ashiftreduceA→(A)shiftreduceA→(A)acceptTheLR(0)parsingtableOnecolumnisreservedtoindicatetheactionsforeachstate;Afurthercolumnisusedtoindicatethegrammarchoiceforthereduction;Foreachtoken,thereisacol

6、umntorepresentthenewstate;Transitionsonnon-terminalsarelistedintheGotosections.StateActionRuleInputGoto012345shiftreducereduceshiftshiftreduceA’→AA→aA→(A)(a)A33225145.3SLR(1)ParsingSLR(1),calledsimpleLR(1)parsing,usestheDFAofsetsofLR(0)itemsasconstructedintheprevioussection

7、SLR(1)increasesthepowerofLR(0)parsingsignificantbyusingthenexttokenintheinputstringFirst,itconsultstheinputtokenbeforeashifttomakesurethatanappropriateDFAtransitionexistsSecond,itusestheFollowsetofanon-terminaltodecideifareductionshouldbeperformed5.3.1TheSLR(1)ParsingAlgori

8、thmDefinitionofTheSLR(1)parsingalgorithm(1)Letsbethecurrentstate,actionsaredefinedasfollows:.1.IfstatescontainsanyitemofformA→α·XβwhereXisaterminal,andXisthenexttokenintheinputstring,thentoshiftthecurrentinputtokenontothestack,andpushthenewstatecontainingtheitemA→αX·β2.Ifst

9、atescontainsthecompleteitemA→γ·,andthenexttokenininputstringisinFollow(A)thentoreducebytheruleA→γDefinitionofTheSLR(1)parsingalgorithm(2)2.(Continue)AreductionbytheruleS'→S,isequivalenttoacceptance;Thiswillhappenonlyifthenextinputtokenis$.Inallothercases,Removethestringγand

10、acorrespondingstatesfromtheparsingstackCorrespondingly,backupintheDFAtothestatefro

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。