Fall 2016 CSE Qualifying Exam CSCE 531, Compilers

Similar documents
CSE Qualifying Exam, Spring February 2, 2008

Fall 2015 CSE Qualifying Exam Core Subjects

Fall 2009 CSE Qualifying Exam Core Subjects. September 19, 2009

Spring 2014 CSE Qualifying Exam Core Subjects

Spring 2013 CSE Qualifying Exam Core Subjects. March 23, 2013

CSCE 531 Spring 2009 Final Exam

CSCE 531, Spring 2015 Final Exam Answer Key

A Simple Syntax-Directed Translator

CSE P 501 Exam Sample Solution 12/1/11

2.2 Syntax Definition

Tree Parsing. $Revision: 1.4 $

MIPS PROJECT INSTRUCTION SET and FORMAT

ECE 30 Introduction to Computer Engineering

Spring 2010 CSE Qualifying Exam Core Subjects. March 6, 2010

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

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

16.10 Exercises. 372 Chapter 16 Code Improvement. be translated as

Solutions to Written Assignment 4

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

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

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

The PCAT Programming Language Reference Manual

ECE/CS 552: Introduction to Computer Architecture ASSIGNMENT #1 Due Date: At the beginning of lecture, September 22 nd, 2010

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Chapter 2. Instructions:

CSE P 501 Exam 8/5/04 Sample Solution. 1. (10 points) Write a regular expression or regular expressions that generate the following sets of strings.

The SPL Programming Language Reference Manual

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE P 501 Exam 11/17/05 Sample Solution

CSE P 501 Exam 8/5/04

A simple syntax-directed

2. Define Instruction Set Architecture. What are its two main characteristics? Be precise!

CSE 311 Lecture 21: Context-Free Grammars. Emina Torlak and Kevin Zatloukal

1 Lexical Considerations

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

Project Compiler. CS031 TA Help Session November 28, 2011

3. (5 points) Name the 5 components of a computer

CSE Lecture In Class Example Handout

Formal Languages and Compilers Lecture VI: Lexical Analysis

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

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

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

Name: Problem 1: (25 points) Short Answers. a) (5 points) Executing a program

CS308 Compiler Principles Lexical Analyzer Li Jiang

CSE 12 Abstract Syntax Trees

This book is licensed under a Creative Commons Attribution 3.0 License

Problem 3: Theoretical Questions: Complete the midterm exam taken from a previous year attached at the end of the assignment.

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Problems and Solutions to the January 1994 Core Examination

Lecture 6 Decision + Shift + I/O

CIS 341 Midterm February 28, Name (printed): Pennkey (login id): SOLUTIONS

ECE232: Hardware Organization and Design

CSE 378 Final Exam 3/14/11 Sample Solution

Intermediate Code Generation

CSE 413 Final Exam Spring 2011 Sample Solution. Strings of alternating 0 s and 1 s that begin and end with the same character, either 0 or 1.

2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h)

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

HW 3: Bottom-Up Parsing Techniques

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

CS2110 Assignment 2 Lists, Induction, Recursion and Parsing, Summer

Computer Architecture

COMPILER DESIGN. For COMPUTER SCIENCE

Midterm II CS164, Spring 2006

Lecture 4: MIPS Instruction Set

Lexical Considerations

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

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

Question Points Score

Introduction to Parsing. Lecture 8

Appendix Set Notation and Concepts

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

CSE 413 Final Exam. December 13, 2012

CSE 413 Final Exam. June 7, 2011

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

CS5363 Final Review. cs5363 1

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

ICS 51: Introduction to Computer Organization

UNIT- 3 Introduction to C++

NAME: 1. (2) What is a transistor?

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

Principles of Programming Languages COMP251: Syntax and Grammars

CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

LECTURE 3. Compiler Phases

Computer Science Engineering Sample Papers

ECE 154A Introduction to. Fall 2012

Chapter 2A Instructions: Language of the Computer

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

