BSCS Fall Mid Term Examination December 2012

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

2068 (I) Attempt all questions.

Top down vs. bottom up parsing

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

Compiler Design Aug 1996

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

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

ECE251 Midterm practice questions, Fall 2010

8 Parsing. Parsing. Top Down Parsing Methods. Parsing complexity. Top down vs. bottom up parsing. Top down vs. bottom up parsing

Question Marks 1 /12 2 /6 3 /14 4 /8 5 /5 6 /16 7 /34 8 /25 Total /120

Parsing. Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1)

Syntax Analysis Part I

Midterm I - Solution CS164, Spring 2014

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

CS143 Midterm Fall 2008

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

Lecture Bottom-Up Parsing

QUESTIONS RELATED TO UNIT I, II And III

Question Bank. 10CS63:Compiler Design

Derivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012

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

UNIVERSITY OF CALIFORNIA

ECE 468/573 Midterm 1 September 30, 2015

INSTITUTE OF AERONAUTICAL ENGINEERING

CS 406/534 Compiler Construction Putting It All Together

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

Page No 1 (Please look at the next page )

Example CFG. Lectures 16 & 17 Bottom-Up Parsing. LL(1) Predictor Table Review. Stacks in LR Parsing 1. Sʹ " S. 2. S " AyB. 3. A " ab. 4.

CMSC 330: Organization of Programming Languages

Chapter 3: Lexing and Parsing

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised:

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

Recursive Descent Parsers

Table-Driven Parsing

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

LR Parsing - The Items

COL728 Minor1 Exam Compiler Design Sem II, Answer all 5 questions Max. Marks: 20

CS606- compiler instruction Solved MCQS From Midterm Papers

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

CS502: Compilers & Programming Systems

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

CS5363 Final Review. cs5363 1

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

Lecture 7: Deterministic Bottom-Up Parsing

Chapter 4. Lexical and Syntax Analysis. Topics. Compilation. Language Implementation. Issues in Lexical and Syntax Analysis.

ECE 468/573 Midterm 1 October 1, 2014

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

GUJARAT TECHNOLOGICAL UNIVERSITY

COP4020 Programming Languages. Syntax Prof. Robert van Engelen

Introduction to Lexing and Parsing

CSE302: Compiler Design

General Overview of Compiler

1. Consider the following program in a PCAT-like language.

Lecture 8: Deterministic Bottom-Up Parsing

CMSC 330: Organization of Programming Languages

CT32 COMPUTER NETWORKS DEC 2015

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6

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

Compilers. Predictive Parsing. Alex Aiken

CSE 401 Midterm Exam Sample Solution 2/11/15

Syntax Analysis. Prof. James L. Frankel Harvard University. Version of 6:43 PM 6-Feb-2018 Copyright 2018, 2015 James L. Frankel. All rights reserved.

CS308 Compiler Principles Syntax Analyzer Li Jiang

CMSC 330: Organization of Programming Languages

Compilers. Computer Science 431

Midterm I (Solutions) CS164, Spring 2002

Introduction to Syntax Analysis

Topic 3: Syntax Analysis I

Review. Pat Morin COMP 3002

CS453 : Shift Reduce Parsing Unambiguous Grammars LR(0) and SLR Parse Tables by Wim Bohm and Michelle Strout. CS453 Shift-reduce Parsing 1

CS143 Handout 20 Summer 2012 July 18 th, 2012 Practice CS143 Midterm Exam. (signed)

Bottom-Up Parsing. Lecture 11-12

Bottom-Up Parsing. Lecture 11-12

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

CMSC 330: Organization of Programming Languages. Context Free Grammars

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

Compiling Regular Expressions COMP360

Final Term Papers 2013

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

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

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Downloaded from Page 1. LR Parsing

Chapter 4. Lexical and Syntax Analysis

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

CS1622. Today. A Recursive Descent Parser. Preliminaries. Lecture 9 Parsing (4)

4 (c) parsing. Parsing. Top down vs. bo5om up parsing

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

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

Wednesday, September 9, 15. Parsers

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

Question Marks 1 /11 2 /4 3 /13 4 /5 5 /11 6 /14 7 /32 8 /6 9 /11 10 /10 Total /117

CMSC 330: Organization of Programming Languages. Context Free Grammars

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

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1

LR Parsing Techniques

A simple syntax-directed

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

The procedure attempts to "match" the right hand side of some production for a nonterminal.

Introduction to parsers

LL(k) Parsing. Predictive Parsers. LL(k) Parser Structure. Sample Parse Table. LL(1) Parsing Algorithm. Push RHS in Reverse Order 10/17/2012

Transcription:

PUNJAB UNIVERSITY COLLEGE OF INFORMATION TECHNOLOGY University of the Punjab Sheet No.: Invigilator Sign: BSCS Fall 2009 Date: 14-12-2012 Mid Term Examination December 2012 Student ID: Section: Morning / Afternoon Student Name: Student Signature: Course Code: CS 420 Course Title: Compiler Construction Maximum Time: 90 Minutes Maximum Marks: 185 Instructions There is only one instruction: We have zero tolerance to cheating. F grade will be given to a cheater without any prior warning. Question # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Total Total Marks 25 10 10 10 10 15 15 15 15 10 10 10 10 10 10 185 Obtained Examiner Signature: Marks Out of 185: DO NOT OPEN UNTIL YOU ARE TOLD TO DO SO Page 1 of 10

This page is intentionally left blank. You may use it for any rough work. Page 2 of 10

Midterm Examination CS420: Compiler Construction Instructor: Prof. Dr. Faisal Aslam Total Marks: 185 Mark each question as true (T) or false (F). Marks: 25 1. The input of lexical analyzer is source program. 2. The output of lexical analyzer is a tree. 3. The input of intermediate code optimizer is an intermediate representation. 4. The input of semantic analyzer is a list of tokens. 5. Usually a program using JIT executes faster than a compiled program 6. Regular languages are more powerful than languages expressed using NFA. 7. All languages expressed using NFAs can also be expressed using DFAs. 8. LL(k) parsers are used for bottom up parsing. 9. LR(k) parsers read input from left to right. 10. A NFA can have many start states. 11. A CFG is more powerful (i.e. can express more languages) than a Regular language. 12. LL(k) parsers can accept more languages than LR(k) parsers. 13. LR(k) parsers can use CFG with left recursion. 14. LR(k) parsers can use ambiguous grammars. 15. DFA can have multiple final states. 16. DFA transition table will never have a null/empty entry. 17. Java bytecode is language dependent but machine independent. 18. Interpreter is usually easier to port on a new machine as compared to a compiler. 19. Each NFA can be expressed using a CFG 20. Context sensitive grammars are less powerful than context free grammars. 21. Recursive descent parsing is used for top down parsing. 22. LL(k) parser can be based on either rightmost or leftmost derivations. 23. The Java code a = = b + c has an error that a lexical analyzer cannot find. 24. The Java code a = = b + c has an error that syntax analyzer cannot find. 25. Compiler's Front-end is machine dependent. Page 3 of 10

Q1: Write a regular expression for all possible strings of 0 s and 1 s with at most single 1. (e.g. 10000, 010000, 0010000 and 000001) Q2: Write a NFA for the regular expression ab? ((b a) + c) + Q3: Write transition table of the NFA created in Q2. Show only first five states. a b c ε 1 2 3 4 5 Q4: Show that the following grammar is ambiguous using the input string aaa. (Hint: you will need to create two parse trees) R R R R R R R R * R ( R ) R a R b Page 4 of 10

This page is intentionally left blank. You may use it for any rough work. Page 5 of 10

Q5: Find FIRST and FOLLOW of each non-terminal. E abt T (L)T [E]T a ε L ER R, ER b Marks 15 FIRST(E) = FOLLOW(E) = FIRST(T) = FOLLOW(T) = FIRST(L) = FOLLOW(L) = FIRST(R) = FOLLOW(R) = Q 6: Create LL(1) parsing table for the CFG of Q5. Marks 15 a b ( ) [ ], $ E T L R Q7: Given the following parsing table (M) use the LL(1) parsing algorithm to validate the input (id+id). Show next 7 stack state and input processed at each stage. Marks 15 id + * ( ) $ E TE' TE' E' +TE' ε ε T FT' FT' T' ε *FT' ε ε F id (E) Stack 1 $ (id+id) 2 $E (id+id) 3 $E'T (id+id) 4 $E'T'F (id+id) 5 6 Input Pointer (remove input characters as pointer moves ahead) Page 6 of 10

7 8 9 10 11 Q8: Remove indirect left recursion from the following CFG. A Ba b B Cd e C Df g D Df Aa Cg Marks 15 Q9: Transform the following grammar by apply left factoring. Z X X Y aec Y aed f Y a b Page 7 of 10

Q10: Above is a finite automaton for LR(k) parser. Show only next 5 steps to verify the input string (id+id) using LR(k) parser. Stack Step # States Symbols Input Action Handle 1 0 $ (id+id) shift to 4-2 04 $( id+id) shift to 5-3 045 $(id +id) reduce using 3 id 4 5 6 7 8 Q11: Write CFG for the given NFA. Page 8 of 10

Q12: Given the following stack of the LR(k) construct parse tree. Also write separately the input and the start symbol. LR(k) Stack Trace Start Symbol: Input Sentence: Parse Tree: x F T T* T*( T*(y T*(F T*(T T*(E T*(E) T*F T E Marks 1+2+7 Page 9 of 10

Q13: Mark the last five values (nodes) added in the following tree created using recursive descent parsing. No marks will be given if you have marked more than five values. (For example you can mark "Program, Block, Var and y") Q14: Subset construction algorithm is used to create DFA from the NFA. Show next five function and subset s created using the NFA of Q11. function subset 1 ε-closure(q0) {q0} 2 3 4 5 6 Page 10 of 10