GUJARAT TECHNOLOGICAL UNIVERSITY

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

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

GUJARAT TECHNOLOGICAL UNIVERSITY

Question Bank. 10CS63:Compiler Design

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

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

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

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

VALLIAMMAI ENGINEERING COLLEGE

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

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

QUESTIONS RELATED TO UNIT I, II And III

2068 (I) Attempt all questions.

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

Compiler Design Aug 1996

INSTITUTE OF AERONAUTICAL ENGINEERING

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

CST-402(T): Language Processors

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

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

Evaluation Scheme L T P Total Credit Theory Mid Sem Exam

LECTURE NOTES ON COMPILER DESIGN P a g e 2

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

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

Name of chapter & details

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

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

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

VIVA QUESTIONS WITH ANSWERS

VALLIAMMAI ENGINEERING COLLEGE

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

Principles of Programming Languages [PLP-2015] Detailed Syllabus

GUJARAT TECHNOLOGICAL UNIVERSITY

DEPARTMENT OF INFORMATION TECHNOLOGY AUTOMATA AND COMPILER DESIGN. B.Tech-IT, III Year -I Sem

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

CS606- compiler instruction Solved MCQS From Midterm Papers

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

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

GUJARAT TECHNOLOGICAL UNIVERSITY

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

GUJARAT TECHNOLOGICAL UNIVERSITY

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

CSCI 565 Compiler Design and Implementation Spring 2014

Translator Design CRN Course Administration CMSC 4173 Spring 2018

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

Translator Design CRN Course Administration CMSC 4173 Spring 2017

PRINCIPLES OF COMPILER DESIGN

Final Term Papers 2013

Compilers for Modern Architectures Course Syllabus, Spring 2015

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

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

Compiler Design Overview. Compiler Design 1

CS6660 COMPILER DESIGN L T P C

General Overview of Compiler

Compiler Construction

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

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

ECE251 Midterm practice questions, Fall 2010

Life Cycle of Source Program - Compiler Design

Working of the Compilers

LALR Parsing. What Yacc and most compilers employ.

Formal Languages and Compilers Lecture VI: Lexical Analysis

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

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

CS143 Midterm Fall 2008

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

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

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

BSCS Fall Mid Term Examination December 2012

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

COMPILER DESIGN. For COMPUTER SCIENCE

Lecture 7: Deterministic Bottom-Up Parsing

UNIT -2 LEXICAL ANALYSIS

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

CS131: Programming Languages and Compilers. Spring 2017

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

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

Lecture 8: Deterministic Bottom-Up Parsing

CS6660-COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS PART A

CS 406/534 Compiler Construction Putting It All Together

JNTUWORLD. Code No: R

Compiler Construction

CSE 401 Midterm Exam 11/5/10

CS5363 Final Review. cs5363 1

Midterm I (Solutions) CS164, Spring 2002

Principles of Compiler Design Presented by, R.Venkadeshan,M.Tech-IT, Lecturer /CSE Dept, Chettinad College of Engineering &Technology

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

Compiler Construction: Parsing

Compilers. Computer Science 431

HOLY ANGEL UNIVERSITY COLLEGE OF INFORMATION AND COMMUNICATIONS TECHNOLOGY COMPILER THEORY COURSE SYLLABUS

CSCI Compiler Design

Formal Languages and Compilers Lecture I: Introduction to Compilers

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

CS308 Compiler Principles Lexical Analyzer Li Jiang

Automatic Scanning and Parsing using LEX and YACC

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

GUJARAT TECHNOLOGICAL UNIVERSITY

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

Context-free grammars

Transcription:

