Compiler Design Aug 1996

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

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

Question Bank. 10CS63:Compiler Design

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

VALLIAMMAI ENGINEERING COLLEGE

QUESTIONS RELATED TO UNIT I, II And III

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

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

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

GUJARAT TECHNOLOGICAL UNIVERSITY

2068 (I) Attempt all questions.

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

INSTITUTE OF AERONAUTICAL ENGINEERING

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

LECTURE NOTES ON COMPILER DESIGN P a g e 2

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

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

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

CST-402(T): Language Processors

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

BSCS Fall Mid Term Examination December 2012

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

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

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

VIVA QUESTIONS WITH ANSWERS

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

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

Compiler Construction

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

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

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

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY

CS606- compiler instruction Solved MCQS From Midterm Papers

General Overview of Compiler

Compiler Construction

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

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

A simple syntax-directed

VALLIAMMAI ENGINEERING COLLEGE

List of Figures. About the Authors. Acknowledgments


Syntax Analysis Part I

UNIT-III BOTTOM-UP PARSING

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

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

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

A Simple Syntax-Directed Translator

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

4. Lexical and Syntax Analysis

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

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

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

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

Lecture 7: Deterministic Bottom-Up Parsing

UNIT III & IV. Bottom up parsing

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

PRINCIPLES OF COMPILER DESIGN

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

Appendix Set Notation and Concepts

LR Parsing - The Items

Lecture 8: Deterministic Bottom-Up Parsing

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis

4. Lexical and Syntax Analysis

Concepts Introduced in Chapter 4

Midterm I - Solution CS164, Spring 2014

Syntax Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

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

CS5363 Final Review. cs5363 1

Compiler Construction Using

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

Downloaded from Page 1. LR Parsing

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 20th May 2016 Time: 14:00-16:00

CS 314 Principles of Programming Languages. Lecture 3

Front End: Lexical Analysis. The Structure of a Compiler

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

CSE 401 Midterm Exam Sample Solution 2/11/15

CSE 401 Midterm Exam 11/5/10

Final Term Papers 2013

shift-reduce parsing

Context-free grammars

Building Compilers with Phoenix

A programming language requires two major definitions A simple one pass compiler

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Midterm I (Solutions) CS164, Spring 2002

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

S Y N T A X A N A L Y S I S LR

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

Principles of Programming Languages [PLP-2015] Detailed Syllabus

Bottom-up parsing. Bottom-Up Parsing. Recall. Goal: For a grammar G, withstartsymbols, any string α such that S α is called a sentential form

LANGUAGE PROCESSORS. Introduction to Language processor:

Compiler Construction: Parsing

Monday, September 13, Parsers

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


Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 4. Y.N. Srikant

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

CS 314 Principles of Programming Languages

Compiler Design Overview. Compiler Design 1

CSCI312 Principles of Programming Languages!

Transcription:

Aug 1996 Part A 1 a) What are the different phases of a compiler? Explain briefly with the help of a neat diagram. b) For the following Pascal keywords write the state diagram and also write program segments to implement the lexical analyzer for these keywords. 12. BEGIN IF END THEN ELSE 2 a) Write the derivations and parse tree for the string (id + id) * (id + id) using the following grammar. E E + T/T E E * F/T F (E)/id 10. b) Define the term handle. Show how operator precedence relations can be used in recognizing handles. Use an appropriate example. 10. 3 a) For the following grammar compute the FIRST and FOLLOW for each of the nonterminals. E TE E +E/ε T FT T &T/ε F PF F *F/ε P (E)/a/b/ε 12 b) Explain SLR parsing technique with an example. 8. 4 a) Write the three-address codes and quadruples for the following program segments. Assume two bytes are required to store each element of the array. 10. SUM = 0; I : = 0; While I 20 do Begin SUM = SUM + A[I]; I : = I + 1 End; b) Explain with an example the simple translation scheme for an assignment statement. 10. 5 a) Explain with examples the indirection that may be used in the symbol table. 8. b) Explain how scope information is represented by symbol table organization using hash tables. 12. Part - B 6 a) Explain with an example each the different sources of errors. 10. b) Explain how error detection and recovery are done in LL(1) parsing. 10. 7 Consider the following matrix multiplication routine; 20 begin for i : = 1 to n do for j : = 1 to n do Kalpataru Institute of Technology 1

