PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

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


COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou


COMPILER DESIGN LECTURE NOTES

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Compiler Design (40-414)

COMPILER DESIGN. For COMPUTER SCIENCE

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

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Formal Languages and Compilers Lecture I: Introduction to Compilers

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

Compilers. Prerequisites

CST-402(T): Language Processors

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

CS 4201 Compilers 2014/2015 Handout: Lab 1

Compiling Regular Expressions COMP360

Introduction to Compiler Design

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.

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

LECTURE NOTES ON COMPILER DESIGN P a g e 2

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

Compiler, Assembler, and Linker

Introduction to Compiler Construction

Introduction to Compiler Construction

Introduction to Compiler Construction

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

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

Introduction to Compiler Construction

LANGUAGE TRANSLATORS

A Simple Syntax-Directed Translator

Lexical Scanning COMP360

Pioneering Compiler Design

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Dixita Kagathara Page 1

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

UNIT-4 (COMPILER DESIGN)

CS131: Programming Languages and Compilers. Spring 2017

Theory and Compiling COMP360

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

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

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

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

PRINCIPLES OF COMPILER DESIGN

Introduction. Compilers and Interpreters

VIVA QUESTIONS WITH ANSWERS

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

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

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

Compiler Design Overview. Compiler Design 1

Life Cycle of Source Program - Compiler Design

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

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

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

Compiler Structure. Lexical. Scanning/ Screening. Analysis. Syntax. Parsing. Analysis. Semantic. Context Analysis. Analysis.

Building Compilers with Phoenix

Question Bank. 10CS63:Compiler Design

INTRODUCTION TO COMPILER AND ITS PHASES

TABLE OF CONTENTS S.No DATE TOPIC PAGE No UNIT I LEXICAL ANALYSIS 1 Introduction to Compiling-Compilers 6 2 Analysis of the source program 7 3 The

COMPILERS BASIC COMPILER FUNCTIONS

Chapter 2 A Quick Tour

Compilation I. Hwansoo Han

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

Group A Assignment 3(2)

Theoretical Part. Chapter one:- - What are the Phases of compiler? Answer:

Overview of Compiler. A. Introduction

COMPILER DESIGN LEXICAL ANALYSIS, PARSING

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

Compiler Code Generation COMP360

Introduction to Syntax Analysis. Compiler Design Syntax Analysis s.l. dr. ing. Ciprian-Bogdan Chirila

Computer Hardware and System Software Concepts

PSD1C SYSTEM SOFTWAE UNIT: I - V PSD1C SYSTEM SOFTWARE

4. An interpreter is a program that

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

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

LANGUAGE PROCESSORS. Introduction to Language processor:

CS 415 Midterm Exam Spring SOLUTION

Time : 1 Hour Max Marks : 30

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

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

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

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Stating the obvious, people and computers do not speak the same language.

G Compiler Construction Lecture 4: Lexical Analysis. Mohamed Zahran (aka Z)

CSE302: Compiler Design

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

Advanced Programming & C++ Language

LESSON 13: LANGUAGE TRANSLATION

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

2068 (I) Attempt all questions.

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

CS426 Compiler Construction Fall 2006

Undergraduate Compilers in a Day

CSCI-GA Compiler Construction Lecture 4: Lexical Analysis I. Hubertus Franke

Laboratorio di Programmazione. Prof. Marco Bertini

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Semantic Analysis. Compiler Architecture

Transcription:

PRINCIPLES OF COMPILER DESIGN 2 MARKS UNIT I INTRODUCTION TO COMPILING 1. Define compiler? A compiler is a program that reads a program written in one language (source language) and translates it into an equivalent program in another language (target language) and the compiler reports to its user the presence of errors in the source program. 2. What are the classifications of compiler? i) Single pass compiler ii) Multi pass compiler iii) Load-and-go compiler iv) Debugging or optimizing compiler 3. What are the phases of compiler? 1. Lexical analyzer 2. Syntax analyzer 3. Semantic analyzer 4. Intermediate code generation 5. Code generation 6. Code optimization 7. symbol table manager. 8. Error Handler 4. Define preprocessor & what are the functions of preprocessor? Preprocessor produce input to the compilers (i.e.) the program will be divided in to the modules. They perform the following functions. i) Macro processing ii) File inclusion iii) Rational preprocessor

