您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > TINY-C编译器的设计与实现-语法分析器的设计与实现
目录摘要...................................................31.前言................................................42.语法分析器的设计原理..................................62.1语法分析器的功能......................................................................62.2语法分析的目标和作用..............................................................62.3构造语法分析器的步骤..............................................................62.4上下文无关文法及分析..............................................................72.5常用的语法分析方法和几种算法的比较..................................92.5.1自上而下分析法.................................................................92.5.2自下而上分析法...............................................................113.语法分析器的设计和实现...............................143.1TINY语言的介绍.......................................................................143.2TINY的文法生成.......................................................................143.3TINY语法分析器算法的选择...................................................173.4TINY语言的递归下降分析程序...............................................203.5TINY语法分析的输出...............................................................223.5.1语法分析的输出结果......................................................223.5.2抽象语法树的节点声明..................................................233.5.3语法树结构......................................................................243.6语法分析的主要函数与核心代码............................................283.6.1语法分析器的主要文件和函数......................................283.6.2语法分析模块..................................................................294.测试分析.............................................394.1测试方法....................................................................................394.2测试计划....................................................................................394.3测试项目说明............................................................................394.4测试结论....................................................................................435.结论与心得...........................................44参考文献.............................................45致谢...................................错误!未定义书签。附录...................................错误!未定义书签。2ContentsAbstract.................................................41.Preface...............................................62.Syntaxanalyzerprincipleofdesign...................72.1Functionofparsing...............................72.2Purposeandfunctionofparsing...................72.3Theofparsinganalyzerstructure.................72.4Context-freegrammarandanalysis.................82.5Commonlysyntaxanalysismethodandseveralalgorithmscomparison........................................102.5.1Fromtoptobottomanalyticmethod..........102.5.2Frombottomtotopanalyticmethod..........123.Syntaxanalyzerdesignandrealization...............153.1IntroduceofTINYlanguage.......................153.2ProductionofTINYgrammar.......................153.3ChoiceofTINYsyntaxanalyzeralgorithm.........183.4RecursiondeclineanalysisprogrameofTINY......213.5OutputofTINYgrammaranalysis..................233.5.1Resultofparsing...........................233.5.2Statementofabstractsyntaxtreenode......243.5.3Thesyntaxtreestruction...................253.6Mainfunctionandcorecodeofsyntaxanalyzer...293.6.1Masterdocumentandfunctionofsyntaxanalyze293.6.2Parsingmodule...............................304.Testingparse........................................404.1Testingmethod...................................404.2TestingPropose..................................404.3Explanationoftestitem.........................404.4Conclusionoftesting............................445.Conclusionandwhatonehaslearned..................45Bibliography............................................46Thanks..................................................47Appendix................................................473TINY-C编译器的设计与实现---语法分析器的设计与实现摘要编译器是将一种源语言翻译为目标语言的计算机程序。本项目采用一种类(ANSI)C的小型语言:TINY语言作为源语言,构造TINY语言的编译器。项目由三人共同完成,其中本人主要是完成了语法分析器的构造,主要工作如下:研究语法分析器的设计原理,并对几种典型的语法分析算法进行分析。生成TINY文法,并证明该文法为LL(1)文法,在此基础上,选择递归下降算法实现TINY语法分析。最终实现了一个TINY语法分析器,它以词法分析器所产生的记号为输入,采用递归下降分析程序进行语法分析,并输出语法树作为下阶段编译的输入。我们最后构造了一个Dephi接口程序,显式输出抽象语法树。关键词:编译器TINY记号语法分析语法树Tiny-CComplierdesignandrealization---SyntaxanalyzerdesignandrealizationRenJun4AbstractThecompilerisacomputerprogramwhichtranslatesthesourcelanguageintothetargetlanguage.Thisprojectusesalanguagesimilarto(ANSI)C:UsingtheTINYlanguageasthesourcelanguagetoconstructthecompilerofTINY.Thewholeprocessoftheprojectisfinishedbythejointeffortofthreepeople,andImyselfmainlycompletedthestructureofsyntaxanalyzer.Themajorworkisasfollows:Analyzingthedesigningprinciplesofthesyntaxanalyzer,andseveralkindsoftypicalparsingalgorithm.ProducingtheTINYgrammar,provingthisgrammarisLL(1)grammar,andinthisfoundation,choosingrecursiondropalgorithmtorealizetheTINYgrammaranalysis.ATINYgrammaranalyzerhasthusbeenaccomplished.Itappliesthesymbolswhichareproducedbythemorphologyanalyzerastheinput,andusestherecursiondropanalysisprogramtocarryonthegrammaranalysis,thenoutputthesyntaxtreeastheinputf
本文标题:TINY-C编译器的设计与实现-语法分析器的设计与实现
链接地址:https://www.777doc.com/doc-5482427 .html