(1.1.1)--1Overview.pdf

上传人:刘静 文档编号:57971668 上传时间:2022-11-06 格式:PDF 页数:23 大小:484.49KB
返回 下载 相关 举报
(1.1.1)--1Overview.pdf_第1页
第1页 / 共23页
(1.1.1)--1Overview.pdf_第2页
第2页 / 共23页
点击查看更多>>
资源描述

《(1.1.1)--1Overview.pdf》由会员分享,可在线阅读,更多相关《(1.1.1)--1Overview.pdf(23页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、Compilers TechniquesIntroductionThe position of compilation principle course in computer science and technology:ProgramminglanguageDiscreteMathematicsDatastructureCompilationprinciplesOperatingsystemInformationsystemsE-commerceSystemsoftwareApplicationsoftwareSoftwareengineeringIntroductionGeneral p

2、rinciples and basic implementation methods of compiler construction are introducedTheoretical knowledge:formal language and automata theory,Syntax-directed definition and attribute grammar,typology and type system,principle of program analysis,etcEmphasis on formal description technologyEmphasis on

3、macro understanding of compilation principles and techniques,no distraction from branch algorithms,no bias towards a source language or target machineCourse ContentSignificance of LearningHave a deep understanding of the implementation and design of programming language,understand the theory related

4、 to programming language,which plays a foundation role in the macro grasp of programming languageFrom the view of software engineering,compiler is a good example.The concepts and techniques introduced can be applied to general software designApplication and development of compiler technology.Advance

5、d language design,computer architecture optimization(parallel,memory stratification),new computer architecture design,program translation,Tools for improving software development efficiency,highly trusted softwareCourse ContentIntroductionThe compiler can logically be divided into several stagesEach

6、 stage transforms the source program from one representation to anotherThis chapter introduces the topic of compiling by describing the various stages of the compilerLexical analyzerSyntax analyzerSemantic analyzerSource programIntermediate-code generatorMachine-independent code optimizerCode genera

7、torMachine-dependent code optimizerTarget-machine codeSymbol tableCompilerOverviewCompilerOverviewSymbol tablepositioninitialrate.123 token flowscharacter streamlexical analysis:source program lexical token stringLexical analyzer id,1 =id,2 +id,3 60 position=initial+rate 60Syntax features of express

8、ionsAny identifier is an expressionAny number is an expressionIf e1 and e2 are all expressions,then e1+e2 e1*e2(e1)are all expressionsExpressionExpressionExpressionIdentifierExpressionExpression(initial)Identifier(rate)Digit(60)*+Parse tree of initial+rate*60 Syntax analysis:lexical token flow synta

9、x phrasesCompilerOverview Syntax tree token flowsSymbol tablepositioninitialrate.123CompilerOverviewSyntax analyzerid,1=id,2+id,3 60=+60id,1id,2id,3Symbol table position initial rate.123 Syntax tree Syntax tree Semantic analysis:checking the semantic correctness of a program,such as type checking Co

10、mpilerOverviewSemantic analyzer=+60id,1id,2id,3=+inttofloatid,1id,2id,360 grammar treeSymbol tablepositioninitialrate.123 Three-address intermediate codeCompilerOverviewIntermediate-code generatort1=inttofloat(60)t2=id3 t1t3=id2+t2id1=t3=+inttofloatid,1id,2id,360Three-address intermediate codeSymbol

11、 tablepositioninitialrate.123Three-address intermediate codeCompilerOverviewCode optimizert1=inttofloat(60)t2=id3 t1t3=id2+t2id1=t3t1=id3*60.0id1=id2+t1 Assembly codeThree-address intermediate codeSymbol tablepositioninitialrate.123CompilerOverviewCode generatorMOVF id3,R2MULF#60.0,R2MOVF id2,R1ADDF

12、 R2,R1MOVF R1,id1t1=id3*60.0id1=id2+t1Lexical analyzerSyntax analyzerSemantic analyzerSource programIntermediate-code generatorMachine-independent code optimizerCode generatorMachine-dependent code optimizerTarget-machine codeSymbol tableCompilerOverviewDifference between an interpreter and a compil

13、erInstead of generating the target code,the interpreter directly performs operations specified by the source program.The interpreter also needs lexical,syntax,and semantic analysis of the source program,and intermediate-code generationBASIC era interpreterFunction:It translates the source program of

14、 a high-level language into an intermediate language program and then interprets and executes it.At that time,the functions of compiling and interpreting were combined in a program called the interpreterJava era interpreterThe above two functions of the interpreter are divided into two programsThe f

15、ormer is called a compiler,which translates the source program into an intermediate language prmgram called bytecodeThe latter is called the interpreter,which interprets bytecode programsCompilerOverviewLexical analyzerSyntax analyzerSemantic analyzerSource programIntermediate-code generatorMachine-

16、independent code optimizerCode generatorMachine-dependent code optimizerTarget-machine codeCompilerOverviewPhase groupingFront endBack endFront end:dependent on the source language,independent of the target machine.Back end:dependent on the target machine,independent of the source language.Front end

17、 andBack endThe compilation process is divided into front-end and back-end.Front end:dependent on source only,independent of target machine(generating intermediate code)Take the front end of a compiler and rewrite its back end to produce the compiler of same source language on another machineDiffere

18、nt front ends use the same back end to get several compilers on one machine(using the same intermediate language)Backend:Dependent on the target machine,independent of the source program,only related to the intermediate language(Generate target code from intermediate code)Benefits:Increased efficien

19、cy in developing compilersIntroductionSource program Target Machine 1Target Machine 2Target Machine 3Target machine nCompilerCompiler that do not distinguish between front end and back end Source program Target Machine 1Target Machine 2Target Machine 3Compilers front endCompilers back end Compilers

20、that distinguish between front end and back end Target machine nIntroductionLexical analyzerSyntax analyzerSemantic analyzerSource programIntermediate-code generatorMachine-independent code optimizerCode generatorMachine-dependent code optimizerTarget-machine codePhase grouping PassA pass scan is co

21、mmonly used in several stages of compilation.A scan includes reading an input file and writing an output file.IntroductionPass:One pass:refers to the whole process that the compiler scans the source program or the equivalent of the source program(intermediate program)from the beginning to the end at

22、 the time of compilation and converts it into another adjacent equivalentSingle pass scan and multi pass scan:each scan can complete one or more of the above stages.The input of each pass is the output of the previous one,the input of the first pass is the text of the source program,and output of th

23、e last pass is object code.Comparison of single and multiple pass:More passes:compiler structure is clear,but time efficiency is not highFewer passes:fast compilation,but high memory requirements for machinesNumber of passes determination:the main factor is the source program and machine(target mach

24、ine)characteristics.IntroductionTools for improving the efficiency of software developmentType checking:Type checking is a mature and effective technique to capture inconsistencies in programs.Boundary check:Data flow analysis technology can be used to locate buffer overflow.Memory management:Automa

25、tic memory management deletion,memory leakage and other memory management errors.Program analysis derived from code optimization techniques in compilers has been improving software development efficiency.Application of Compiler TechnologySyntax-directed structured editor Program formatting toolsSoftware testing toolsProgram understanding toolsTranslation tools for high-level languagesetc.Application of Compiler TechnologyCompilers TechniquesIntroduction

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com