ECE 468/573 Midterm 1 September 30, 2015

Similar documents
ECE 468/573 Midterm 1 October 1, 2014

ECE 573 Midterm 1 September 29, 2009

Midterm I (Solutions) CS164, Spring 2002

ECE 468/573 Midterm 1 September 28, 2012

CS 164 Programming Languages and Compilers Handout 9. Midterm I Solution

2068 (I) Attempt all questions.

Midterm I - Solution CS164, Spring 2014

CS606- compiler instruction Solved MCQS From Midterm Papers

CS 132 Compiler Construction, Fall 2012 Instructor: Jens Palsberg Multiple Choice Exam, Nov 6, 2012

Monday, September 13, Parsers

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

BSCS Fall Mid Term Examination December 2012

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

Table-driven using an explicit stack (no recursion!). Stack can be viewed as containing both terminals and non-terminals.

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

Note that for recursive descent to work, if A ::= B1 B2 is a grammar rule we need First k (B1) disjoint from First k (B2).

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

CSE 5317 Midterm Examination 4 March Solutions

CSE302: Compiler Design

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

Downloaded from Page 1. LR Parsing

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

Bottom-Up Parsing LR Parsing

Wednesday, August 31, Parsers

Wednesday, September 9, 15. Parsers

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

CSE 401 Midterm Exam Sample Solution 2/11/15

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

Compiling Regular Expressions COMP360

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

COP4020 Spring 2011 Midterm Exam

shift-reduce parsing

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.

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

UVa ID: NAME (print): CS 4501 LDI Midterm 1

Question Bank. 10CS63:Compiler Design

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Principles of Programming Languages

MIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

General Overview of Compiler

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

CS453 : JavaCUP and error recovery. CS453 Shift-reduce Parsing 1

CS502: Compilers & Programming Systems

CMSC 330, Fall 2018 Midterm 2

CS164: Midterm I. Fall 2003


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

ECE468 Fall 2003, Final Exam

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

LR Parsing E T + E T 1 T

CSE 105 THEORY OF COMPUTATION

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

CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1

KEY. A 1. The action of a grammar when a derivation can be found for a sentence. Y 2. program written in a High Level Language

LR Parsing - The Items

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

Table-Driven Parsing

Top down vs. bottom up parsing

Compiler Design Aug 1996

Final Term Papers 2013

CS 415 Midterm Exam Spring SOLUTION

Lecture Bottom-Up Parsing

Formal Languages and Compilers Lecture VI: Lexical Analysis

Parser. Larissa von Witte. 11. Januar Institut für Softwaretechnik und Programmiersprachen. L. v. Witte 11. Januar /23

CSE 582 Autumn 2002 Exam 11/26/02

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

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

ECE251 Midterm practice questions, Fall 2010

CS 4120 Introduction to Compilers

UNIVERSITY OF CALIFORNIA

CMSC330 Spring 2018 Midterm 2 9:30am/ 11:00am/ 3:30pm

MIDTERM EXAM (Solutions)

Chapter 3: Lexing and Parsing

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

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

Parsing Part II (Top-down parsing, left-recursion removal)

CS143 Midterm Sample Solution Fall 2010

More Bottom-Up Parsing

1 Parsing (25 pts, 5 each)

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

Compilation 2012 Context-Free Languages Parsers and Scanners. Jan Midtgaard Michael I. Schwartzbach Aarhus University

List of Figures. About the Authors. Acknowledgments

Chapter 3. Parsing #1

Chapter 4. Lexical and Syntax Analysis

LR(0) Parsing Summary. LR(0) Parsing Table. LR(0) Limitations. A Non-LR(0) Grammar. LR(0) Parsing Table CS412/CS413

CSE 401 Midterm Exam 11/5/10

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

CSCI Compiler Design

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

CS 314 Principles of Programming Languages. Lecture 3

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

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

LR Parsing Techniques

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

Parsing Algorithms. Parsing: continued. Top Down Parsing. Predictive Parser. David Notkin Autumn 2008

CS 164 Programming Languages and Compilers Handout 8. Midterm I

The Parsing Problem (cont d) Recursive-Descent Parsing. Recursive-Descent Parsing (cont d) ICOM 4036 Programming Languages. The Complexity of Parsing

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

Lexical Scanning COMP360

Transcription:

ECE 468/573 Midterm 1 September 30, 2015 Name: Purdue email: Please sign the following: I affirm that the answers given on this test are mine and mine alone. I did not receive help from any person or material (other than those explicitly allowed). X Note: ECE 468 students do not have to complete Part 6. Part Points Score 1 15 2 20 3 15 4 15 5 25 6 10 Total 90 (+ 10)

