书签 分享 收藏 举报 版权申诉 / 52
上传文档赚钱

类型B138编译程序概论课件.ppt

  • 上传人(卖家):晟晟文业
  • 文档编号:4372143
  • 上传时间:2022-12-03
  • 格式:PPT
  • 页数:52
  • 大小:1.15MB
  • 【下载声明】
    1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
    2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
    3. 本页资料《B138编译程序概论课件.ppt》由用户(晟晟文业)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
    4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
    5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
    配套讲稿:

    如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

    特殊限制:

    部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

    关 键  词:
    B138 编译程序 概论 课件
    资源描述:

    1、 1 1.1 1.2 1.3 1.4 (syntax)(semantics)(),COBOLCOmmon Business Oriented Language1960,(CODASYL)1968 1974 ANSI COBOL FORTRANFORmula TRANslation1960,J.Backus 1977 FORTRAN77 ALGOLALGOrithmic LanguageALGOL68-1968 IFIP WG2.1 Pascal1970,N.Wirth -,C1974 D.Ritchie UNIX 1988 ANSI C C+Ada1980 :reliability,simpl

    2、icity,modularity,efficiency:package,generic features,multi-taskingreal-time application C+1983 B.Stroustrup OOPL:class,inheritance,polymorphismJava1996 Sun MicroSystems James Gosling OOPL,Exception processing()&Multithread Internet&Distributed Environment 5th :Independent Platform of OS&H/WC#2000 Mi

    3、crosoft John Gough.NET Platform OOPL(Object-Oriented Prog.Lang.).NET Framework,JIT(Just In-Time Compilation)high Expressiveness&Simplicity C+VB,JAVA VB user interface,C+,JAVA component S/W Compiler A compiler is a computer program which translates programs written in a particular high-level programm

    4、ing language into executable code for a specific target computerSource programSource programObjectprogramObjectprogramError messageLinkageEditorExecutableprogramExecutableprogramCompilerLibrarySource programwith macroSource programRelocatable machine codeAbsolute machine codeLibraryPreprocessorCompi

    5、lerassemblerLinkage EditorObject program(as assembly code)(Cross-Compiler)(PreProcessor)(Assembler)(Interpreter)(Compiler)Cross-Compiler C program in WorkstationObject Code for PC CompileCrossCompile-:assembler ,Compiler :Operational System Interpreter:Developing or Educational System InterpreterInt

    6、erpreterSource Program Macro substitution#define PI 3.141592Conditional compilation-#IF SUB100.Inclusion of files-#include PreprocessorPreprocessorPreprocessorTranslatorSource ProgramTarget Programs SourceProgramFront-EndFront-EndobjectProgramBack-EndBack-EndFront-End language dependent partBack-End

    7、 machine dependent partI.C.:Intermediate CodeO.C.:Optimized Code Lexical AnalyzerSyntax AnalyzerSemantic AnalyzerImmediate Code GenerationCode OptimizationCode GenerationSymbolTableErrorHandlerSource ProgramObject ProgramFrontEndBackEnd1.Lexical Analyzer(Scanner).ex)if(a 10).Token :if (a 10 ).Token

    8、Number:32 7 4 25 5 8 2.Syntax Analyzer(Parser):Syntax checking,syntax Tree generation.:incorrect-error message correct -program structure(tree)ex)if(a 10)a=1;if =a 10 a 13.Intermediate Code Generator ex)if(a 10)a=1.0;/a semantic error!ex)a=b+1;Tree:=a +b 1 Ucode:lod R1 b ldc R1 add store R1 a 4.Code

    9、 OptimizerOptional phase()code code .Meaning of optimizationmajor part:improve running timeminor part:reduce code size ex)LDC R1,1 LDC R1,1 (x)Criteria for optimizationpreserve the program meaningsspeed up on averagebe worth the effortLocal optimizationlocal inspection inefficient code efficient cod

    10、e .1.Constant folding 2.Eliminating redundant load,store instructions 3.Algebraic simplification 4.Strength reductionGlobal optimizationflow analysis technique 1.Common subexpression 2.Moving loop invariants 3.Removing unreachable codes5.Target Code Generator machine instruction.Code generator tasks

    11、1.instruction selection&generation2.register management3.storage allocation4.code optimization(Machine-dependent optimization)6.Error Recovery Error recovery -error Error repair -error Error HandlingError detectionError recoveryError reportingError repairErrorSyntax ErrorSemantic ErrorRun-time Error

    12、 “?”.()().:Analysis()vs.Synthesis()Analysis q ()q (Syntax tree)q :w=x+y*10w=+xy*10 q q MS Office q comment q q :()No Operationq Type check:()Undefined Symbol,type mismatching q()type checking q -(Lexical Analysis)-Symbol,-token stream :)x=y+10;q -(Syntax analysis)-token -q -Type check v Scanning :sc

    13、an token v :.,1):-,2):-,v White space:blank,tab,new line v :position=initial+rate*60 /v :v token v :.v :)exp id|num|exp op exp Stmt id=exp if(exp)then Stmt if(exp)then Stmt else Stmt .op +|-|*|/|.v (),()()(),begin-end Syntax 的=position+initial*rate60Semantic 的=position+initial*rate60inttoreal v v ty

    14、pe Parse tree v Key Focus:Type Checking 1),Symbol Table 2)Type Checking ):5+4.5v Compiler :identifier v identifier 1),type,(,),Scope 2)/type,/type/passing,v Symbol Table 1)field record 2)Hashing 3)type binding Scope RuleLife Timev -.v :)-:-:()-:/Syntax AnalyzerImmediate CodeGenerationCode Generation

    15、Lexical Analyzer=id1+id2*id360Semantic Analyzerid1=id2+id3*60=id1+id2*id360Inttorealtemp1=inttoreal(60)temp2=id3*temp1 temp3=id2+temp2 id1 =temp3Code Optimizationtemp1=id3*60.0 id1 =id2+temp1 Mov ax,id3Mul ax,60.0Mov bx,id2Add ax,bxMov id1,axv ,.v -Object code v (control flow),.v :smaller&faster v :

    16、Pre-code vs.Post-codev :Local Optimization vs.Global Optimization,-Local :(),/,-Global :Flow analysis .,Loop Unreachable code v Peep-hole:,control flow Algebraic,RISC v Relocatable Machine Code Assembly Code -)add ax,k 10001010 v :,:vs.push dx mov wordptrbx+di,1234h mov ax,2 mov bx,5678h mov ax,bx .

    17、0000 52 0001 C741021234 0006 B80002 0009 BB5678 000C 8BC3 .v :binary code op-code,register,symbol,Etc.symbol )MOV a,R1 ADD 2,R1 MOV R1,b v Two-Pass Assembly 1)1st Pass:()Symbol Table 2)2nd Pass:Symbol :a0b40001 01 00 00000000 *0011 01 10 00000010 0010 01 00 00000100 *Loader&Link Editorv Loader:(,Lin

    18、king loader,Linking editor)-:v Link Editor -+()v front-end vs.Back-end -dependent on source program&independent on machine -,symbol table,error handling,()-dependent on machine&immediate code -independent on source program -,symbol table,error handlingv Pass -:,-token ()v Pass -token.-.-Goto forward

    19、 jump jump address -forward jump :Back-patching Goto there /there there:mov x,R1 /there there back-patch.Abstract Syntax Tree forposition=initial+rate*60Assignment statementidposition=expression+expressioninitialidexpression*expressionrateidexpression60numCompiler Generating Tools(=Compiler-Compiler

    20、,Translator Writing System)Language machine compiler.:.N language M N*M .ex)2 language:C,Ada 3 Machine :IBM,SPARC,Pentium C-to-IBM,C-to-SPARC,C-to-Pentium Java-to-IBM,Java-to-SPARC,Java-to-PentiumCompiler-compiler ModelLanguage description grammar theory ,Machine description .HDL:Hardware Descriptio

    21、n Language Computer Architecture design .Machine architecture programming language automatic compiler generation.1.Lexical Analyzer GeneratorLEX:1975 M.E.Lesk .2.Parser Generator(PGS:Parser Generating System)(1)Stanford PGSJohn Hennessy :5000 lines:AST .Output:Abstract Syntax Tree(AST).(2)Wisconsin

    22、PGSC.N.Fisher .:10000 lines:error recovery (3)YACC(Yet Another Compiler Compiler)UNIX.C language .3.Automatic Code Generation Three aspects1.Machine Description:ISP,ISPS,HDL2.Intermediate language3.Code generating algorithmCGAPattern matching code generationTable driven code generation4.Compiler Com

    23、piler System (1)PQCC(Production Quality Compiler Compiler System)W.A.Wulf(Carnegie-Mellon University)input language description target machine description PQC(Production Quality Compiler)table output.tree TCOL.Pattern Matching Code Generation code.(2)ACK(Amsterdam Compiler Kit)Vrije Andrew S.Tanenbaum Compiler Back-End .UNCOL .EM Abstract Machine Code .Portable Compiler .

    展开阅读全文
    提示  163文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
    关于本文
    本文标题:B138编译程序概论课件.ppt
    链接地址:https://www.163wenku.com/p-4372143.html

    Copyright@ 2017-2037 Www.163WenKu.Com  网站版权所有  |  资源地图   
    IPC备案号:蜀ICP备2021032737号  | 川公网安备 51099002000191号


    侵权投诉QQ:3464097650  资料上传QQ:3464097650
       


    【声明】本站为“文档C2C交易模式”,即用户上传的文档直接卖给(下载)用户,本站只是网络空间服务平台,本站所有原创文档下载所得归上传人所有,如您发现上传作品侵犯了您的版权,请立刻联系我们并提供证据,我们将在3个工作日内予以改正。

    163文库