Compilers

2,371 views
1,937 views

Published on

Presentation is about Traditional Two Pass Compiler architecture done by 4th year Computer Science and Technology(special) undergraduates at Uva Wellassa University, Sri Lanka

Published in: Education, Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,371
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
121
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Compilers

  1. 1. Compilers Group #4Independent studies and seminar CST 477-1 Computer Science and Technology Uva Wellassa University
  2. 2. IntroductionWhat is translator A Translator is a computer program that translates one programming language instruction(s) into another programming language instruction(s) without the loss of original meaning.
  3. 3. What is a compiler?If the translator translates a high level language into an assembly or machine language it is called a compiler.Functionalities of a Compiler• recognize legal (and illegal) programs• generate correct code• manage storage of all variables and code• agree on format for object (or assembly) code 3
  4. 4. History1952: First compiler (linker/loader) written by Grace Hopperfor A-0 programming language1957: First complete compiler for FORTRAN by John Backusand team1960: COBOL compilers for multiple architectures1962: First self-hosting compiler for LISP
  5. 5. Some examples for compilersCompiler Author Windows Unix-like Other OSs IDEGNU Java GNU Project No Yes No No Sun MicrosystemJavac Yes Yes Yes No s (Owned by Oracle)C++ Builder Embarcadero Yes No OS X Yes Yes IBM mainframe,GCC C GNU Project Yes Yes AmigaOS, No VAX/VMS, RTEMSVisual Basic Microsoft Yes No DOS Yes
  6. 6. Structure of a compiler• intermediate representation (IR)• front end maps legal code into IR• back end maps IR onto target machine• simplify retargeting• allows multiple front ends• multiple passes better code
  7. 7. Intermediate representationSuppose we wish to build compilers for n source languages and m target machines. Case 1: no IR Need separate compiler for each source language/target machine combination. A total of n ∗ m compilers necessary. Front-end becomes cluttered with machine specific details, back-end becomes cluttered with source language specific details. Case 2: IR present Need just n front-ends, m back ends.
  8. 8. Front end•Line reconstruction.•Lexical analysis•Preprocessing•Syntax analysis•Semantic analysis
  9. 9. Scanner• Lexical analysis breaks the source code text into small pieces called tokens.• Each token is a single atomic unit of the language, for instance a keyword, identifier or symbol name• This phase is also called lexing or scanning
  10. 10. Parser• recognize context-free syntax• guide context-sensitive analysis• produce meaningful error messages• attempt error correction
  11. 11. Back end Analysis This is the gathering of program information from the intermediate representation derived from the input. Optimization the intermediate language representation is transformed into functionally equivalent but faster (or smaller) forms. Code generation the transformed intermediate language is translated into the output language, usually the native machine language of the system.
  12. 12. Instruction selection• produce compact, fast code• use available addressing modes• pattern matching problem — ad hoc techniques — tree pattern matching — string pattern matching — dynamic programming
  13. 13. Register allocation• have value in a register when used• limited resources• changes instruction choices• can move loads and stores• optimal allocation is difficult
  14. 14. Other types of compilerssource-to-source compiler a type of compiler that takes a high level language as its input and outputs a high level language.Stage compiler compiles to assembly language of a theoretical machine, like some Prolog implementations This Prolog machine is also known as the Warren Abstract Machine (or WAM). Bytecode compilers for Java, Python, and many more are also a subtype of this.Just-in-time compiler Applications are delivered in bytecode, which is compiled to native machine code just prior to execution.
  15. 15. Issues Driving Compiler Design Advantage: Self-Contained and Efficient Hardware Optimization Disadvantage: Compiled programs are targeted towards a particular platform and hence are platform dependent. Compile Times They are slower in execution than assembly programs. Compiled programs do not allow security to be implemented with in the code - e.g. a compiled program can access any area of the memory, and can do whatever it wants with your PC (most of the viruses are made in compiled languages). 15
  16. 16. Referencehttp://lambda.uta.edu/cse5317/notes/node5.htmlhttp://dragonbook.stanford.edu/lecture-notes/Stanford-CS143/16-Intermediate-Rep.pdfhttp://en.wikipedia.org/wiki/Compilerhttp://www.personal.kent.edu/~rmuhamma/Compilers/MyCompiler/phase.htm
  17. 17. Group membersUWU/CST/08/0019 LANKATHILAKA B.A.R.UWU/CST/08/0020 LIYANAGE C.J.V.UWU/CST/08/0021 MAHANAMA A.C.UWU/CST/08/0023 MUTUNAYAKE M.N.A.UWU/CST/08/0024 NASHAN M.H.M.UWU/CST/08/0025 NAYANATHARA J.A.J.U.
  18. 18. Thank You

×