C[i,j] : = 0; for i : = 1 to n do for j : = 1 to n do for k : = 1 to n do C[i,j] : = C[i,j] + A[i,k] * B[k,j] End; i) Assuming A, B and C are allocated static storage and there are two bytes per word in a byte addressable memory, produce the three address codes for the matrix multiplication program. ii) Partition the three address codes into basic blocks iii) Marks the loops in the flow-graph. iv) Move loop invariant computations out of the loop. 8 a) Explain the different Problems involved in code generation. 9. b) Describe the code generation algorithms. 6. c) Describe the functions GETREG( ). 5. February 1997 Part A 1. a) Briefly explain the different phases of a compiler and their functions with a neat diagram b) Construct an NFA for recognizing the following tokens: 1) a(aa)* 2) (a+b)*a convert the NFA to an equivalent DFA and make the token recognized by each state of DFA. 12. 2. a) Explain the following with suitable examples: 9. 1) Bootstrapping 2) Lookahead operator 3) Non-context-free language constructs? b) Remove left recursion for the following grammar and then write recursive descent parser for the same. 11. E E * F F F (E) id 3 a) Briefly explain the working of LL(1) parser. 5. b) For the following grammar calculate LR(0) items. 8. S S S AS c A aa b c) Write SLR (1) parsing table for the grammar in Q. No 3(b) 7. 4 a) Briefly explain the differences between SLR (1), Cononical LR and LALR parsing methods. 8. Incomplete August 1997 Part A 1 a) Explain: 8. 1) Lexical analysis phase. Kalpataru Institute of Technology 2

2) Syntax analysis phase with examples. b) Write transition diagram for recognizing. 12. i) Identifier = letter ( letter/digit ) * ii) Constant = ( + - t ) digit digit * And code for each state of DFA recognizing above tokens. 2 a) construct an NFA and a transition table for DFA, for recognising following tokens. i) 0 ii) 101 iii) 1*0t 12. b) Discuss non-context free language. Construct with an example. 3 3 a) Give operator-precedence-parting algorithm and discuss the same with an example.8 b) Write a recursive descent parser for the grammar. 12. S a ^ (T) T T, S S 4 a) Discuss the working of an LR parser with a neat diagram. 8. b) Construct sets-of-items and deterministic finite automation for the grammar. 12. E E E E + T T T T* F F F id 5 a) Discuss the following Intermediate codes: 8. i) Postfix notation. ii) Syntax trees. iii) Quadruples. iv) Triples. b) Discuss data structures used for symbol tables. 12. Part B 6 a) Discuss. 10. i) Error recovery. ii) Semantic errors. iii) Dynamic errors with examples. b) Discuss error recovery in LR parsing. 10. 7 a) Generate three-address code for the following program fragment. Assume A and B are allocated static storage and four bytes for each elements of A and b. 12. Begin PROD : = 0; I : = 1; do Begin PROD : = PROD + A[I] * B[i]; I : = I + 1; End While I 20 End b) Construct the DAG for the following basic block: 8. 1) D : = B * C 2) E : = A + B 3) B : = B * C 4) G : = A + B 5) A : = E D 6) F : = E * B 7) IF F 10 GOTO (1) Kalpataru Institute of Technology 3

8 a) Write short notes on any four: (5 * 4) i) Code-generation algorithm. ii) Code-notion. iii) Panic node. iv) Global register allocation v) Induction variables. March/April 1998 Part A 1 a) What are compiler writing tools? Explain the principal aids provided by the existing compiler compilers. b) Briefly describe boot strapping. c) Write the state diagram for accepting a decimal real number. Also write the program segments. 2. a) Define a parser. Explain the concepts of top-down and bottom-up parser. 6. b) Explain the stack implementation of shift-reduce parsing. 6. c) Define an operator precedence grammar. Consider the grammar, E => E + E E => E E E => E * E E => E E E => E E E => (E) E => id Construct the operator-precedence relation table assuming the following operator precedence relations. 1) is of highest precedence and right-associative. 2) * and are of next highest precedence and are left-associative. 3 a) Explain the concept of recursive-descent parsing with an example. 8. b) Mention the importance of LR parsers. Write the parsing table and the moves made for the input (id*id) + (id*id) by an L parser based on the following grammar. 12. 4 a) Explain the need of intermediate code. Mention the different types of intermediate code. b) For the following expression write the three address code, quadruples and triples. 9. While A < C and B < D do If A = 1 then C:=C + 1 Else While A <= D do A := A + 2 c) Explain the abstract translation scheme for the translation of assignment statements. 5 a) Explain the need of symbol table in the design of a compiler. 4. b) Briefly describe the operations that are commonly performed and the different information stored in the symbol table. 8. c) With the help of a neat diagram explain how scope information is represented in the symbol table organization of ALGOL. 8. Part B 6 a) Explain the different sources of errors with an example each. 7. b) Explain the concept of minimum distance correction of syntactic errors. 7. c) Explain the recovery in operator precedence parsing. 6. 7 a) Explain the principal sources of code optimization. 6. b) Write three address codes, form basic blocks, draw flow graph, and move the loop invariant code outside the loop. Also assume that four bytes are required to store each element of the array. 8. Min = A[0]; Max = A[0]; Kalpataru Institute of Technology 4