Type of course: Core GUJARAT TECHNOLOGICAL UNIVERSITY SUBJECT NAME: Compiler Design SUBJECT CODE: 21701 B.E. 7 th SEMESTER Prerequisite: Data Structures and Algorithms, Theory of Computation, Rationale: Compiler Design is a fundamental/core subject of Computer Engineering. It teaches how Compiler of a Programming Language works. It also focuses on various designs of Compiler and structuring and optimizing various phases of a Compiler. It is also necessary to learn types of Grammar, Finite state machines, lex, yacc and related concepts of languages. Teaching and Examination Scheme: Teaching Scheme Credits Examination Marks Total L T P C Theory Marks Practical Marks Marks ESE PA (M) ESE (V) PA (E) PA ALA ESE OEP (I) 4 0 2 6 70 20 10 20 10 20 150 Content: Sr. No. Content Total Hrs % Weightage 1 Overview of the Translation Process, A Simple Compiler, Difference between interpreter, assembler and compiler. Overview and use of linker and loader, types of Compiler, Analysis of the Source Program, The Phases of a Compiler, Cousins of the Compiler, The Grouping of Phases, Lexical Analysis, Hard Coding and Automatic Generation Lexical Analyzers, Front-end and Back-end of compiler, pass structure 2 Lexical Analyzer Introduction to Lexical Analyzer, Input Buffering, Specification of Tokens, Recognition of Tokens, A Language for Specifying Lexical Analyzers, Finite Automata From a Regular Expression, Design of a Lexical Analyzer Generator, Optimization of DFA 3 Parsing Theory Top Down and Bottom up Parsing Algorithms, Top-Down Parsing, Bottom-Up Parsing, Operator-Precedence Parsing, LR Parsers, Using Ambiguous Grammars, Parser Generators, Automatic Generation of Parsers. Syntax-Directed Definitions, Construction of Syntax Trees, Bottom-Up Evaluation of S-Attributed Definitions, L-Attributed Definitions, syntax directed definitions and translation schemes 08 15 08 15 10 22

4 Error Recovery Error Detection & Recovery, Ad-Hoc and Systematic Methods 5 Intermediate Code Generation Different Intermediate Forms, Syntax Directed Translation Mechanisms And Attributed Mechanisms And Attributed Definition. 6 Run Time Memory Management Source Language Issues, Storage Organization, Storage-Allocation Strategies, and Access to Non local Names, Parameter Passing, Symbol Tables, and Language Facilities for Dynamic Storage Allocation, Dynamic Storage Allocation Techniques. 7 Code Optimization Global Data Flow Analysis, A Few Selected Optimizations like Command Sub Expression Removal, Loop Invariant Code Motion, Strength Reduction etc. 8 Code Generation Issues in the Design of a Code Generator, The Target Machine, Run-Time Storage Management, Basic Blocks and Flow Graphs, Next-Use Information, A Simple Code Generator, Register Allocation and Assignment, The DAG Representation of Basic Blocks, Peephole Optimization, Generating Code from DAGs, Dynamic Programming Code-Generation Algorithm, Code- Generator Generators. 06 08 06 10 06 10 06 10 06 10 Suggested Specification table with Marks (Theory): Distribution of Theory Marks R Level U Level A Level N Level E Level C Level 20 20 10 10 5 5 Legends: R: Remembrance; U: Understanding; A: Application, N: Analyze and E: Evaluate C: Create and above Levels (Revised Bloom s Taxonomy) Note: This specification table shall be treated as a general guideline for students and teachers. The actual distribution of marks in the question paper may vary slightly from above table. Reference Books: 1. Compilers: Principles, Techniques and Tools By Aho, Lam, Sethi, and Ullman, Second Edition, Pearson, 2014 2. Compilers: Principles, Techniques and Tools By Aho, Sethi, and Ullman, Addison-Wesley, 1986 3. Compiler Design in C By Allen I. Holub, Prentice-Hall/Pearson. 4. Advanced Compiler Design and Implementation By Muchnick, Morgan and Kaufmann, 1998.

