外文翻译 - 编译原理技术和工具_第1页
外文翻译 - 编译原理技术和工具_第2页
外文翻译 - 编译原理技术和工具_第3页
外文翻译 - 编译原理技术和工具_第4页
外文翻译 - 编译原理技术和工具_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

外文原文文献CompilersPrinciplesTechniquesAndToolsThefirstphaseofacompileriscalledlexicalanalysisorscanning.Thelexicalanalyzerreadsthestreamofcharactersmakingupthesourceprogramandgroupsthecharactersintomeaningfulsequencescalledlexemes.Foreachlexeme,thelexicalanalyzerproducesasoutputatokenoftheformtoken-name,attribute-valuethatitpassesontothesubsequentphase,syntaxanalysis.Inthetoken,thefirstcomponenttoken-nameisanabstractsymbolthatisusedduringsyntaxanalysis,andthesecondcomponentattribute-valuepointstoanentryinthesymboltableforthistoken.Informationfromthesymbol-tableentryisneededforsemanticanalysisandcodegeneration.Thesecondphaseofthecompilerissyntaxanalysisorparsing.Theparserusesthefirstcomponentsofthetokensproducedbythelexicalanalyzertocreateatree-likeintermediaterepresentationthatdepictsthegrammaticalstructureofthetokenstream.Atypicalrepresentationisasyntaxtreeinwhicheachinteriornoderepresentsanoperationandthechildrenofthenoderepresenttheargumentsoftheoperation.Thesemanticanalyzerusesthesyntaxtreeandtheinformationinthesymboltabletocheckthesourceprogramforsemanticconsistencywiththelanguagedefinition.Italsogatherstypeinformationandsavesitineitherthesyntaxtreeorthesymboltable,forsubsequentuseduringintermediate-codegeneration.Animportantpartofsemanticanalysisistypechecking,wherethecompilerchecksthateachoperatorhasmatchingoperands.Forexample,manyprogramminglanguagedefinitionsrequireanarrayindextobeaninteger;thecompilermustreportanerrorifafloating-pointnumberisusedtoindexanarray.Thecodegeneratortakesasinputanintermediaterepresentationofthesourceprogramandmapsitintothetargetlanguage.Ifthetargetlanguageismachinecode,registersOrmemorylocationsareselectedforeachofthevariablesusedbytheprogram.Then,theintermediateinstructionsaretranslatedintosequencesofmachineinstructionsthatperformthesametask.AcrucialaspectofcodeAnessentialfunctionofacompileristorecordthevariablenamesusedinthesourceprogramandcollectinformationaboutvariousattributesofeachname.Theseattributesmayprovideinformationaboutthestorageallocatedforaname,itstype,itsscope(whereintheprogramitsvaluemaybeused),andinthecaseofprocedurenames,suchthingsasthenumberandtypesofitsarguments,themethodofpassingeachargument(forexample,byvalueorbyreference),andthetypereturned.generationisthejudiciousassignmentofregisterstoholdvariables.Thediscussionofphasesdealswiththelogicalorganizationofacompiler.Inanimplementation,activitiesfromseveralphasesmaybegroupedtogetherintoapassthatreadsaninputfileandwritesanoutputfile.Forexample,thefront-endphasesoflexicalanalysis,syntaxanalysis,semanticanalysis,andintermediatecodegenerationmightbegroupedtogetherintoonepass.Codeoptimizationmightbeanoptionalpass.Thentherecouldbeaback-endpassconsistingofcodegenerationforaparticulartargetmachine.Thecompilerwriter,likeanysoftwaredeveloper,canprofitablyusemodernsoftwaredevelopmentenvironmentscontainingtoolssuchaslanguageeditors,debuggers,versionmanagers,profilers,testharnesses,andsoon.Inadditiontothesegeneralsoftware-developmenttools,othermorespecializedtoolshavebeencreatedtohelpimplementvariousphasesofacompiler.Thesetoolsusespecializedlanguagesforspecifyingandimplementingspecificcomponents,andmanyusequitesophisticatedalgorithms.Themostsuccessfultoolsarethosethathidethedetailsofthegenerationalgorithmandproducecomponentsthatcanbeeasilyintegratedintotheremainderofthecompiler.Somecommonlyusedcompiler-constructiontoolsinclude1.Parsergeneratorsthatautomaticallyproducesyntaxanalyzersfromagrammaticaldescriptionofaprogramminglanguage.2.Scannergeneratorsthatproducelexicalanalyzersfromaregular-expressiondescriptionofthetokensofalanguage.3.Syntax-directedtranslationenginesthatproducecollectionsofroutinesforwalkingaparsetreeandgeneratingintermediatecode.4.Code-generatorgeneratorsthatproduceacodegeneratorfromacollectionofrulesfortranslatingeachoperationoftheintermediatelanguageintothemachinelanguageforatargetmachine.5.Data-flowanalysisenginesthatfacilitatethegatheringofinformationabouthowvaluesaretransmittedfromonepartofaprogramtoeachotherpart.Data-flowanalysisisakeypartofcodeoptimization.6.Compiler-constructiontoolkitsthatprovideanintegratedsetofroutinesforconstructingvariousphasesofacompiler.Compilerdesignisnotonlyaboutcompilers,andmanypeopleusethetechnologylearnedbystudyingcompilersinschool,yethavenever,strictlyspeaking,written(evenpartof)acompilerforamajorprogramminglanguage.Compilertechnologyhasotherimportantusesaswell.Additionally,compilerdesignimpactsseveralotherareasofcomputerscience.外文原文翻译编译原理技术和工具编译器的第一个阶段称为词法分析或扫描。词法分析器读取组成源程序的字符流,并且将它们组织成为有意义的词素的序列。对于每个词素,词法分析器产生如下形式的词法单元作为输出:这个词法单元被传送给下一个步骤,即语法分析。在这个词法单元中,第一个分量token-name是一个由语法分析步骤使用的抽象符号,而第二个分量attribute-value指向符号表中关于这个词法单元的条目。符号表条目的信息会被语义分析和代码生成步骤使用。编译器的第二阶段是语法分析或解析。解析器使用由词法分析器生成的的第一个分量来创建类似树的中间表示。该中间表示给出了词法分析产生的词法单元流的语法结构一个常用的表示方法是语法树,树中的每个内部节点表示一个运算,而该节点的子节点代表该运算的分量。语义分析器使用语法树和符号表中的信息来检查源程序是否和语言定义的语义一致。它同时也收集类型信息,并把这些信息存放在语法树或符号表中,以便在随后的中间代码生成过程中使用。语义分析的一个重要部分是类型检查。编译器检查每个运算符是否具有匹配的运算分量。比如,很多程序设计语言的定义中要求一个数组的下标必须是整数。如果用一个浮点数作为数组下标,编译器就必须报错。代码生成器以源程序的中间表示形式作为输入,并把它映射到目标语言。如果目标语言是机器代码,那么就必须为程序使用的每个变量选择寄存器或内存位置。然后,中间指令被翻译成为能够完成相同任务的机器指令序列。代码生成的一个至关重要的方面是合理分配及寻求以存放变量的值。编译器的重要功能之一是记录源程序中使用的变量的名字,并收集和每个名字的各种属性有关的信息。这些属性可以提供一个名字的存储分配、它的类型、作用域(即在程序的哪些地方可以使用这个名字的值)等信息。对于过程名字,这些信息还包括:它的参数数量和类型、每个参数的传递方法(比如传值或传引用)以及返回类型。前面关于步骤的讨论讲的是一个编译器的逻辑组织方式。在一个特定的实现中,多个步骤的活动可以被组合成一趟。每趟读入一个输入文件并产生一个输出文件。比如,前端步骤中的词法分析、语法分析、语义分析,以及中间代码生成可以组合在一起成为一趟。代码优化可以作为一个可选的趟。然后可以有一个为特定目标机生成代码的后端

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论