for(i=1;i<n;i++) { if A[i] > Max Max = A[i]; If A[i] < Min Min = A[i]; } c) Write a note on directed acyclic graph. 6 8 a) Describe the different problems of code generation. 6. b) Explain next-use information, register descriptors and address descriptors. 8. c) Write the code sequence generated for the following three address codes. 6. T := A B U := A C V := T + U W := V + U Sept/Oct 1998 Part A 1 a) Explain briefly the phases of a compiler with an example. 10. b) Explain the implementation of lexical analyser with an example. 10. 2 a) Construct non-deterministic finite automata for the given regular expression using Thompson s algorithm. 10. (a/b) * abb. b) Construct DFA using the subset algorithm for the regular expression (a/b)*abb. 10. 3 a) Compute the FIRST and FOLLOW symbols for each of the non-terminals in the grammar given below after eliminating left recursion. 10. E Ε + Τ/Τ T Τ F/F F (E)/id b) Determine the operator precedence relations for the grammar. 10. E E + E E E * E E / E E E (E) E id i) is of highest precedence and right associative. ii) * and / are the next highest precedence and left associative and iii) + and are the lowest precedence and left associative. 4 a) Construct the syntax directed translation scheme that translates arithmetic expression from postfix notation into infix notation. Give annotated parse trees for the input 13 5* and 135*-. 6. b) Translate the arithmetic expression 6. a *-(b + C) into i) A syntax tree. ii) Postfix notation. iii) Three-address code. c) Explain the LR Parsing algorithm with an example. 8. 5 a) Explain the concept of the shift-reduce on input with the sentence id 1 + id 2 * id 3 10. b) Explain briefly the different data structure used for symbol table. 10. Kalpataru Institute of Technology 5

Part B 6 a) Discuss error recovery in operator precedence parsing. Trace out the behavior of the operator precedence LR and LL error-correcting parsers on input. a) (id + (*id)) 8. b) Explain with an example minimum distance correction of syntactic errors. 6. c) Explain briefly the different types of errors encountered in each phase of compiler. 6. 7 a) Generate code for the following C program: main( ) { int i; int a[10]; while(i<=10) a[i]=0; } b) Construct the dag for the following basic block. 6. d = b * c e = a + b b = b * c a = e d c) Explain the need for optimization with at least two examples. 8. 8 Write short notes on the following: (4 x 5) a) Context free grammars. b) Top-down parsing. c) Panic mode recovery. d) Semantic errors. March/April 1999 Part A 1 a) Briefly explain the lexical analysis phase of a compiler and indicate the output for the each of the following statements. i) IF(5.EQ. MAX) GOTO 100 ii) DO 20 I = 1, 10, 2. 10. b) Write transition diagrams for recognising C language reserved words given below; 10. case, char, if, not, struct, switch. 2 a) Explain operator-precedence grammar and construct operator precedence relation matrix for the following operators: 12. / % left to right associativity, highest priority. = right to left associativity. Next highest priority. b) Explain the working of a predictive parser. 8. 3 a) Compute the FIRST and FOLLOW symbols for each of the non-terminals. 12. E TE E +E/ε Τ FT T T/ε F PF F *F/ε P (E) a b e b) Discuss LR parser technique and advantages of LR parsers. 8. 4 a) Show that the following grammar is not SLR (1) type: 10. S L = R S R L *R L iδ R L Kalpataru Institute of Technology 6

