INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –

Slides:



Advertisements
Similar presentations
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Advertisements

Compilers and Language Translation
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.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
CPSC Compiler Tutorial 9 Review of Compiler.
Chapter 9 Compilers and Language Translation. The Compilation Process Phase I: Lexical analysis Phase I: Lexical analysis Phase II: Parsing Phase II:
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Compiled by Benjamin Muganzi 3.2 Functions and Purposes of Translators Computing 9691 Paper 3 1.
Invitation to Computer Science 5th Edition
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
COP4020 Programming Languages
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.
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
CSC 338: Compiler design and implementation
Lexical Analysis - An Introduction. The Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source.
Lexical Analysis - An Introduction Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at.
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.
CST320 - Lec 11 Why study compilers? n n Ties lots of things you know together: –Theory (finite automata, grammars) –Data structures –Modularization –Utilization.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Lexical and Syntax Analysis
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
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 Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
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.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Chapter 1 Introduction Major Data Structures in Compiler
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
Dr. Mohamed Ramadan Saady 314ALL CH1.1 Chapter 1: Introduction to Compiling.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CSC 8505 Compiler Construction
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
Introduction to Compiler Construction
CS 3304 Comparative Languages
Introduction.
-by Nisarg Vasavada (Compiled*)
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Compiler Construction
Course supervisor: Lubna Siddiqui
Introduction CI612 Compiler Design CI612 Compiler Design.
Compilers B V Sai Aravind (11CS10008).
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Introduction Chapter : Introduction.
Presentation transcript:

INTRODUCTION TO COMPUTING CHAPTER NO. 06

Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 – Parsing Phase 3 – Semantic and Code generation Phase 4 – Code Optimization

Introduction All of the high-level languages differ widely in structure and behavior but they are identical in one respect that is no computer can understand them. Therefore these languages must be translated into machine language prior to execution, by a special software called a Compiler. Compilers are very complex programs, as they contain thousands of lines of code and require dozens of person- years to complete. Unlike the assemblers these translators are not easy to design and implement.

Introduction There is a vast difference in complexity between assemblers and compilers. Assembly language and machine language are related 1- to-1, one assembly instruction produces exactly one machine instruction. The relationship between a high-level language and machine language is 1-to-many, one high-level language statement produces many machine language instructions. For this compiler does a thorough linguistic analysis of the structure (syntax) and meaning of each statement.

Introduction When performing a translation, a compiler has two distinct goals. Correctness - The machine language code produced by the compiler must do exactly what the high-level language statement describes, and nothing else. Efficiency and Conciseness – Even though memory costs have come down and processors are much faster, programmers will not accept inefficiencies in either execution speed or size of the compiled program.

The Compilation Process The design and organization of a compiler is variable, an idealized structure of compiler is based on four phases. Phase I : Lexical analysis – The compiler examines the individual characters in the source program and groups them into syntactical units, called tokens, that will be analyzed in succeeding stages (grouping letters into words). Phase II : Parsing – The sequence of tokens formed by the scanner is checked to see whether it is syntactically correct according to the rules of the programming language (checking grammatical errors).

The Compilation Process Phase III : Semantic Analysis and code generation – If the HLL statements is structurally correct, then the compiler analyzes its meaning and generates the proper sequence of machine language instructions to carry out these actions. Phase IV : Code Optimization – Compiler takes the generated code and sees whether it can be made more efficient, either by making it run faster or having it occupy less memory.

The Compilation Process ScannerParser Code generator Optimizer The Compiler Phase IPhase IIPhase IIIPhase IV Source Program Object Program Object File

Phase I: Lexical Analysis Lexical analysis is done by a program called Lexical Analyzer, also termed as a Scanner. Its job is to group input characters into tokens, that are treated as single, indivisible entities for the purposes of translation. Example:a = b – delta; It is visible to scanner as: tab,a,blank,=,blank,b,blank,+,blank,3,1,9,blank,-,blank,d,e,l,t,a,; It is the task of scanner to discard nonessential characters, and then groups the remaining characters into HLL.

Phase I: Lexical Analysis Scanner must classify tokens according to their type (number, symbol, character etc) and also assigns classification number (1 to ----) to all tokens. Regardless of programming language every scanner does the same set of operations. It discards blanks and other nonessential characters looking for the beginning of a token, When it finds the beginning, it puts characters together until, It detects the end of the token, at which point it classifies the token and begins looking for the next one.

Phase II: Parsing The compiler determines whether the tokens recognized by the scanner during phase I fit together in grammatically meaningful way. In Compiler design, the process of diagramming a HLL statement is called Parsing, and it is done by a program called a Parser, the output of a parser is a Parse Tree. The successful construction of a parse tree is proof for ay statement that is correctly formed according to the rules of the language. If a parser cannot produce a parse tree, then the statement is not correctly formed.

Phase II: Parsing a=b+c A PARSE TREE

Phase III: Semantic and Code Generation The compiler examines the semantics of a programming language statement. It analyzes the meaning of the tokens and tries to understand the actions they perform. If the statement is meaningless, then it is semantically rejected, even though it is syntactically correct. If the statement is meaningful, then the compiler translates it into machine language. Example:sum = a + b; This is correct syntactically, but what if the variables ‘a’ and ‘b’ are declared as: char a, double, int sum;

Phase IV: Code Optimization The code optimization techniques were one of the most important reasons for the rapid acceptance of high-level programming languages during the early years of Computer Science. There are two types of optimization: Local and Global. Local Optimization – the compiler looks at a very small block of instructions typically from one to five. It tries to determine how it can improve the efficiency of this local code block without regard for what instructions come before or after.

Phase IV: Code Optimization Global Optimization – the compiler looks at large segments of the program, not just small pieces, to decide how to improve performance. The compiler examines large blocks of code such as loops, if statement, and procedures to determine how to speed up execution. This is a much harder problem, both for a compiler and for a human programmer, but it can produce enormous savings in time and space.