Course Outcome: After learning the course the students should be able to: 1. Understand the basic concepts and application of Compiler Design 2. Apply their basic knowledge Data Structure to design Symbol Table, Lexical Analyser, Intermediate Code Generation, Parser (Top Down and Bottom Up Design) and will able to understand strength of Grammar and Programming Language. 3. Understand various Code optimization Techniques and Error Recovery mechanisms. 4. Understand and Implement a Parser. List of Experiments: 1. Design a lexical analyzer for given language and the lexical analyzer should ignore redundant spaces, tabs and new lines. It should also ignore comments. Although the syntax specification states that identifiers can be arbitrarily long, you may restrict the length to some reasonable value. Simulate the same in C language 2. Write a C program to identify whether a given line is a comment or not 3. Write a C program to test whether a given identifier is valid or not. 4. Write a C program to simulate lexical analyzer for validating operators 5. To Study about Lexical Analyzer Generator(LEX) and Flex(Fast Lexical Analyzer) 6. Implement following programs using Lex. a. Create a Lexer to take input from text file and count no of characters, no. of lines & no. of words. b. Write a Lex program to count number of vowels and consonants in a given input string. 7. Implement following programs using Lex. a. Write a Lex program to print out all numbers from the given file. b. Write a Lex program to printout all HTML tags in file. c. Write a Lex program which adds line numbers to the given file and display the same onto the standard output. 8. Write a Lex program to count the number of comment lines in a given C program. Also eliminate them and copy that program into separate file. 9. Write a C program for implementing the functionalities of predictive parser for the mini language. 10. Write a C program for constructing of LL (1) parsing. 11. Write a C program for constructing recursive descent parsing 12. Write a C program to implement LALR parsing. 13. Write a C program to implement operator precedence parsing. 14. To Study about Yet Another Compiler-Compiler(YACC). 15. Create Yacc and Lex specification files to recognizes arithmetic expressions involving +, -, * and /. 16. Create Yacc and Lex specification files are used to generate a calculator which accepts,integer and float type arguments.

Design based Problems (DP)/Open Ended Problem: Students can do a mini project in C to implement various phases of a Compiler considering a simple set of Instructions and other assumptions. They can also practice on LEX and YACC for various applications involving different Grammars etc. Major Equipment: PC, Unix Server/Client. List of Open Source Software/learning website: 1. nptel.ac.in 2. https://en.wikipedia.org/wiki/principles_of_compiler_design 3. https://en.wikipedia.org/wiki/compiler_construction ACTIVE LEARNING ASSIGNMENTS: Preparation of power-point slides, which include videos, animations, pictures, graphics for better understanding theory and practical work The faculty will allocate chapters/ parts of chapters to groups of students so that the entire syllabus to be covered. The power-point slides should be put up on the web-site of the College/ Institute, along with the names of the students of the group, the name of the faculty, Department and College on the first slide. The best three works should submit to GTU.

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII (NEW) - EXAMINATION SUMMER 2017 Subject Code: 21701 Date: 29/04/2017 Subject Name: Complier Design Time: 02.30 PM to 05.00 PM Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) Explain Semantic analysis and Syntax analysis phases of compiler with suitable example. Also explain the errors generated by these two phases. (b) Construct the NFA using thompson s notation for following regular expression and then convert it to DFA. (a / b)* ab# Q.2 (a) Check following grammar is LL (1) or not? S -> ab B -> bc C -> cs (b) What is left factoring and left recursion? Explain it with suitable example. (b) Construct CLR parsing table for following grammar. S -> asa A -> bs c Q.3 (a) Show that following grammar is not a SLR (1) grammar. S -> AaBa BbBa A -> B -> (b) Develop a syntax directed definition for following grammar. E -> TE E -> +TE T -> ( E ) T -> id Q.3 (a) Write a grammar to declare variables with data type int or float or char. Also develop a syntax directed definition for that. Draw the dependency graph for same. (b) Define operator precedence grammar. Construct precedence matrix and precedence graph for arithmetic grammar as shown below: E -> E + T T T -> T * F F F -> (E) id Q.4 (a) Explain Activation record and Activation tree in brief. (b) Explain Quadruple, triple, and indirect triple with suitable example. Q.4 (a) Write a note on peephole optimization. (b) Write a short note on symbol table management. Q.5 (a) Define a following: Basic block, Constant folding, Natural loop, Handle 1

