Compiler Construction Lecture No. 1 By Muhammad Owais Zahid.

Slides:



Advertisements
Similar presentations
COMPILER CONSTRUCTION
Advertisements

compilers and interpreters
Compiler Construction by Muhammad Bilal Zafar (AP)
Programming Types of Testing.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.5 Analysis and Synthesis of Compiler There are two parts to compilation: analysis and synthesis. The analysis part breaks up the source program into.
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
Compiler Construction Composed By, Muhammad Bilal Qureshi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Introduction to Language Programming Hierarchy of programming lang. Based on machine independences: 1. Machine language 2. Assembly language 3. Higher.
Dr. Mohamed Ramadan Saady 314ALL CH1.1 Chapter 1: Introduction to Compiling.
Chapter – 8 Software Tools.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Introduction to Computer Programming using Fortran 77.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Advanced Computer Systems
Component 1.6.
Compiler Design (40-414) Main Text Book:
Introduction to Compiler Construction
CSCI-235 Micro-Computer Applications
CS510 Compiler Lecture 4.
A451 Theory – 7 Programming 7A, B - Algorithms.
Lecture 2 Introduction to Programming
Compiler Lecture 1 CS510.
Compiler Construction
CS416 Compiler Design lec00-outline September 19, 2018
Introduction to Compiler Construction
Textbooks and Class Materials
Course supervisor: Lubna Siddiqui
Introduction CI612 Compiler Design CI612 Compiler Design.
Compiler Construction
Unit 1: Introduction Lesson 1: PArts of a java program
CS416 Compiler Design lec00-outline February 23, 2019
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

Compiler Construction Lecture No. 1 By Muhammad Owais Zahid

2 Course Goals The areas covered in this course include: Compiler techniques and methodology. Phases of compiler Parsing techniques. Contrast b/w compiler and interpreter.

3 Pre- requisite Strong programming background in C, C++ Formal Language (REs,NFAs, DFAs, CFG)

4 Textbooks and Class Materials  Compilers: Principles, Techniques and Tools, Alfred v.Aho, Ravi Sethi, Jeffrey D.Ullman.  Compiler Construction principles and Practice, Kenneth G.Louden  Compiler Design O.G.Kakde  Introduction to computer theory(second Edition) Daniel I.A.Cohen

5 Answer These Questions  What is compiler ?  Why we need compiler?  What are the high or low level languages?  Difference b/w them.

6 Answer These Questions (cont’d)  Difference b/w Assembly and Machine language.  What is the language of computer ?  Why we feel easy in high level language ?

7 What is compiler ? A compiler is a program that reads a program written in one language (i.e source program) And translates it into equivalent program in another Language(i.e the target language). Compiler Source program Target Program

8 Besides this what it does ?

9 The compiler reports to its user the presence of errors in the source program. Compiler Source program Target Program Error Messages

10 Different Terminology  Compiler are sometimes classified as SINGLE PASS,MULTI PASS,DEBUGGING depending on how they have been constructed or on what function they are supposed to perform.Despite the apparent complexity, the basic functions that any compiler must perform are essentially the same.

11 Decompiler “A program that translates from low level to higher level one is a decompiler ” It can be used for the recovery of lost source code,and is also useful in some cases for error correction.In case if the vendor of a software lose its source code,they can use a decompiler to recover the source code from the executable.

12 Decompiler (cont’d) If some error creeps in the executable of a software,it can be decompiled to make corrections.Example of decompiler is: JAD- the fast java decompiler –jad is a 100% pure c++ program and claims to be several times faster than decompilers written in java.Jad is free for non-commercial use,but since the version it’s no longer free for commercial use.

13 The Ethics of Decompilation  Is decompilation legal, and is it allowed? There are many situations when decompilation can be used... 1)To recover lost source code. You may have written a program for which you only have the executable now (or you got the exe of a program you wrote long back, from someone else!). If you want to have the source for such a program, you can use decompilation to recover it. In all rights, you are the owner of the program, so nobody is going to question you.

14 The Ethics of Decompilation(cont’d) 2) Just as stated above, applications written long back for a computer may not have the source code now, and you may need to port it to a new platform. Either you have to rewrite the application from the scratch, or use decompilation to understand the working of the application and write it again.

15 The Ethics of Decompilation(cont’d) 3) Say you have code written in some language for which you cant find a compiler today! If you have the executable, just decompile it and rewrite the logic in the language of your choice today

