CSCI Compiler Design

Similar documents
CSCI Compiler Design

CSCI Compiler Design

CSCI Compiler Design

CSCI Compiler Design

Question Points Score

CS 536 Midterm Exam Spring 2013

Midterm II CS164, Spring 2006

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

Midterm I - Solution CS164, Spring 2014

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

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

COP4020 Spring 2011 Midterm Exam

QUESTIONS RELATED TO UNIT I, II And III

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

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

CSCI 565: Compiler Design and Implementation Spring 2006

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

COP5621 Exam 4 - Spring 2005

Midterm I (Solutions) CS164, Spring 2002

2068 (I) Attempt all questions.

Test I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Spring Department of Electrical Engineering and Computer Science

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

CST-402(T): Language Processors

CSE 582 Autumn 2002 Exam 11/26/02

CS 164 Handout 16. Final Examination. There are nine questions on the exam, some in multiple parts. You have 3 hours to work on the

EXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully

UNIVERSITY OF CALIFORNIA

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

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

Compiler Construction

Compilers. Computer Science 431

Compiler Construction

CSE P 501 Exam 8/5/04

CS606- compiler instruction Solved MCQS From Midterm Papers

A simple syntax-directed

Question Marks 1 /20 2 /16 3 /7 4 /10 5 /16 6 /7 7 /24 Total /100

G.PULLAIH COLLEGE OF ENGINEERING & TECHNOLOGY

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

MIDTERM EXAM (Solutions)

CS 415 Midterm Exam Spring SOLUTION

ECE251 Midterm practice questions, Fall 2010

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

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

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

CSE 401 Midterm Exam 11/5/10

CSE302: Compiler Design

CSCI 565 Compiler Design and Implementation Spring 2014

CSE 582 Autumn 2002 Exam Sample Solution

MIDTERM EXAMINATION - CS130 - Spring 2003

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

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Compiler Design. Spring Run-Time Environments. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Appendix Set Notation and Concepts

Error Handling: SYNTAX

CSCE 531, Spring 2015 Final Exam Answer Key

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

Syntax-Directed Translation

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

More On Syntax Directed Translation

CSE3322 Programming Languages and Implementation

Special Topics: Programming Languages

CSCI 1260: Compilers and Program Analysis Steven Reiss Fall Lecture 4: Syntax Analysis I

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

BSCS Fall Mid Term Examination December 2012

LECTURE NOTES ON COMPILER DESIGN P a g e 2

COMP 524 Spring 2018 Midterm Thursday, March 1

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

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

CSE3322 Programming Languages and Implementation

INSTITUTE OF AERONAUTICAL ENGINEERING (AUTONOMOUS)

Compiler Design Overview. Compiler Design 1

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

Chapter 4 - Semantic Analysis. June 2, 2015

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

CSE-304 Compiler Design

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY

CS 3360 Design and Implementation of Programming Languages. Exam 1

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

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

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

GUJARAT TECHNOLOGICAL UNIVERSITY

CSE 401 Midterm Exam Sample Solution 11/4/11

Summary: Semantic Analysis

CS164: Midterm I. Fall 2003

[Syntax Directed Translation] Bikash Balami

CS 415 Midterm Exam Spring 2002

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Conflicts in LR Parsing and More LR Parsing Types

Question Marks 1 /16 2 /13 3 /12 4 /15 5 /8 6 /15 7 /8 8 /5 9 /8 Total /100

Mid-term Examination

Translator Design CRN Test 3 Revision 1 CMSC 4173 Spring 2012

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

CSCI565 Compiler Design

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Front End. Hwansoo Han

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Semantic Analysis with Attribute Grammars Part 4

CSCE 531 Spring 2009 Final Exam

CSE 401 Midterm Exam Sample Solution 2/11/15

Downloaded from Page 1. LR Parsing

Transcription:

CSCI 565 - Compiler Design Spring 2015 Midterm Exam March 04, 2015 at 8:00 AM in class (RTH 217) Duration: 2h 30 min. Please label all pages you turn in with your name and student number. Name: Number: Grade: Problem 1 [30 points]: Problem 2 [20 points]: Problem 3 [20 points]: Problem 4 [30 points]: Total: INSTRUCTIONS: 1. This is a open-book exam and you may notes either typed or handwritten for your own personal use during the exam. 2. Please identify all the pages where you have answers that you wish to be graded. Also make sure to label each of the additional pages with the problem you are answering. 3. Use black or blue ink. No pencil answers allowed. 4. Staple or bind additional answer sheets together with this document to avoid being misplaced or worse, lost. Make sure this cover page is stapled at the front. 5. Please avoid laconic answers so that we can understand you understood the concepts being asked. Name: Number: 1 of 5

