Dixita Kagathara Page 1

Similar documents

LANGUAGE PROCESSORS. Presented By: Prof. S.J. Soni, SPCE Visnagar.

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

CS 4201 Compilers 2014/2015 Handout: Lab 1

Language Processors Chapter 1. By: Bhargavi H Goswami Assistant Professor Sunshine Group of Institutes Rajkot, Gujarat, India

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Life Cycle of Source Program - Compiler Design

COMPILER DESIGN. For COMPUTER SCIENCE

SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A

Compiler Design (40-414)

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design


COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP455: COMPILER AND LANGUAGE DESIGN. Dr. Alaa Aljanaby University of Nizwa Spring 2013

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

Compiler, Assembler, and Linker

CST-402(T): Language Processors

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

QUESTION BANK CHAPTER 1 : OVERVIEW OF SYSTEM SOFTWARE. CHAPTER 2: Overview of Language Processors. CHAPTER 3: Assemblers

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character

COMPILER DESIGN LECTURE NOTES

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

1. INTRODUCTION TO LANGUAGE PROCESSING The Language Processing System can be represented as shown figure below.

Formal Languages and Compilers Lecture I: Introduction to Compilers

VIVA QUESTIONS WITH ANSWERS

Question Bank. 10CS63:Compiler Design

CS426 Compiler Construction Fall 2006

LANGUAGE TRANSLATORS

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Compiling Regular Expressions COMP360

Principles of Compiler Design

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR / EVEN SEMESTER

Introduction. Interpreters High-level language intermediate code which is interpreted. Translators. e.g.

COMPILER DESIGN UNIT I LEXICAL ANALYSIS. Translator: It is a program that translates one language to another Language.

Compiler Design Overview. Compiler Design 1

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

A Simple Syntax-Directed Translator

Introduction to Compiler Construction

UNIT I- LEXICAL ANALYSIS. 1.Interpreter: It is one of the translators that translate high level language to low level language.

Dixita Kagathara Page 1

Compiler Design. Lecture 1

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER-15 EXAMINATION Model Answer Paper

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY

Group A Assignment 3(2)

CS131: Programming Languages and Compilers. Spring 2017

Chapter 2 A Quick Tour

Introduction to Compiler Construction

COMPILER DESIGN LEXICAL ANALYSIS, PARSING

Introduction to Compiler Construction

PSD1C SYSTEM SOFTWAE UNIT: I - V PSD1C SYSTEM SOFTWARE

Have examined process Creating program Have developed program Written in C Source code

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Undergraduate Compilers in a Day

names names identifiers variables subroutines constants

AS-2883 B.Sc.(Hon s)(fifth Semester) Examination,2013 Computer Science (PCSC-503) (System Software) [Time Allowed: Three Hours] [Maximum Marks : 30]

PART ONE Fundamentals of Compilation

4. An interpreter is a program that

A simple syntax-directed

Time : 1 Hour Max Marks : 30

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Crafting a Compiler with C (II) Compiler V. S. Interpreter

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

Programming in C++ 4. The lexical basis of C++

CS 132 Compiler Construction

CSE 504: Compiler Design. Code Generation

PRINCIPLES OF COMPILER DESIGN

Introduction. Compilers and Interpreters

Compilers and Interpreters

Fundamentals of Compilation

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

Overview of Compiler. A. Introduction

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

Pioneering Compiler Design

Compiler Design IIIT Kalyani, West Bengal 1. Introduction. Goutam Biswas. Lect 1

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

CMPT 379 Compilers. Anoop Sarkar.

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

VALLIAMMAI ENGINEERING COLLEGE

LECTURE NOTES ON COMPILER DESIGN P a g e 2

GUJARAT TECHNOLOGICAL UNIVERSITY

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

CA Compiler Construction

AC59/AT59 OPERATING SYSTEMS & SYSTEMS SOFTWARE DECEMBER 2012

Introduction to Compiler Construction

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

UNIT I. Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK-4. 1

Introduction to Compiler Construction

COSC121: Computer Systems: Runtime Stack

Principles of Programming Languages. Lecture Outline

III) EXAMINATION, 2015 CS 331 : SYSTEM PROGRAMMING AND OPERATING SYSTEM I

Introduction to Compiler Design

Compiler Design. Subject Code: 6CS63/06IS662. Part A UNIT 1. Chapter Introduction. 1.1 Language Processors

Intermediate Code Generation

2) Save the Macro definition:- The processor must store the macro instruction definitions which it will need for expanding macro calls.

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

COMPILERS BASIC COMPILER FUNCTIONS

Transcription:

2014 Sem - VII Introduction 1) Explain Phases of compiler or Analysis synthesis model of compilation. The compiler is designed into two parts. The first phase is the analysis phase while the second phase is called synthesis. The main objective of the analysis phase is to break the source code into parts. It then arranges these pieces into a meaningful structure (or grammar of the language). Lexical analysis, syntax analysis and semantic analysis constitute the analysis phase. The Synthesis phase is concerned with generation of target language statement which have the same meaning as the source statement. Lexical Analysis: Lexical analysis identifies the lexical unit in a source statement. Then it classifies the units into different lexical classes. E.g. id s, constants, keyword etc...and enters then into different tables. Lexical analysis builds a descriptor, called a token. We represent token as code#no Consider following code i: integer; a,b: real; abi; The statement a:bi is represented as a string of token a b i Id#1 Op#1 Id#2 Op#2 Id#3 Syntax Analysis: The syntax analyzer checks each line of the code and spots every tiny mistake that the programmer has committed while typing the code. Syntax analysis processes the string of token to determine statement class and also check whether given statement is syntax wise valid or not. a b i Semantic Analysis: The letter identifies the sequence of actions necessary to implement the meaning of a source statement. It adds information to a table or adds action to the sequence of actions. The analysis ends when the tree has been completely processed. Dixita Kagathara Page 1

a, real a, real a,real temp,real b,real i,int b,real i*,real Intermediate representation IR contains intermediate code and table. Symbol table symbol Type length address 1 i int 2 a real 3 b real 4 i* real 5 temp real Intermediate code 1. t1: int to real (id1) 2. t2:t1b 3. a:t2 Code Optimization: As the name suggests, this phase aims at optimizing the target code. The code can be optimized in terms of time taken to execute, length of the code, memory utilized or any other criteria. Code Generation: Target code is generated at this phase using the intermediate representation of the source program. The machine instructions perform the same tasks as the intermediate code. Registers are allocated to variables in the program. This has to be done carefully so as to avoid any clashes or repeated assignments. Various algorithms have been formulated to generate the most efficient machine code. the synthesis phase may decide to hold the value of i* and temp in machine registers and may generate the assembly code CONV_R AREG, I ADD_R AREG, B MOVEM AREG, A Dixita Kagathara Page 2

Lexical Analysis Syntax Analysis Symbol Table Semantic Analysis Intermediate Code Generation Error detection and recovery Code Optimization Code Generation Target A symbol table is a data structure used by a language translator such as a compiler or interpreter, for storing names encountered in the source program, along with the relevant attributes for those names. Information about following entities is store in symbol table Variable/Identifier Procedure/function Keyword (store before lexical analysis starts) Constant Class name Label name Structure & union name Symbol table is used in different phases of compiler as listed below Semantic Analysis: check correct semantic usage of language constructs Code generation: All program variables and temporaries need to be allocated some memory locations Error Detection: Leave variables undefined Optimization: To reduce the total number of variables used in a program we need to reuse the temporaries generated by the compiler 2) What is passes of compiler? Also explain forward reference issue. Language processing analysis of SP synthesis of TP. Each compiler consists of mainly two phases 1. Analysis phase 2. Synthesis phase Analysis phase uses each component of source language to determine relevant information Dixita Kagathara Page 3

concerning a statement in the source statement. Thus, analysis of source statement consists of lexical, syntax and semantic analysis.(front end) While, synthesis phase is concerned with the construction of target language. It includes mainly two activities memory allocation and code generation.(back end) Compiler Source Analysis phase Synthesis phase Target Errors Errors If compilation can be performed on statement by statement basis- that is, analysis of source statement cab be immediately followed by synthesis of equivalent target statement. This may not be feasible due to: Forward reference: a forward reference of a program entity is a reference to the entity which precedes its definition in the program. This problem can be solved by postponing the generation of target code until more information concerning the entity becomes available. It leads to multipass model of language processing. Language processor pass: a language processor pass is the processing of every statement in a source program, to perform language processing function. In Pass I: Perform analysis of the source program and note relevant information In Pass II: It once again analyses the source program to generate target code using type information noted in pass I. The language processor performs certain processing more than once. This can be avoided using an intermediate representation (IR) of the source program An intermediate representation is a representation of a source program which reflects the effect of some, but not all, analysis and synthesis task performed during language processing. Source Front End Back End Target Intermediate representation (IR) 3) Explain cousins of the compiler OR Explain roles linker, loader and preprocessor in compilation process. Preprocessor Preprocessor produce input to compiler. They may perform the following functions: Dixita Kagathara Page 4

1. Macro processing: A preprocessor may allow user to define macros that are shorthands for longer constructs. 2. File inclusion: A preprocessor may include the header file into the program text. 3. Rational preprocessor: Such a preprocessor provides the user with built in macro for construct like while statement or if statement. 4. Language extensions: this processors attempt to add capabilities to the language by what amount to built-in macros. Ex: the language equal is a database query language embedded in C. statement beginning with ## are taken by preprocessor to be database access statement unrelated to C and translated into procedure call on routines that perform the database access. Linker Linker allows us to make a single program from a several files of relocatable machine code. These file may have been the result of several different compilation, and one or more may be library files of routine provided by a system and available to any program that needs them. Loader The process of loading consists of taking relocatable machine code, altering the relocatable address and placing the altered instructions and data in memory at the proper location. Dixita Kagathara Page 5