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

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

GUJARAT TECHNOLOGICAL UNIVERSITY

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

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

Question Bank. 10CS63:Compiler Design

QUESTIONS RELATED TO UNIT I, II And III

VALLIAMMAI ENGINEERING COLLEGE

2068 (I) Attempt all questions.

Compiler Design Aug 1996

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

INSTITUTE OF AERONAUTICAL ENGINEERING

DEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING UNIT -1-INTRODUCTION TO COMPILERS 2 MARK QUESTIONS

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

VIVA QUESTIONS WITH ANSWERS

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.

1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]

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

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

SYLLABUS UNIT - I UNIT - II UNIT - III UNIT - IV CHAPTER - 1 : INTRODUCTION CHAPTER - 4 : SYNTAX AX-DIRECTED TRANSLATION TION CHAPTER - 7 : STORA

LECTURE NOTES ON COMPILER DESIGN P a g e 2

VALLIAMMAI ENGINEERING COLLEGE

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

PRINCIPLES OF COMPILER DESIGN

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

CST-402(T): Language Processors

Roll No. :... Invigilator's Signature :. CS/B.Tech(CSE)/SEM-7/CS-701/ LANGUAGE PROCESSOR. Time Allotted : 3 Hours Full Marks : 70

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTER SCIENCE AND ENGINEERING COURSE PLAN

GUJARAT TECHNOLOGICAL UNIVERSITY

General Overview of Compiler

CS6660-COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS PART A

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

Torben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer


VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

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

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

Principles of Programming Languages [PLP-2015] Detailed Syllabus

CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points.

CS606- compiler instruction Solved MCQS From Midterm Papers

UNIT IV INTERMEDIATE CODE GENERATION

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

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

University of Technology Department of Computer Sciences. Final Examination st Term. Subject:Compilers Design

Syntax Analysis Part I

BSCS Fall Mid Term Examination December 2012

Compiler Construction

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

Compiler Construction

CSE 401 Midterm Exam 11/5/10

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

List of Figures. About the Authors. Acknowledgments

Introduction to Syntax Analysis

LALR Parsing. What Yacc and most compilers employ.

UNIT I INTRODUCTION TO COMPILING

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

Let us construct the LR(1) items for the grammar given below to construct the LALR parsing table.

CS5363 Final Review. cs5363 1

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters

Introduction to Syntax Analysis. The Second Phase of Front-End

Compilerconstructie. najaar Rudy van Vliet kamer 140 Snellius, tel rvvliet(at)liacs(dot)nl. college 3, vrijdag 22 september 2017

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

CMSC 330: Organization of Programming Languages

Compiler Construction

CSE 401 Midterm Exam Sample Solution 11/4/11

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

Formal Languages and Compilers Lecture VI: Lexical Analysis

UNIT-III BOTTOM-UP PARSING

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN

COP 3402 Systems Software Syntax Analysis (Parser)

4. An interpreter is a program that

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

DADI INSTITUTE OF ENGINEERING & TECHNOLOGY (Approved by A.I.C.T.E., New Delhi & Affiliated to JNTUK, Kakinada)

CSE 401 Midterm Exam Sample Solution 2/11/15

UNIT III. The following section deals with the compilation procedure of any program.

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

UNIT III & IV. Bottom up parsing

Compiler Construction: Parsing

KALASALINGAM UNIVERSITY ANAND NAGAR, KRISHNAN KOIL DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING ODD SEMESTER COURSE PLAN

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

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

COMPILER DESIGN. For COMPUTER SCIENCE

Parsing Wrapup. Roadmap (Where are we?) Last lecture Shift-reduce parser LR(1) parsing. This lecture LR(1) parsing

JNTUWORLD. Code No: R

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Midterm I (Solutions) CS164, Spring 2002

Theory and Compiling COMP360

Working of the Compilers

LR Parsing Techniques

Context-free grammars

CMSC 330: Organization of Programming Languages

Transcription:

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov 2014 Compiler Design (170701) Question Bank / Assignment Unit 1: INTRODUCTION TO COMPILING 1. What is a compiler? Explain the various phases of compiler in detail, with a neat sketch. 2. What is a pass in a compiler? What is the effect of reducing the number of passes? 3. Explain the analysis synthesis model of compilation. List the factors that affect the design of compiler. Also List major functions done by compiler. 4. Find the Regular Expression corresponding to given statement, subset of {0,1}* a. The Language of all strings containing at least one 0 and at least one. b. The Language of all strings containing 0 s and 1 s both are even. c. The Language of all strings containing at most one pair of consecutive 1 s. d. The Language of all strings that do not end with 01. 5. What does the linker do? What does the loader do? What does the preprocess do? Explain their role(s) in compilation process. 6. Find errors and identify the phase of compiler detecting them for following C program segment. Justify your answers. int fi( int); char a[10], * cptr; int k = 1 ; int j = 2; float f; cptr = a; if (k); fi(k); fi( j ) ++k; *(cptr + 1 ) = 0 ; ++ a; n + *k ; 7. What is a symbol table? Discuss any two data structures suitable for it & compare their merits / demerits. Also compare one pass & two pass compilers. 8. Define compiler,interpreter,tokens, Patterns and lexemes,symbol table. 9. What are the possible error recovery actions in lexical Analyzer? 10. What are the three general approaches to the implementation of a Lexical Analyzer?