(b) Construct DAG for a + a * (b- c) + (b c) * d. also generate three address code for same. Q.5 (a) Discuss the issues in the design of code generation. (b) Define dominators. Construct dominator tree for following graph. ************* 2

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII (OLD) - EXAMINATION SUMMER 2017 Subject Code: 1701 Date: 09/05/2017 Subject Name: Compiler Design Time: 02:30 PM to 05:00 PM Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) Explain various phases of compiler with example. (b) Explain input buffering methods. Q.2 (a) Explain symbol table with two data structures suitable for it. (b) Construct a DFA without constructing NFA for the following regular expression. (a b) * a (b) Explain subset construction method with an example. Q.3 (a) Explain SLR parsing method with an example. (b) How do you check whether the grammar is LL (1) or not? Justify your answer with appropriate example. Q.3 (a) Explain operator precedence parsing method. (b) Check the following grammar is LR(1) or not. S AaAb S BbBa A B Q.4 (a) Discuss differences between inherited attributes and synthesized attributes. (b) Write a short note on various representations of three address code. Q.4 (a) Explain syntax directed translation scheme with example. (b) Define: DAG. Explain DAG representation of basic block with example. Q.5 (a) Discuss various code optimization methods. (b) Explain code generator design issues. Q.5 (a) Explain static storage allocation technique. (b) Explain activation record organization in brief. ************* 1

Seat No.: No. Enrolment GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII(OLD) EXAMINATION WINTER 2016 Subject Code: 1701 Date: 29/11/2016 Subject Name: Compiler Design Time: 10:30 AM to 01:00 PM Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) Describe all phases of a compiler. (b) (i) What is a symbol table? Discuss the most suitable data structure for it by stating merits / demerits. (ii) Explain linker & loader. Q.2 (a) (i) Consider the grammar S -> SS+ SS* a Show that the string aa+a* can be generated by the grammar. Construct the parse tree for the grammar. Is the grammar ambiguous? (ii) Write unambiguous production rules for if then else construct. (b) Construct DFA without constructing NFA for following regular expression: a*b*a(a b)b*a# Minimize the same. (b) Construct NFA for following regular expression using Thompson s notation and then convert it into DFA. a(b c)*a*c# Q.3 (a) Apply shift reduce parser for parsing following string using unambiguous grammar. id - id * id - id (b) (i) Compare top-down and bottom-up parser. (ii) Explain right-most-derivation-in-reverse with the help of an example. Q.3 (a) Explain SLR parser. How is its parse table constructed? (b) Construct a precedence graph, precedence table for operator precedence parser to be used for parsing a string consisting of id, -, *, $. Parse following string. $ id - id * id * id $ Q.4 (a) Write production and semantic rules for producing and analyzing statements like : int * ip, i, j, *ip1; float * fp, f; (b) Explain synthesized attributes with the help of an example. Q.4 (a) Draw transition diagrams corresponding to production rules for arithmetic expressions consisting of operators + and ^ for predictive parser. Explain how parsing takes place for the same using transition diagrams. (b) (i) Explain various parameter passing methods. (ii) Explain left factoring with the help of an example. 1

