Docsity

Compiler Construction Part 1-Compiler Construction-Lecture Slides, Slides of Compiler Construction

Partial preview of the text

Download Compiler Construction Part 1-Compiler Construction-Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

1

Compiler

Construction

By :

Sufi Tabassum Gul

10/15/

LayoutLayout

  1. Introduction
  2. Course Outline
  3. Compilers
  4. Functions of Compilers
  5. Anatomy of a Compiler
  6. Conclusion

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 22

3

Why Study Compilers?Why Study Compilers?

ƒ General background of a software engineer

  • How do compilers work?
  • How do computers work? (instruction set, registers, addressing modes, run time data structures, …)
  • What machine code is generated for certain language constructs? (efficiency considerations)
  • Getting "a feeling" for good language design

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 33

10/15/

Why Study Compilers?

W iti il i d t di f

Why Study Compilers?

ƒ Writing a compiler requires an understanding of almost all of the major subfields of computer sciencescience

  • Theory of automata for parsing and lexical analysis
  • A whole lot of programmingg g
  • Some programming language design theory
  • Some assembly language
  • A bit of computer architecture
  • A large range of data structures and algorithms

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 44

  • A good software engineering principles to tie everything together

7

Computer Language EngineeringComputer Language Engineering

  1. How to give instructions to a computer?
  2. How to make the computer carryout the instructions efficiently?

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 77

10/15/

History (1/3)History (1/3)

ƒ Jon Von Neumann in the late 1940: Machine Language

  • C7 06 0000 0002 ƒ AssemblyAssembly LanguageLanguage inin whichwhich instructionsinstructions andand memory locations are given in symbolic form
  • MOV XMOV X , 2 2 ƒ Machine Independent Form

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 88

  • X = 2

9

History (2/3)History (2/3)

ƒ 1957 Fortran ¾ First steps ¾ Arithmetic expressions ¾ Set of procedures ƒ 1960 Algol (Algo Oriented Language) ¾ First formal language definition ¾ Block structure (locality of names) ¾ Recursion

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 99

10/15/

History (3/3)History (3/3)

ƒ 1970 Pascal ¾ Type concept ¾ Virtual machines (P-code) ¾ RR ecursive descent parsingi d t i

ƒ today C++, Java, … ¾¾ Optimizing compilersOptimizing compilers ¾ New language concepts ¾ Separate compilation ¾ Object-orientation ¾ Threads and distribution ¾ Exception handling

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 1010

13

Programming LanguagesProgramming Languages

ƒ Properties

  • need to be unambiguous
  • need to be precise
  • need to be concise
  • need to be expressive
  • need to be at a high-level (lot of abstractions)

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 1313

10/15/

How to instruct the computerp

  1. Write a program using a programming language
    • High level Abstract Description
  2. Microprocessors talk in assembly language
    • Low-level Implementation DetailsLow level Implementation Details

Program (^) A bl

Compiler

g written in a Programming Languages

Assembly Language Translation 15 15--OctOct--10 10 SufiSufi TabassumTabassum GulGul 1414

Languages

15

How to instruct the computerHow to instruct the computer

ƒ Input => High-level programming language

ƒƒ Output => Low level assembly instructionsOutput => Low-level assembly instructions

ƒ Compiler has to:

  • Read and understand the program
  • Precisely determine what actions it require
  • Figure-out how to carry-out those actions
  • Instruct the computer to carry out those actions

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 1515

10/15/

In a NutshellIn a Nutshell

Compilers are computer programs that translate one language to another.g g Compiler takes as itsp input a program written in Source Language and produces a program written in Target Languageproduces a program written in Target Language. Usually the source language is High Level LLanguage and the target language is Object Code d th t t l i Obj t C d sometimes also called Machine Code.

15 15--OctOct--10 10 Sufi Tabassum GulSufi Tabassum Gul 1616