11. Describe briefly rational preprocessors with an example. 12. What are the reasons for separating the analysis phase of compiling into Lexical analysis and parsing? 13. Give the diagrammatic representation of a language processing system. 14. Explain briefly the producer consumer pair of a lexical analyzer and parser. 15. Mention the issues in a lexical analyzer and some of the cousins of the compiler. Unit 2: LEXICAL ANALYZER 1. Write a regular definition for the language of all strings of 0 s and 1 s with an even number of 0 s and odd number of 1 s. 2. Convert the following regular expression into deterministic finite automata. (a+b)*abb(a+b)* 3. Write the two methods used in lexical analyzer for buffering the input. Which technique is used for speeding up the lexical analyzer? 4. Convert the following NFA-^into equivalent NFA. Here ε is a ^-transition 5. Construct a DFA for a given regular expression (010+00)*(10)* 6. How do the parser and scanner communicate? Explain with the block diagram communication between them. Also explain: What is input buffering? 7. What is the difference between parse tree and syntax tree? Draw the parse tree for following expression: a= a + a * b + a * b * c a / b + a * b and write three address code for it. 8. Perform the Left factoring of following Grammar A ad a ab abc b 9. (a) Left factor the following grammar: E-> int int + E int - E E -(E) (b) Eliminate left-recursion from the following grammar: A -> A + B B B ->int (A) 10. Explain: Error Recovery Strategies in Compiler in brief 11. Explain lexical analysis phase of a compiler and, for a statement given below, write output of all phases (except of an optimization phase) of a complier. Assume a, b and c of type float a = a + b * c * 2;

12. Construct a DFA without constructing NFA for following regular expression. Find minimized DFA. a*b*a(a b)*b*a# 13. Construct a NFA for following regular expression using Thompson s notation and then convert it into DFA. aa*(b c) a*c# 14. Describe language denoted by the following regular expression:0(0/1)*0, (0/1)*0(0/1)(0/1),(00/11)*((01/10)(00/11)*(01/10)(01/10)(00/11)*)*, : 0*a0*a0*a0* 15. Write the regular definition for the following language: "All strings of digits with no repeated digits". 16. Give an example for ambiguous grammar and justify it. 17. Write regular definition for a number which can have fraction or exponent part as optional. 18. For the following grammar: list --> list+digit / list-digit / digit digit --> 0/1/.../9 Derive the sentence (9+5-4) using left-most derivation. 19. Write the algorithm for moving forward pointer in "input buffering" scheme using sentinels. Unit 3:PARSING THEORY 1. How can panic mode and phrase level recovery be implemented in LR parsers? 2. Explain how type checking & error reporting is performed in a compiler. 3. Consider the expression grammar. E E + E E * E (E) id 4. Prepare the SLR parsing table with error detection and recovery routines. 5. Write an algorithm for eliminating left recursion. 6. Is the following grammar suitable for LL(1) parsing? If not make it suitable for LL(1) parsing. Compute FIRST and FOLLOW sets. Generate the parsing table. S AB A Ca ϵ B BaAC c C b ϵ 7. Compute the operator precedence matrix and precedence function for the following grammar if it exists. +,*,-,/,id,num,( and ) are terminal symbols. G E E E+T E-T T T T*F T/F/F F num id (E) 8. Consider the following grammar E E+T T T TF F F F* a b

1) Construct the SLR parsing table for this grammar. 2) Construct the LALR parsing table. 9. Construct predictive parsing table for following. S -> A A -> ab Ad B -> bbc f C -> g 10. Eliminate left recursion from the following grammar and rewrite the Grammar. S -> Aa b A -> Ac Sd ε 11. Find out FIRST & FOLLOW set for all the Non-terminals S AcB cbb Ba A da BC B g ε C h ε 12. Explain non-recursive predictive parsers. Draw the block diagram of it. 13. Eliminate left recursion from the following grammar A->Ac/Aad/bd/c. 14. Test whether the following grammar is LL (1) or not. Construct predictive parsing table for it. S 1AB ε A 1AC 0C B 0S C 1 15. Construct the canonical parsing table for the following Grammar S S S CC C cc d 16. Generate the SLR parsing table for the following Grammar S Aa bac bba A d B d 17. Write unambiguous grammar for producing arithmetic expression consisting of symbols id, +, -, /, $. Find first & follow of non terminal symbols of the grammar for non recursive predictive parser. Construct parse table and parse following string. id - id + id - id $ 18. Consider the grammar S -> SS+ SS* a 19. Show that the string aa+a* can be generated by the grammar. 20. Construct the parse tree for it. Is the grammar ambiguous? Justify. 21. Write unambiguous production rules for producing arithmetic expression consisting of symbols id, *, -, ( ) and ^, where ^ represents exponent. Parse following string using shift reduce parser: id id * id ^ id * (id ^ id ) ^ id 22. Explain various conflicts of a shift reduce parser.