Q.5 (a) Draw syntax tree and DAG for following statement. Write three address codes from both. a = (a + b * c) ^ (b * c) + b * c ^ a ; (b) Explain activation record. How is task divided between calling & called program for stack updating? Q.5 (a) For a statement given below, write output of all phases (except that of optimization phase) of a complier. a = a + b * c ; (b) Explain peephole optimization. ************* 2

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII EXAMINATION SUMMER 2016 Subject Code:1701 Date:16/05/2016 Subject Name:Compiler Design Time:02:30 PM to 05:00 PM Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) Explain different phases of compiler. (b) What is regular expression, give all the algebraic properties of regular expression. Q.2 (a) Draw the DFA for the regular expression (a b)*abb using set construction method only. (b) Unsigned numbers are strings such as 5280, 39.37, 6.336E4 or 1.894E-4, give the regular definitions for the above mentioned strings. (b) Draw the state transition diagram for the unsigned numbers. Q.3 (a) Convert the (a b c)*d*(a* b)ac + # regular expression to DFA directly and draw its DFA. (b) Write short note on context free grammar (CFG) explain it using suitable example. Q.3 (a) Explain all error recovery strategies using suitable examples. (b) Where do we use operator precedence parsing technique? Give the general precedence table for operating precedence parsing, considering all the generalized rules. Q.4 (a) What is left recursion? Eliminate the left recursion from the following grammar. E E + T T T T * F F F ( E ) id (b) Translate the expression (a*b)+(c*d)+(a*b*c) into 1. Quadruples 2. Triples 3. Indirect triples. Q.4 (a) Explain SLR parser in detail with the help of a suitable example. (b) Design the FIRST SET and FOLLOW SET for the following grammar. E E + T T T T * F F F ( E ) id Q.5 (a) Explain how type checking & error reporting is performed in compiler. Draw syntax tree and DAG for the statement a = (a * b + c) ^ (b + c) * b + c. Write three address codes from both. (b) Explain peephole optimization. 1

Q.5 (a) Differentiate SLR, Canonical LR and LALR. Also justify the statement A class of grammar that can be parsed using LR methods is a proper subset of the class of grammars that can be parsed with predictive parser (b) What is an activation record? Explain how they are used to access local and global variables. ************* 2

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII EXAMINATION WINTER 2015 Subject Code: 1701 Date: 12/12/2015 Subject Name: Compiler Design Time: 10:30am to 1:00pm Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) Define lexeme, token and pattern. Identify the lexemes that make up the tokens in the following program segment. Indicate corresponding token and pattern. void swap (int a, int b) { int k; k = a; a = b; b = k; } (b) Explain Semantic Analysis and Syntax Analysis phases of compiler with suitable example. Also explain the reporting errors by these two phases. Q.2 (a) Write a short note on Symbol Table Management. (b) Construct DFA for following Regular expression. Use firstpos, lastpos and followpos functions to construct DFA. ( a * b * ) * (b) Construct NFA for following Regular Expression using Thomson s Construction. Apply subset construction method to convert into DFA. (a b)*abb Q.3 (a) Construct LL(1) parsing table for the following Grammar: S ( L ) a L L, S S (b) Check whether the following grammar is CLR or not. S Aa bac Bc bba A d B d 1

Q.3 (a) Define: Left Recursive. State the rule to remove left recursive from the grammar. Eliminate left recursive from following grammar. S Aa b A Ac Sd f (b) Construct SLR Parsing Table for the following grammar. S 0S0 1S1 10 Q.4 (a) Explain Operator Precedence Parsing method with example. (b) Show syntax directed definition for simple desk calculator. Also show annotated parse tree for 3*5+4n, where n indicates newline. Q.4 (a) Explain LALR parser in detail. Support your answer with example. (b) Give the translation scheme that converts infix to postfix expression for the following grammar and also generate the annotated parse tree for input string 7+3+2. E E+T E T T 0 1 2 3 4 5 6 7 8 9 Q.5 (a) Translate following arithmetic expression - ( a * b ) + ( c + d ) - ( a + b + c + d ) into 1] Quadruples 2] Triple 3] Indirect Triple (b) Explain various dynamic storage allocation techniques. Q.5 (a) Explain any three code optimization techniques with example. (b) Explain various issues in design of code generator. ************* 2

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII EXAMINATION SUMMER 2015 Subject code: 1701 Date: 01/05/2015 Subject Name: Compiler Design Time: 02.30pm-05.00pm Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) What are regular expressions? Find the regular expression described by DFA {{A,B},{0,1},δ,A,{B}},where δ is detailed in following table. 0 1 A A B B φ A Please note B is accepting state. Describe the language defined by the regular expression. (b) Construct the NFA using thompson s notation for following regular expression and then convert it to DFA. a + (c d) b * f # Q.2 (a) List the errors generated by the syntax analysis phase. Discuss error handling methods in the syntax analysis phase. (b) For the following grammar D T L ; L L, id id T int float 1)Remove left recursion (if required) 2)Find first and follow for each non terminal for Resultant grammar 3)Construct LL(1) parsing table 4)Parse the following string (show stack actions clearly) and draw parse tree for the input: int id, id; (b) How top down and bottom up parser will parse the string bbd using grammar A ba d. Show all steps clearly. 1