iv) Language extension 5. What are the tools available in analysis phase? i) Structure editors ii) Pretty printer iii) Static checkers iv) Interpreters. 6. Define pretty printers? A pretty printer analyzes a program and prints it in such a way that the structure of the program becomes clearly visible. For the comments may appear with an amount of indentation proportional to the depth of their nesting in the hierarchical organization of the statements. 7. Define assembler and its types? It is defined by the low level language is assembly language and high level language is machine language is called assembler. One pass assembler Two pass assembler 8. Give the types of a language processing system? a) Preprocessors b) Compilers c) Assembler d) Loaders and link editors 9. What are the functions performed in analysis phase? a) Lexical analysis or Linear analysis b) Syntax analysis or hierarchical analysis c) Semantic analysis 10. What are the functions performed in synthesis phase? i) Intermediate code generation ii) Code generation iii) Code optimization 11. Give the classification of processing performed by the semantic analysis? a) Processing of declarative statements. b) Processing of executable statements. 12. Give the properties of intermediate representation?

a) It should be easy to produce. b) It should be easy to translate into the target program. 13. What are the two different parts of compilation? a) Analysis phases of compilation b) Synthesis phases of compilation 14. What is the role of lexical analysis phase? Lexical analyzer reads the source program one character at a time, and grouped into a sequence of atomic units called tokens. Identifiers, keywords, constants, operators and punctuation symbols such as commas, parenthesis, are typical tokens. 15. What is meant by syntax analysis? This phase processes the string of descriptors, synthesized by the lexical analyzer, to determine the syntactic structure of an input statement. This process is known as parsing. Output of the parsing step is a representation of the syntactic structure of a statement in the form of syntax tree. 16. What is meant by intermediate code generation? After syntax and semantic analysis, some compilers generate an explicit intermediate representation of the source program. It can have a variety of forms. This form called three-address code. It consists of sequence of instructions, each of which has at most three operands. 17. What is meant by semantic analysis? This phase checks the source program for semantic errors and gathers type of information for the subsequent phase. An important component of semantic analysis is type checking.in type checking the compiler checks that each operator has operands that are permitted by the source language specification 18. What do you meant by interpreter? A translator that transform a programming language into a simplified language called intermediate code, which can directly execute using a program called an interpreter. 19. What do you meant by phase? Each of which transforms the source program one representation to another. A phase is a logically cohesive operation that takes as input one representation of the source program and produces as output another representation 20. Write short notes on symbol table manager?

The table management or bookkeeping portion of the compiler keeps track of the names used by program and records essential information about each, such as its type (int,real etc.,) the data structure used to record this information is called a symbol table manager. 21. Write short notes on error handler? The error handler is invoked when a flaw in the source program is detected. It must warn the programmer by issuing a diagnostic, and adjust the information being passed from phase to phase so that each phase can proceed. So that as many errors as possible can be detected in one compilation. 22. Mention some of the cousins of the compiler? i) Preprocessors ii) Assemblers iii) Two pass assembly iv) Loaders and Linker-editors. 23. What is front end and back end? The phases are collected into a front end and a back end. The front end consists of those phases or parts of phases, that depends primarily on the source language and is largely independent of the target machine. The back ends that depend on the target machine and generally these portions do not depend on the source language. 24. What do you meant by pass? A pass reads the source program or the output of the previous pass, makes the transformations specified by its phases and writes output into an intermediate file, which may then be read by a subsequent pass. In an implementation of a compiler, portions of one or more phases are combined into a module called pass. 25. List some compiler construction tools? i) Parser generators ii) Scanner generators iii) Syntax-directed translation engine iv) Automatic code generators v) Data-flow engine. 26. Explain any one compiler construction tool? Scanner generators, these automatically generate lexical analyzers normally from a specification based on regular expressions. The resulting of lexical analyzer is in effect of finite automata.