Problem 1: Context-Free-Grammars and Parsing Algorithms [30 points] Consider the CFG fragment with non-terminal symbols {decl, type, id_list}, with start symbol S, terminal symbols { id, :, ; var, integer, real } and the productions P listed below. (1) decl var id_list : type ; $ (2) type integer (3) type real (4) id_list id_list, id (5) id_list id Questions: a) [05 points] Is this grammar suitable to be parsed using a predictive LL(0) parsing algorithm? Why? b) [15 points] Compute the DFA that recognizes the LR(0) sets of items for this grammar and construct the corresponding LR(0) parsing table. Comment on the nature of the conflicts, if any. b) [10 points] Typically the LR(0) table construction algorithm leads to tables that are very 'dense'. Construct the SLR parsing table by indicating the FOLLOW sets used to trim the entries on the table. Name: Number: 2 of 5

Problem 2: Syntax-Directed Translation [20 points] In Pascal a programmer can declare two integer variables a and b with the syntax var a, b : integer This declaration might be described by the grammar in problem 1 above: (1) decl var id_list : type ; (2) type integer (3) type real (4) id_list id_list, id (5) id_list id where id_list derives a comma separated list of variable names and type derives a valid Pascal type. You may find it necessary to rewrite the grammar. (a) [10 points] Write an attribute grammar that assigns the correct data type to each declared variable and show the values of your attributes for the example given above (considering that the size of an integer scalar variable is say 4). (b) [05 points] Determine an evaluation order of the attributes irrespective of the way the parse tree is constructed. (c) [05 points] How would you change the grammar to ensure that all the attributes would be synthesized attributes? (d) [10 points] Modify the original grammar to eliminate the left-recursion, and describe how to implement the corresponding attributive grammar using a table-based LL predictive parser. Name: Number: 3 of 5

Problem 3. Intermediate Code Generation [20 points] Suppose your programming language provided support for the exponentiation operation in both integers and floating-point representations with the syntax as shown below where the exponent is E 2 and the base operand is E 1. For the purpose of this exercise, you can ignore the base type of the operand but that the exponent needs to be a positive integer. E E 1 ^ E 2 Questions: (a) [15 points] Write an SDT scheme for this exponentiation operator generating code that checks that the exponent is a non-negative number. Your solution will clearly include some localized control flow as you may not assume that there is a native exponentiation instruction. Show your work for an illustrative expression. When the exponent is a negative integer your generated code should execute a 'trap' instruction. (b) [05 points] Revise your solution implementing specific code to test for the cases of E 2 = 0 and E 2 = 1 when this is known at compile time and/or at run-time. For this part you have to assume that the non-terminal expression includes other attributes in addition to the attributes place and code we have discussed in class. These could include for instance an attribute for type and an attribute to check if the corresponding value is a compile-time constant. Name: Number: 4 of 5

Problem 4. Activation Records and Stack Layout [30 points] Under the assumption that the AR are allocated on the stack with the individual layout as shown below, and given the PASCAL code on the right-hand-side answers the following questions: (a) [05 points] Draw the call tree starting with the invocation of the main program. (b) [15 points] Draw the set of ARs on the stack when the program reaches line 16 in procedure P2. Include all relevant entries in the ARs and use line numbers for the return addresses. Draw direct arcs for the access links and clearly label the values of local variables and parameters in each AR. (c) [10 points] For this particular example would there be any advantage of using the Display mechanism? ARP Local Variables AR Pointer Access Link Return Address Return Value Argument 1 Argument 1 01: program main(input, output); 02: procedure P1(a: integer)); 03: var x: integer; 04: begin 05: if (a <> 0) then 06: begin 07: P1(a-1); 08: P2(a); 09: end 10: end; 11: procedure P2(b: integer); 12: var y: integer; 13: begin 14: if(b <> 0) then 15: P2(b-1); 16: end; 17: begin (* main *) 18: P1(1); 19: P2(1); 20: end. Name: Number: 5 of 5