Q.3 (a) Explain the phases of compiler with an example. (b) Construct the collection of sets of LR(0) items for the following grammar. S-> Aa bac dc bda A->d Q.3 (a) Construct DFA by syntax tree construction method. a + b * (c d) f # Optimize the resultant DFA. (b) Develop a predictive parser for the following grammar. S ->S S->aA b cb d A->aA b B->cB d Q.4 (a) Explain the following: 1) The Handle 2) Left Factoring 3) Directed Acyclic Graph 4) Conflicts in LR Parsing 5) Parser Generator 6) Dependency Graph 7) Locality of reference (b) Construct an SLR Parsing table for the following grammar. E->E-T T T->F T F F->(E) id Q.4 (a) Elaborate the term Activation Record in detail. (b) Discuss various code optimization techniques. Q.5 (a) Write a context free grammar for arithmetic expressions. Develop a syntax directed definition for the grammar. Draw an annotated parse tree for the input expression: (3*2+2)*4 (b) Convert the following statement into triple, indirect triple and quadruple forms. A= (B+C) $ E + (B+C) *F Q.5 (a) Discuss synthesized and inherited attributes using a suitable grammar. (b) What is intermediate code? What is its importance? Discuss various representations of three address code. ************* 2

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII EXAMINATION WINTER 2014 Subject Code: 1701 Date: 25-11-2014 Subject Name: Compiler Design Time: 10:30 am - 01:00 pm Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) Explain Buffer pairs and Sentinels. (b) Draw Transition diagram of following: i. relational operators. ii. unsigned operator. Q.2 (a) Explain recursive-descent and predictive parsing. (b) Construct minimum state DFA s for following regular expressions. i. (a b)*a(a b) ii. (a b)*a(a b) (a b) (b) What do you understand by a handle? Explain the stack implementation of shift reduce parser with the help of example. Q.3 (a) Show that the following grammer S-> AaAb BbBa A -> ϵ B -> ϵ is LL(1) but not SLR(1). (b) Show that the following grammer S->Aa bac dc bda A->d is LALR(1) but not SLR(1). Q.3 (a) Show that the following grammer S->Aa bac Bc bba A->d B->d is LR(1) but not LALR(1). (b) Explain various error recovery strategy of compilers Q.4 (a) Construct a Syntax-Directed Translation scheme that translates arithmetic expressions from intfix into postfix notation. Show the application of your scheme to the string 3*4+5*2. (b) What is the use of a symbol table? How identifiers are stored in the symbol table? Q.4 (a) Explain quadruple, triple and indirecttriple with suitable example. (b) Explain with an appropriate example how to perform bottom up evaluation of an inherited attributes. Q.5 (a) Explain various code optimization technique. (b) Describe algorithm for global common subexpression elimination. Q.5 (a) Explain code generator design issues. (b) Explain Stack allocation and Activation record organization in brief. ************* 1

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII EXAMINATION SUMMER 2014 Subject Code: 1701 Date: 22-05-2014 Subject Name: Compiler Design Time: 02:30 pm - 05:00 pm Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) What is the pass of a compiler? Explain how the single and multi-pass compilers work. (b) Draw Deterministic Finite Automata for : 1. (0+1)*101(0+1)* 2. 10(0+1)*1 Q.2 (a) List out phases of a compiles. Write a brief not on Lexical Analyzer. 06 (b) Implement the following grammar using Table Driven parser and check whether it is 08 LL(1) or not. S -> abdh, B -> cc, C -> bc / ^, D -> EF, E -> g / ^, F-> f / ^ (b) Implement the following grammar using Recursive Descent Parser. S -> Aa bac bba, A -> d, B -> d 08 Q.3 (a) What is bottom-up parsing? Discuss Shift Reduce parsing technique in brief. What is a handle? 08 (b) Write a syntax directed definition of a simple desk calculator and draw an annotated parse tree for 4*3 + 2*5 n. 06 Q.3 (a) Define an Operator Precedence Grammar. Also write down the rules to find relationship between each pair of terminal symbols. 08 (b) Convert the following into quadruple, triple and indirect triple forms : -(a+b)*(c-d). 06 Q.4 (a) Construct SLR parsing table for the following grammar : E->E+T E->T T->T*F T->F F->(E) F->a (b) Differentiate Synthesized and Inherited attributes. 04 Q.4 (a) Error Recovery strategies of compiler. (b) What is the use of a symbol table? How the identifiers are stored in the symbol table? Q.5 (a) Write a note on peephole optimization. (b) Write a note on static and dynamic memory allocation. What do you mean by dangling reference? Q.5 (a) What is an activation record? Explain how they are used to access various local and global variables. (b) Write a brief note on input buffering techniques. ************* 10 1