16 The Ethics of Decompilation(cont’d) 4) To discover the internals of someone else's program (like what algorithm they have used...)

17 The Ethics of Decompilation(cont’d)  Usually all software are copyrighted by the authors. This means, copying or expressing the same idea in another program is prohibited. Hence if you are using decompilation to discover the internals of a program and if that particular part is breaking the copyright of the owner, you are liable for legal action. However, there are some permitted uses of decompilation, like the first three cases stated above

18 The Ethics of Decompilation(cont’d) Also, decompilation of parts of software which do not come under the copyright laws is permitted. In any case, it is better to contact your legal advisor if you are doing any serious work with decompilation.

19 The Ethics of Decompilation(cont’d) In all practical purposes, decompiling programs which were created by you can't be questioned! After all, you are the owner of all rights to the program. But be careful if you are trying it out on someone else's programs.

20 Language Translator  A program that translates between high level languages is usually called a language translator,source to source translator,language converter,or language rewriter (this last term is usually applied to translations that do not involve a change of language)

21 Benefits  The benefit of using a language converter is to preserve investment in software across a change in programming language.As an example,if some organization wants to convert its software made in some old language to a newly arrived language in the software industry,the organization will have to spend a lot of money for this purpose.

22 Benefits (cont’d)  Because the task of conversion requires a lot of programming effort from the programmers.But using a language translator will simplify this task and is not a costly solution.  EXAMPLE Example of language translator is “DIAMOND CONVERTER”.This converter is used to convert a code written in Pascal to Ada.

23 Cross-Compiler “A compiler that runs on one computer but produces object code for a different type of computer ” Cross compilers are used to generate software that can run on computers with a new architecture or on special-purpose devices that cannot host their own compilers.

24 Example  A program developed to control the operations of a microwave oven is an example of such an embedded system.As the software environment of a microwave oven is not that much proficient that is can support its own compiler,so a separate compiler is needed to first separately compile the software code.

25 Example (cont’d)  After compilation,the software is embedded into the machine.This separate compiler used to compile the source code is called a cross compiler.

26 The Analysis-Synthesis Model of Compilation  There are two parts of compilation analysis and synthesis.  The ANALYSIS part breaks up the source program into pieces and creates and intermediate representation of the source program

27 The Analysis-Synthesis Model of Compilation (cont’d)  The SYNTHESIS part constructs the desired target program from the intermediate representation.

28 The Analysis-Synthesis Model of Compilation (cont’d)  D uring analysis the operations implied by the source program are determined and recorded in an hierarchical structure called a TREE.Often a special kind of tree called a SYNTAX TREE is used,in which each node represents an operation and the children of a node represent the arguments of the operation.

29 Example Position:= initial + rate * 60

30 Software Tools  Many software tools that manipulate source programs first perform some kind of analysis.  Some examples of such tools include.

31 Structure Editors  A structure editor takes as input a sequence of commands to build a source program.The structure editor not only performs the text creation and modification functions of an ordinary text editor but it also analyses the program text,putting appropriate hierarchical structure on the source program.Thus the structure editor can perform additional tasks that are useful in preparation of programs.

32 Structure Editors (cont’d)  For example it can check that the input is correctly formed can supply keywords automatically(e.g.when the user types while the editor supplies the matching do and reminds the user that a condition must come between them) and can run from a begin or left parenthesis to its matching end or right parenthesis.Further the output of such an editor is often similar to the output of the analysis phase of a compiler.

33 Pretty Printer A pretty printer analysis a program and prints it in such a way that the structure of the program becomes clearly visible.For example,comments may appear in a special font,and statements may appear with an amount of indentation proportional to the depth of their nesting in hierarchical organization of the statements.

34 Static checkers A static checker reads a programme, analysis it and attempts to discover bugs with running the program for example a static checker may detect the parts of the source program can never be executed or that a certain variable might be used before being defined

35 Interpreter Instead of producing a target program as an translation an interpreter performs the operations implied by the source program for an assignment statement for example and interpreter might build a tree and then carry out the operations at the nodes as it walks the tree.

36 Interpreter (cont’d)  At the root it would discover it (interpreter) had on assignment to perform so it would call a routine to evaluate the expression on the right and then store the resulting value in the location as associated with the identifier position.At the right side of the root the routine would discover,it had to compute the sum of two expressions.It would call itself recursively to compute the value of the expression rate*60 it would then add that value to the value of the variable initial.

37 THANKS