27. What does translator mean? A translator is a program that takes a input program on one programming language (source language) and produces output in another language (object language or target language). 28. What are the two functions of parser? * It checks the tokens appearing in its input, which is output of the lexical analyzer. * It involves grouping the tokens of source program into grammatical phrases that are used by the compiler to synthesize the output. Usually grammatical phrases of the source program are represented by tree like structure called parse tree. 29. What is a language processing system? 16 MARKS 1. Write about the phases of compiler and by assuming an input and show the output of various phases.

The process of compilation is very complex. So it comes out to be customary from the logical as well as implementation point of view to partition the compilation process into several phases. A phase is a logically cohesive operation that takes as input one representation of source program and produces as output another representation. Source program is a stream of characters: E.g. pos = init + rate * 60 lexical analysis: groups characters into non-separable units, called token, and generates token stream: id1 = id2 + id3 * const The information about the identifiers must be stored somewhere (symbol table). Syntax analysis: checks whether the token stream meets the grammatical specification of the language and generates the syntax tree. Semantic analysis: checks whether the program has a meaning (e.g. if pos is a record and init and rate are integers then the assignment does not make a sense). Intermediate code generation, intermediate code is something that is both close to the final machine code and easy to manipulate (for optimization). One example is the threeaddress code: dst = op1 op op2 The three-address code for the assignment statement: temp1 = inttoreal(60); temp2 = id3 * temp1; temp3 = id2 + temp2; id1 = temp3 Code optimization: produces better/semantically equivalent code. temp1 = id3 * 60.0 id1 = id2 + temp1

Code generation: generates assembly code MOVF id3, R2 MULF #60.0, R2 MOVF id2, R1 ADDF R2, R1 MOVF R1, id1 Symbol Table Creation / Maintenance Contains Info (storage, type, scope, args) on Each.Meaningful. Token, typically Identifiers Data Structure Created / Initialized During Lexical Analysis Utilized / Updated During Later Analysis & Synthesis Error Handling Detection of Different Errors Which Correspond to All Phases Each phase should know somehow to deal with error, so that compilation can proceed, to allow further errors to be detected

2. Explain briefly about compiler construction tools. Parser Generators : Produce Syntax Analyzers Scanner Generators : Produce Lexical Analyzers Syntax-directed Translation Engines : Generate Intermediate Code Automatic Code Generators : Generate Actual Code Data-Flow Engines : Support Optimization 3. Explain how abstract stack machines can be used as translators. The front end of a compiler constructs an intermediate representation of source program from which the back end generates the target program. One popular form of intermediate representation is code for an abstract stack machine. Arithmetic instructions L-values and r-values stack manipulation translation of expressions control flow translation of statements emitting a translation 4. Illustrate the compiler internal representation of the changes in the source program, as translation progresses by considering the translation of the statement A:=B+C*50. 5. Write note on front and back end of compiler Grouping of phases. Passes Reducing the no of passes Problems due to grouping of phases 6. Explain Symbol table management and error handling Symbol table Error detection and reporting Error in lexical phase Error in Syntax Analysis phase Error in Semantic Analysis phase 7. Explain cousins of compiler Preprocessors Functions Macro processing, File Inclusion, Rational preprocessors, Language Extensions Macro Definition,

Macro Use Assemblers Assembly code Two Pass Assembly Pass1 Pass2 Loaders and Link Editors Loading, Link Editing External references 8. Describe the following software tools i. Structure Editors ii. Pretty printers iii. Interpreters Structure Editors: Analyses the program text Pretty printers Analyses and prints the program that the structure of the program become clearly visible. Interpreters: Perform operations implied by the source program