University of Palestine. Final Exam 2 nd semester 2014/2015 Total Grade: 50

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

Programming Assignment in Semantics of Programming Languages

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

CS 354 Midterm 1a, 33.33% Monday, October 9th, 2000 Solution

COMP MIPS instructions 2 Feb. 8, f = g + h i;

Chapter 2: Instructions:

Transcription:

Fall 2016 CSE Qualifying Exam CSCE 531, Compilers 1. LR-Parsing (a) Give definitions of FIRST( ) and FOLLOW(X). (b) Consider the following augmented grammar G with start symbol S 0 : S 0! S S! V = E S! E S! V V! id V! E E! V For the grammar G above generate six of the LR(1) sets of items along with transition information for a canonical LR(1) parser (c) Using the partial Sets-of-Items constructed in part (b) construct as much as you can of the action table. If an action requires shifting to a state you did not construct, say s? for the action. (d) Describe in detail how the LR Parsing Algorithm will proceed in general when the state is s, thenexttokenist and the stack contents is X 0,X 1,...,X top 1,X top. 1

2. Syntax-Directed Definitions Consider the following standard LR (bottom-up) grammar for arithmetic expressions with constants, addition, and multiplication (S is the start symbol): S ::= E E ::= E 1 + T E ::= T T ::= T 1 F T ::= F F ::= c F ::= (E) (Subscripts have been added to distinguish di erent occurrences of the same nonterminal in the same production.) Do either but not both of the two items below: (a) (For 80% credit) Add semantic rules to the grammar above that, given an input expression, produce an equivalent expression with the minimum number of parentheses. So the rules in e ect remove unnecessary parentheses. Your resulting expression should be passed as a string attribute to S.output. Assume that the terminal c has a text attribute that contains the string representing the constant. You may use + in your actions to denote string concatenation, and please surround string constants with double quotes. You should assume that + and are associative operators, and that the usual precedence rules apply ( before +). Do not rearrange or alter the expression in any way other than the parentheses. (b) (For 100% credit) Do the same as the last item, but with the grammar also having aproductionforsubtraction: E ::= E 1 T Subtraction has the same precedence as addition, and both operators associate from left to right. Subtraction is not associative. Examples: Input Output Comment 2+(3+4) 2+3+4 addition is associative (2 3) 4 2 3 4 multiplication is associative 2 +(3 4) 2 + 3 4 multiplication presides over addition (2 + 3) 4 (2 + 3) 4 parentheses needed (2 3) + 4 2 3+4 operators associate left to right anyway 2 (3 + 4) 2 (3 + 4) parentheses needed 2

3. Control Flow and Liveness Analysis Consider the intermediate code below. 0 sum = 0 1 i = 0 L0: 2 j = 0 L1: 3 t1 = b 4 t1 = t1 + i * w 5 t1 = t1 + j * 8 6 f = array [ t1 ] 7 if (f > 0) goto L2 8 goto L3 L2: 9 sum = sum + f 10 goto L4 L3: 11 sum = sum - 1 L4: 12 j = j + 1 13 if (j < 32) goto L1 14 i = i + 1 L5: 15 if (i < 8) goto L0 L6: 16 return L7: 17 goto L0 Assume that there are no entry points into the code from outside other than at the start. (a) (20% credit) Decompose the code into basic blocks B1,B2,..., giving a range of line numbers for each. (b) (20% credit) Draw the control flow graph, and describe any unreachable code. (c) (40% credit) Fill in an 18-row table listing which variables are live at which control points. Treat array as a single variable. Assume that n and sum are the only live variables immediately before line 16 (the only exit point). Your table should look like this: Before line Live variables 0 1 2 17 (d) (20% credit) Describe any simplifying tranformations that can be performed on the code (i.e., transformations that preserve the semantics but reduce (i) the complexity of an instruction, (ii) the number of instructions, (iii) the number of branches, or (iv) the number of variables). 3