Seat No.: Enrolment No. GUJARAT TECHNOLOGICAL UNIVERSITY BE - SEMESTER VII EXAMINATION WINTER 2013 Subject Code: 1701 Date: 26-11-2013 Subject Name: Compiler Design Time: 10.30 am - 01.00 pm Total Marks: 70 Instructions: 1. Attempt all questions. 2. Make suitable assumptions wherever necessary. 3. Figures to the right indicate full marks. Q.1 (a) Draw structure of Compiler. Also explain Analysis Phase in brief. (b) Draw Deterministic Finite Automata for the binary strings ending with 10. 04 (c) Write down the algorithm for left factoring. 03 Q.2 (a) Write a brief note on input buffering techniques to Lexical Analyzer. (b) Write down C program for Recursive Descend Parser for : S ABC B 1B A 0A1 C 1C0 Q.2 (a) Explain Shift-Reduce parsing with suitable example. (b) Draw parsing table for Table Driven Parser for the given grammar. Is the grammar LL(1)? A AaB x B BCb Cy C Cc Q.3 (a) What is Inherited attribute? Explain with suitable example. 06 (b) Write down steps to set precedence relationship for Operator Precedence Grammar. Design precedence table for: 08 E E+ T T T T * F F F a Q.3 (a) Explain how panic mode recovery can be implemented. (b) What is the difference between parse tree and syntax tree? Write appropriate grammar and draw parse as well as syntax tree for a*(a-a^a) Q.4 (a) Write SLR parsing table for : S T T CC C cc C d 08 (b) Explain Stack Allocation and Activation Record Organization in brief. 06 Q.4 (a) Write a note on Peephole Optimization. 08 (b) Explain quadruple, triple and indirect triple with suitable example 06 Q.5 (a) Explain the roles of linker, loader and preprocessor. 08 (b) Differentiate: static v/s dynamic memory allocations. 03 (c) Write down the regular expression for the binary strings with even length. 03 Q.5 (a) Discuss generic issues in the design of code generation. (b) Write down the algorithm for partitioning of basic blocks. ************* 1