b) Clearly bring out the features of following techniques: 10. i) SLR ii) Canonical LR iii) LALR 5 a) Give quadruple, triple representation of the following: 10. i) A[I] : = - B * C * D[j] + E ii) F!= -E * (G + H) b) Explain how scope information is represented in case of ALGOL language. 10. Part B 6 a) Discuss error recovery 9in operator precedence parsing. 8. b) Convert the following program fragment to three-adders code and optimize the same 12. Begin I : = 1; 12 while I <= 10 do Begin C 1 : = 3.14; C 2 : = 180.0; C 3 : = C 1 /C 2 ; X[I] : = X[i] * (3; I : = I + 1; End 7 a) Represent the following using DAG: 12. 1) S 1 : = 2 * I 2) S 2 : = addr(a) 2 3) S 3 : = S 2 [S 1 ] 4) S 4 : = 2 * I 5) S 5 : = addr(b) 2 6) S 6 : = S 5 [S 4 ] 7) S 7 : = S 3 * S 6 8) S 8 : = PROD + S 7 9) PROD : = S 8 10) S 9 : = I + 1 11) I : = S 9 12) IF I <= 20 Goto ( I ) b) Write Function GETREG and describe its use. 8. 8 Write short notes on: i) Code generation algorithm ii) Induction Variables. iii) Basic blocks. iv) Error recovery in LL Parsing. v) Global register allocation. Sept/Oct 1999 Part - A 1 a) Bring out the functions of different phases of a compiler with a diagram. 8. b) Give (i) the parse tree and (ii) the intermdeiate code for the statement: 8. while A > B and a <= 2 * B - 5 do A : = A + B c) Illustruate local optimisation with simple examples. 4. 2 a) Explain the essential requirements of operator precdence grammar with an example. Also, give operator precedence parsing algorithm. 12. b) Construct DFA using the subset algorithm for the regular expression (a/b) * a b b. 8. 3 a) Briefly explain the working of LL(1) parser. 6. b) For the following grammar obtain the canonical collection of sets of LR (0) items. 8. E' -> E E -> E + T T Kalpataru Institute of Technology 7

T -> T * F F F -> (E) / id c) Obtain the SLR table for the grammar of (b) above. 6. 4 a) Construct the syntax directed translation scheme that translates arithmetic expression from postfix notation into infix notation. Give annotated parse trees for the input 2 4-6 * and 2 4 6 * -. 10. b) Explain with an example the simple translation scheme for an assignment statement. 10. 5 a) Explain the meaning of quadruples, triples and indirect pipes with an example. 6. b) What is activated record? Explain the purpose of each item in an activtion record with an example. 6. c) Write a note on the implementation of a simple stack allocation scheme. 8. Part - B 6 a) Explain with an example minimum distance correction of syntactic errors. 6. b) Explain error recovery in operator precedence parser. 8. c) Explain the types of errors likely the occur in different phases of a compiler. 6. 7 a) Discuss the code-generation algorithm with a sequence of quadruples constituting a basic block as input. 6. b) Generate the machine code sequence for the following 3 address - code sequence: 6. T : = A - B U : = A - C V : = T + U W : = V + U c) Explain the DAG representation of basic blocks. Assume a sequence of 3-address code for illustruation. 8. 8 Write explanatory notes on the following: 5x4 = 20 i) Flow graphs ii) Regular expression. iii) Top-down parsing iii) Global register allocation. March/April 2000 Part - A 1 a) Explain the role of Task management in the design of compiler. 10. b) Explain the kind of association, which exists between lexical and syntax analysis phases of compiler. 5 c) Explain the different compiler working tools available. 5. 2 a) How input buffering is implemented in lexical analysis? 5 b) Write rules, which are used, for construction of regular expressions. 5 c) Write algorithm for constructing a DFA from non deterministic one. 10. 3 a) Design DFA for the following NFA using subset construction algorithm. 12. a 2 3 ε ε ε ε ε 0 1 6 7 8 13 c 9 10 14 Kalpataru Institute of Technology 4 5 8 11 12

ε ε ε ε ε ε ε b d ε b) Briefly explain the components of context-free grammar. 8. 4 a) Is the following grammar ambiguous? If yes why? 4. Stat if cond then stat if cond then stat else stat other - stat b) Consider the following grammar: 10. 1) E E + E 2) E E * E 3) E (E) 4) E (id) Trace shift reduce parsing actions using stack during parsing the statement id1 * id2 + id3. c) What is operator grammar? Convert the following grammar into operator grammar. 6 E EAE (E) - E id A + - * / 5 a) Write algorithm for computing operator - precedence relations, assume LEADING(A) and TRAILING(A) for non terminal A are already available. 10. b) Write algorithm to eliminate left recursion from a grammar with no cycles or ε - productions c) Eliminate the left-recursion of the following grammar: E E + T T T T * F F F (E) id Part - B 6 a) Briefly explain: 8. i) Semantic actions ii) Translations on the parse tree by considering suitable e.g. b) Explain different sources of error. 10. c) What is error recovery? 2. 7 a) What are the principal sources of code optimization. 10. b) Generate three-address code for the following program segments. Assume A is an allocated static storage and 2 bytes for each elements of A. 10. begin SUM : = 0; I : = 1; do begin SUM : = SUM + A[I]; I : = I + 1; Kalpataru Institute of Technology 9

end; end while I 15 8 Write short notes on any four: e) DAG ii) Problems in code generation. iii) Minimum distance matching. iv) Quadruples. v) Global register allocation. Kalpataru Institute of Technology 10