23. A robot is to be moved to a unit step in a direction specified as a command given to it. The robot moves in the direction North, South, East, West on receiving N, S, E, W command respectively & in the direction North-East, North-West, South-East, South-West on receiving A, B, C, D commands respectively. The current position of the robot is initialized to (0,0) Cartesian coordinates on receiving command Start. Write production rules for producing sequence of commands and semantic rules for knowing position of a robot after receiving a sequence of commands. Draw annotated parse tree for following sequence: Start N N A A C C N 24. Explain SLR parser in detail with the help of an example. 25. Draw transition diagrams corresponding to production rules for operators +, -, *, / and id for a predictive parser. Explain how parsing takes place for it. 26. Explain operator precedence parser by giving example for constructing a precedence graph and table. 27. Write ambiguous and unambiguous production rules for if then else construct. Illustrate parsing using both types of rules by giving an example. Also explain left factoring and its use. 28. What do you mean by Handle Pruning? 29. Define LR (0) items, viable prefixes,handle. 30. What is phrase level error recovery? 31. Construct Predictive Parsing table for the following grammar: S -> (L)/ a L -> L, S/S and check whether the following sentences belong to that grammar or not. (i) (a,a) (ii) (a, (a, a)) (iii) (a,((a,a),(a,a))) 32. Check whether the following grammar is SLR (1) or not. Explain your answer with reasons. S-> L+R S->R L->*R L->id R->L 33. For the grammar given below, calculate the operator precedence relation and the precedence functions. E->E+E E E E*E E/E E^E (E) E id 34. Check whether the following grammar is a LL(1) grammar S -> iets ietses a E-> b Also define the FIRST and FOLLOW. 35. Explain LALR parsing, justify how it is efficient over SLR parsing. 36. Draw the transition diagrams for predictive parsers for the following grammar. E TE E +TE ϵ T FT T *FT ϵ F (E) id

Unit 5:INTERMEDIATE CODE GENERATION 1. What is attributed grammar? Which phase of the compilation process does it facilitate? Explain with example. 2. Write syntax directed Defination for translating following grammar for postfix notation. Also draw annotated parse tree for 9-5+2. expr -> expr + term expr -> expr term term -> 0 1.. 9 3. Write a syntax directed definition for desk calculator. Justify whether this is an S-attributed definition or L-attributed definition. Using this definition draw annotated parse tree for 3*5+4n. 4. What is inherited attribute? Write syntax directed definition with inherited attributes for type declaration for list of identifiers. Show annotated parse tree for the sentence real id1,id2,id3. 5. What is Intermediate form of the code? What are the advantages of it? What are generally used intermediate forms? Write N-Tuple notation for: (a+b)*(c+d)-(a+b+c) 6. Give the Syntax directed definition of if else statement. 7. What are the various methods of implementing three address statements? 8. How would you generate the intermediate code for the flow of control statements? Explain with example. 9. What is back patching? 10. Translate the expression (a+b)*(c+d)+(a+b+c) into 1. Quadruples 2. Triples 3. Indirect triples 11. Convert the exp into three address code & Quadruple. S=(a+b)/(c-d)*(e+f) 12. Translate the arithmetic expression a*-(b+c) into 1. Syntax tree 2. Postfix notation 3. Three address code Unit 6:. RUN TIME MEMORY MANAGEMENT 1. Suggest a Suitable approach for completing hash function 2. Explain activation tree and control stack. 3. What are the limitations of static storage allocation? Explain the problem of dangling references. 4. For what purpose compiler uses symbol table? How characters of a name are stored in symbol table?

5. Explain the static scope rule and dynamic scope rule. 6. Explain the structure of an activation record with all its components 7. Explain: Symbol Table Management. How symbol table differs from other data structures? 8. Compare: Static v/s Dynamic Memory Allocation 9. Explain activation record. How is task divided between calling & called program for stack updating? 10. Explain various parameter passing methods. 11. Explain heap, dynamic storage allocation techniques and synthesized attributes 12. How Back patching can be used the generate code for Boolean expressions and flow of control statements. Unit 7: CODE OPTIMIZATION 1. Why are quadruples preferred over triples in an optimizing Complier? 2. Write an algorithm for global common subexpression elimination. 3. Explain peephole optimization. 4. Explain any three types of optimization techniques. Unit 8: CODE GENERATION 1. Write the generic issues in the design of code generators 2. Discuss the factors affecting the target code generation. 3. What are the applications of DAG? 4. How would you represent the following equation using the DAG, a. a: =b*c + b*c. What is the purpose of DAG? 5. Draw syntax tree and DAG for following statement. Write three address codes from both. 6. a = (a + b * c) ^ (b * c) + b * c -----------------------------------------------------------------------------------------------------------------