Part 1: Compiler types and phases (15 points) The following questions are multiple choice, and worth 3 points each. Circle the one choice that you think best answers the question. 1) You are the compiler developer at a company that has their own programming language. You realize on your first day of work that your predecessor used fore instead of for as the keyword for for-loops. Which phases of your compiler do you need to change to fix the problem? a) The parser and the scanner b) Only the parser c) Only the scanner d) The code generator 2) The computers NASA sends into space tend to be much slower and more resource-constrained than earth-bound computers because they have to be radiation hardened. But it is still important that code executing on the spacebased computers run fast. What kind of compiler infrastructure should NASA use for the software they run on the space station: a) An ahead-of-time compiler that generates machine code b) A compiler that generates byte code that can be run in an interpreter c) A compiler that generates byte code that s compiled just in time when it is run 3) If I want to add a new instruction to the intermediate representation of my compiler, what phases of the compiler do I have to change? a) The parser b) The code generator c) The code generator and optimization passes d) None of the above answers are correct

4) If I have a compiler for Intel chips, and Intel adds a new instruction to the x86 ISA, what phases of the compiler do I have to change? a) The parser b) The code generator c) The code generator and optimization passes d) None of the above answers are correct 5) You want to add a new type of looping construct to your programming language, that uses a new keyword and syntax, but otherwise behaves exactly like a while loop. Your compiler uses three address code as its intermediate representation. What phase(s) of the compiler do you have to change? a) The scanner b) The parser and the scanner c) The code generator d) The entire front end

Part 2: Regular expressions, finite automata and scanners (20 points) 1) Consider the following NFA. Fill in the transition table below with its corresponding DFA using the subset construction. You may not use all of the rows (10 points): 2 c 4 d 6 a 1 a b e e 3 d, e 5 b, c State Final? a b c d e 2) How many states does the reduced version of this machine have? (5 pts) Draw the reduced machine (5 pts):

Part 3: First and Follow Sets (15 points) Let G be the grammar to the right. Using this grammar, answer the following multiple-choice questions. 1) Which of these are the first set of A (5 points) a) {x} S! AAB$ A! xa A! CB B! z B! C! y C! b) {x, z} c) {x, y, z} d) {x, y, z, λ} e) None of the above 2) Which of these are the follow set of B (5 points) a) {$} b) {x, $} c) {z} d) {x, y, z, $} e) {z, λ} f) None of the above 3) Which of these are the first set of BCx (5 points) a) {z} b) {x} c) {x, z} d) {y, z} e) None of the above

Part 4: LL parsers (15 points) Consider the following grammar: 1.S! AB$ 2.A! xa 3.A! B 4.B! zb 5.B! C 6.C! yc 7.C! The first and follow sets for the non-terminals of this grammar are: First(S) : {x, z, y, $} Follow(S) : { } First(A) : {x, z, y, λ} Follow(A) : {z, y, $} First(B) : {z, y, λ} Follow(B) : {z, y, $} First(C) : {y, λ} Follow(C) : {z, y, $} 1) Fill in the following parse table. If there are two entries for a given cell in the parse table, list both. (12 points) x y z $ S A B C 2) Is the grammar LL(1)? Why or why not? (3 points)

Part 5: LR(0) Parsers (25 points) Use the following grammar for the next questions: 1. S! A$ 2. A! (A) 3. A! B 4. B! [B] 5. B! x 1) Fill in the information for states 4 and 8 in this CFSM (10 points). In addition, two arrows are missing from the CFSM draw those in (3 points). State 0 A State 1 $ State 2 x B S A$ A (A) A B B [B] B x State 3 A B x ( B S A $ State 4 A S A$ State 5 A (A ) State 6 A (A) ) State 7 B x [ x [ State 8 B State 9 B [B ] State 10 B [B] ]

2) For the following sub-questions, use the CFSM you built in the previous question. Each question will provide the state of the parser in mid-parse, giving the state stack (most recent state on the right) and the next token. For each question, give the action the parser will take next, using the format Shift X for shift actions (where X is the state being shifted to) and Reduce R, goto X for reduce actions (where R is the rule being reduced, and X is the state the parser winds up in after finishing the reduction). Also provide the new state stack. (3 points each) a) State stack: 0 4 4 8. Next token: [ b) State stack: 0 4 4 8 7. Next token: ] c) State stack: 0 4 8 8 9 10. Next token: ] d) State stack: 0 4 4 8. Next token: (

Part 6 (573 only): LR(1) Parsers (10 points): 1) For the following grammar, show what the first state of the LR(1) machine would be (8 points): S! A$ A! Bx A! By B! B! Cz C! x C! 2) Is there a conflict in the first state? If so, what is it? (2 points)

Use this sheet for scratch paper, if you need it.

Use this sheet for scratch paper, if you need it.

Use this sheet for scratch paper, if you need it.