Algorithms 1. Find tight asymptotic bounds on any positive function T (n) satisfying the following recurrence for all large enough n: 2n 3n 6n T (n) =T + T + T + n 2 7 7 7 You may assume that any implicit floors or ceilings in the arguments to T are of no consequence. 2. A palindrome is a string that is unchanged by reversal. Specifically, a string S[1,...,n] is a palindrome if S[i] = S[n i + 1] for every i 2{1,...,n}. Examples: hannah, smhtiroglalgorithms, and x are palindromes, but turtles is not a palindrome. Any string can be expanded into a palindrome by inserting characters. The table below shows some examples, with the inserted letters shown as capitals. Original String abb turtles smorgasbord algorithms kayak Palindrome abba SELtRurtles DROBsAGROmorgasbord SMHTIROGLalgorithms kayak Describe, inpseudocode,a (n 2 ) time algorithm that takes as input a string of length n, and outputs the length of the shortest palindrome that can be formed by inserting characters into the input string. Your algorithm only needs to compute the length of the palindrome; it does not need to generate the palindrome itself. Explain why your algorithm works, in enough detail to convince an intelligent but skeptical reader that it is correct. (Hint: Let p[i, j] denote the length of the shortest palindrome that can be formed by inserting characters into S[i,..., j]. How can you fill in the table p?) 3. Consider a binary tree data structure represented as a collection of n nodes, in which each node v has three attributes: (i) An integer key v.key. The keys are all distinct. (ii) A pointer v.left to the left child. Ifv has no left child, then v.left = nil. (iii) A pointer v.right to the right child. Ifv has no right child, then v.right = nil. A binary tree is represented by a pointer to its root (or a nil pointer, if empty). This question has two parts; you should answer both. (a) (50% credit) Describe, in pseudocode, a (n) time algorithm that decides whether a given tree is a binary search tree. Hint: Be sure that your algorithm correctly identifies that this tree is a BST: 5 3 1 (b) (50% credit) Describe, in pseudocode, a (n) time algorithm that decides whether a given tree is a max-heap. (Repeating for emphasis: The input is a binary tree represented by node objects with pointers to their children. The input is not the traditional array representation of a heap.) Hint: Be sure that your algorithm correctly identifies that this tree is not a max-heap: 9 8 1 In both cases, the input is given as a pointer to the root node. Explain why your algorithms work, in enough detail to convince an intelligent but skeptical reader that they are correct. 6 7 6 7

Architecture 1. For this question consider the following loop: for (i=0;i<1024;i++) for (j=0;j<n;j++) a[j*128+i] = a[(j+2)*128+i] * 16; a. Is this loop parallel? Why or why not? b. Suppose you wanted to execute the inner loop in multiple threads. Describe a potential strategy for achieving this. c. Is there a way to transform the loop nest to increase its potential parallelism? How or why not? d. Using the original code, is it possible to unroll the inner loop without the compiler having access to the value of n? What are the potential advantages of unrolling the loop?

2. Consider the following segment of MIPS assembly code: loop: mov r2,r3 beq addi lw loop2: beq sll lw sw addi addi j r2,r8,complete r4,r4,4 r3,0(r4) r2,r3,exit r5,r2,2 r6,0(r5) r6,0(r7) r7,r7,4 r2,r2,1 loop2 exit: j loop complete: a. Identify all the data dependencies in the inner loop. b. In what ways can a programmer parallelize this code? c. Is there any instruction level parallelism available in this code?

3. Consider the following code: float a[1024*1024], b[1024*1024], c[1024*1024]; for (i=0;i<1024;i++) for (j=0;j<1024;j++) { sum=0.0; for (k=0;k<1024;k++) sum+=a[i*1024+k]*b[k*1024+j] c[i*1024+j]=sum; } a. What is the arithmetic intensity of the i-loop, j-loop, and k-loop? b. What is the minimum cache size needed to avoid any conflict and capacity misses in the k-loop? c. How many times does the processor access the a-array before the same element is accessed twice? How many times does the processor access the b-array before the same element is accessed twice?