Compiler 2nd Edition By Alfred V.Aho Slides Ppt Download

Download

compiler n.

Skip this Video

Loading SlideShow in 5 Seconds..

Compiler PowerPoint Presentation

play prev play next

Compiler

Download Presentation

Compiler

- - - - - - - - - - - - - - - - - - - - - - - - - - - E North D - - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

  1. Compiler Chang Chi-Chung 2008.02.26

  2. Textbook • Compilers: Principles, Techniques, and Tools, 2/East. • Alfred V. Aho, Columbia University • Monica S. Lam, Stanford University • Ravi Sethi, Avaya Labs • Jeffrey D. Ullman, Stanford University • Free books • http://freecomputerbooks.com Dragon

  3. Score • Midterm Examination twenty% • Final Examination 25% • Quizz(2) 30% • Project 10% • Homework x% • Participation 5%

  4. Objectives • 瞭解編譯器的構建原理 • Know how to utilize compiler construction tools, such as generators of scanners and parsers • Be able to ascertain LL(1), LR(one), and LALR(1) grammars • Exist familiar with compiler analysis and optimization techniques • 建立屬於自己的編譯器

  5. History • Early 1950's • Mnemonic assembly languages. • Macro instructions were added later. • In the latter half of the 1950 • Fortran: scientific computation. • To take 18 human-years • Cobol: business organisation data processing. • Lisp: symbolic computation.

  6. History - Grace Hooper

  7. Programming Languages 低階語言 machine dependent 高階語言 machine independent 自然語言 none 機器語言 組合語言 C、C++、Java … Chinese English language German

  8. Introduction to Compilers(1) Compiler Source Programme Target Plan • Source programme must exist equivalent to target program. • Definitions • Recognizer • Translator

  9. Introduction to Compilers(ii) • Translator • from one format to another • query interpreter • text formatter • silicon compiler • infix note  postfix notation: 3 + 5 - 6 * 6 ====> 3 5 + 6 6 * - • pretty printers • Computational theory • power of certain machines • the set of languages that can be recognized by this machine • Grammer • definition of this car

  10. Impacts on Compilers • Programming languages • Auto architecture • Language theory • Algorithms and information structures • Software technology

  11. Use the Compiler Techniques • Programming Languages (C、C++…) • Scripts (Javascript、bash) • Editors (syntax highlighting) • Pretty printers (e.grand. Doxygen) • Static checkers (e.g. Lint and Splint) • Interpreters • Text formatters (east.g. TeX and LaTeX) • Silicon compilers (due east.1000. VHDL) • Query interpreters/compilers (Databases)

  12. Input Compiler Target Program Source Program Mistake messages Output Compilers 編譯器 • Compilation • Translation of a program written in a source language into a semantically equivalent plan written in a target language

  13. Source Programme Interpreter Output Input Fault messages Interpreters 直譯器 • Interpretation • Performing the operations implied past the source programme

  14. Hybrid Source Plan Translator Virtual Car intermediate program input output

  15. Compiler vs. Interpreter • 請自己蒐集資料比較

  16. A Linguistic communication-Processing Organization source plan Preprocessor Try for example: gcc -v myprog.c modified source program Compiler target assembly plan Assembler relocatable machine code library files relocatable object files Linker/Loader target machine code

  17. character stream Phases of a Compiler Lexical Analyzer token stream Syntax Analyzer syntax tree Semantic Analyzer syntax tree Symbol Table Intermediate Lawmaking Generator intermediate representation Machine-Independent Code Optimizer intermediate representation Code Generator target-machine code Machine-Dependent Lawmaking Optimizer target-machine lawmaking target-machine lawmaking

  18. = = + <id,1> + <id,ane> * <id,2> * <id,2> <id,3> sixty <id,three> inttofloat 60 character stream position = initial + charge per unit * 60 Lexical Analyzer <id,ane> <=> <id,2> <+> <id,three> <*> <60> Syntax Analyzer Semantic Analyzer

  19. Intermediate Code Generator t1 = inttofloat(60) t2 = id3 * t1 t3 = id2 + t2 id1 = t3 Machine-Independent Code Optimizer t1 = id3 * 60.0 id1 = id2 + t1 Code Generator LDF R2, id3 MULF R2, R2, #60.0 LDF R1, id2 ADDF R1, R1, R2 STF id1, R1 SYMBOL TABLE

  20. The Grouping of Phases • Compiler front and dorsum ends: • Front finish: analysis (machine contained) • Back end: synthesis (machine dependent) • Compiler passes: • A drove of phases is done but once (single pass) or multiple times (multi pass) • Unmarried laissez passer: usually requires everything to be defined earlier being used in source plan • Multi pass: compiler may take to keep unabridged program representation in memory

  21. The Analysis-Synthesis Model of Compilation • There are 2 parts to compilation: • Analysis determines the operations implied past the source program which are recorded in a tree construction • Synthesis takes the tree structure and translates the operations therein into the target program

  22. Compiler-Construction Tools • Software development tools are bachelor to implement 1 or more compiler phases • Scanner generators • Parser generators • Syntax-directed translation engines • Automated code generators • Data-flow engines

  23. Programming Language Bones(ane) • Static vs. Dynamic • Compile Time vs. Run Fourth dimension • Examples • scope of declarations • memory location of variables • Environments and States environment land locations (variables) names values According to the telescopic rules of a linguistic communication

  24. Programming Language Basic(2) • Static Scope and Block Construction • C/C++ uses { } • Pascal uses begin, end • Explicit Access Control • C++, C#, Coffee provide public, protected, individual • Dynamic Scope • Parameter Passing Mechanisms • caller and callee • actual parameters and formal parameters. • call by value • telephone call by reference (call by address) • phone call by name • Aliasing

  25. program Examination; beginx=ane;y=two;SUB(x,x+y);print(x); end; An Example procedure SUB(i,j) begin i=i+1; impress(x); i=i+j; print(i); cease;

  26. Results • Answer • Call-by-reference 2,five,5 • Call-by-value 1,v,1 • Phone call-by-name 2,vi,six • Phone call-by-value and re-create-restore 1,5,5

DOWNLOAD HERE

Posted by: carterthismis.blogspot.com