ECE 468/573 Midterm 1 September 28, 2012

Similar documents
Midterm I Solutions CS164, Spring 2006

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.

Compilers Spring 2013 PRACTICE Midterm Exam

CS 321 Programming Languages and Compilers. Bottom Up Parsing

acronyms possibly used in this test: CFG :acontext free grammar CFSM :acharacteristic finite state machine DFA :adeterministic finite automata

CS 430 Spring Mike Lam, Professor. Parsing

CSE 401 Midterm Exam 11/5/10 Sample Solution

CMSC 331 First Midterm Exam

Fig.25: the Role of LEX

ECE 468/573 Midterm 1 October 1, 2014

Definition of Regular Expression

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

ECE 468/573 Midterm 1 September 30, 2015

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata

CSCE 531, Spring 2017, Midterm Exam Answer Key

Dr. D.M. Akbar Hussain

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

Assignment 4. Due 09/18/17

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong

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

Lexical Analysis: Constructing a Scanner from Regular Expressions

10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

Eliminating left recursion grammar transformation. The transformed expression grammar

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

Midterm 2 Sample solution

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number>

Scanner Termination. Multi Character Lookahead

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

CMPSC 470: Compiler Construction

Lecture T4: Pattern Matching

Fall 2018 Midterm 1 October 11, ˆ You may not ask questions about the exam except for language clarifications.

Theory of Computation CSE 105

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

Context-Free Grammars

Lexical analysis, scanners. Construction of a scanner

Context-Free Grammars

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015

2014 Haskell January Test Regular Expressions and Finite Automata

EECS 281: Homework #4 Due: Thursday, October 7, 2004

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University of the Negev

Reducing a DFA to a Minimal DFA

Section 3.1: Sequences and Series

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

12-B FRACTIONS AND DECIMALS

MIPS I/O and Interrupt

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

ECE 573 Midterm 1 September 29, 2009

Topic 2: Lexing and Flexing

pdfapilot Server 2 Manual

INTRODUCTION TO SIMPLICIAL COMPLEXES

Section 10.4 Hyperbolas

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

Physics 208: Electricity and Magnetism Exam 1, Secs Feb IMPORTANT. Read these directions carefully:

Fall 2017 Midterm Exam 1 October 19, You may not use any books, notes, or electronic devices during this exam.

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

5 Regular 4-Sided Composition

Qubit allocation for quantum circuit compilers

Top-down vs Bottom-up. Bottom up parsing. Sentential form. Handles. Handles in expression example

Regular Expression Matching with Multi-Strings and Intervals. Philip Bille Mikkel Thorup

File Manager Quick Reference Guide. June Prepared for the Mayo Clinic Enterprise Kahua Deployment

Small Business Networking

9.1 apply the distance and midpoint formulas

How to Design REST API? Written Date : March 23, 2015

Spring 2018 Midterm Exam 1 March 1, You may not use any books, notes, or electronic devices during this exam.

MATH 2530: WORKSHEET 7. x 2 y dz dy dx =

Digital Design. Chapter 6: Optimizations and Tradeoffs

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

CS 241 Week 4 Tutorial Solutions

TO REGULAR EXPRESSIONS

6.2 Volumes of Revolution: The Disk Method

3.5.1 Single slit diffraction

Compilation

stack of states and grammar symbols Stack-Bottom marker C. Kessler, IDA, Linköpings universitet. 1. <list> -> <list>, <element> 2.

Solutions to Math 41 Final Exam December 12, 2011

Small Business Networking

Small Business Networking

Geometric transformations

Small Business Networking

Engineer To Engineer Note

MA1008. Calculus and Linear Algebra for Engineers. Course Notes for Section B. Stephen Wills. Department of Mathematics. University College Cork

Context-Free Grammars

Compiler Construction D7011E

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

3.5.1 Single slit diffraction

Representation of Numbers. Number Representation. Representation of Numbers. 32-bit Unsigned Integers 3/24/2014. Fixed point Integer Representation

Subtracting Fractions

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

Transcription:

ECE 468/573 Midterm 1 September 28, 2012 Nme:! Purdue emil:! Plese sign the following: I ffirm tht the nswers given on this test re mine nd mine lone. I did not receive help from ny person or mteril (other thn those explicitly llowed). X Prt Points Score 1 10 2 15 3 15 4 25 5 35 6 20 Totl 120

Prt 1: Short nswers (10 points) Hlf credit tken off for not providing justifiction. 1) You hve just come up with new kind of compiler optimiztion tht cn improve the run-time of code by fctor of 10, but is very slow. For code tht normlly tkes 10 seconds to run, the compiler tkes 1000 seconds to perform the optimiztion, but the optimized code runs in 1 second. Would you rther implement this optimiztion in stndrd compiler (tht compiles code before it runs) or in just-in-time compiler? Justify your nswer (4 points). Becuse this optimiztion tkes long time, it is hrd to justify performing it in JIT compiler, s the code would hve to run for very long time to mke up for the compiltion time. Hence, we would prefer to do this in stndrd compiler. 2) Suppose this optimiztion requires seeing the high-level structure of your code (e.g., the loops in the code). Should this optimiztion tke plce in the frontend of your compiler? Or the bck-end? Justify your nswer (3 points). Becuse the bckend strts with n intermedite representtion nd produces ssembly, it never gets to see the high-level structure of the code (e.g., loops re converted into brnches). Hence, the optimiztion needs to tke plce in the front-end, where the code structure is still vilble. 3) You hve just been employed by Intel to work on their compiler technology nd to give it more powerful optimiztions thn compilers for ARM. Should you be working on front-end optimiztions? Or bck-end? Justify your nswer (3 points.) Becuse the optimiztions you re doing re rchitecture specific, this needs to be done in the bck-end, which cn be specilized for prticulr rchitectures. Note, lso, tht ny optimiztions done in the front-end would likely help ARM s well, since they re not rchitecture-specific: probbly not something Intel would wnt to do!

Prt 2: Regulr expressions, finite utomt nd scnners (15 points) 1) Give n rgument for why we cnnot use regulr expressions to define progrmming lnguges like Micro (hint: think bout the wy blocks of code cn nest inside ech other). (6 points): Lnguges like Micro hve nested blocks tht strt with BEGIN nd end with END (or { nd }, etc.) Prsing the lnguge requires mtching n equl number of BEGINs with ENDs, which we cnnot do with regulr expression. 2) Consider the following NFA. Fill in the trnsition tble below with its corresponding DFA using the subset construction. (8 points): One point per row 2 c 4 6 1 b c 3 5 b 7 Stte Finl? b c 1 no 2 3 err 2 no err err 4 3 no 2, 3, 5 err 4 4 no 6 no no 2, 3, 5 no 2, 3, 5, 6 7 4 6 yes err err err 2, 3, 5, 6 yes 2, 3, 5, 6 7 4 7 yes err err err 3) List which sttes should be merged when you reduce the bove DFA (1 point): We cn combine sttes 6 nd 7: they re both finl nd they hve the sme behvior on every input. Note tht we cnnot combine 2, 3, 5 nd 2, 3, 5, 6 becuse one is finl nd one is not.

Prt 3: Grmmrs (15 points) Let G be the grmmr: S! AC$ A! xab A! B! y C! BCz C! Using this grmmr, nswer the following questions. 1) Drw the prse tree for the string xyyz$ (3 points) Not given here (but everyone got this right) 2) Describe the kinds of strings this grmmr cn generte. (3 points) x i y i y k z k (This question did not get counted) 3) Cn the lnguge of this grmmr be cptured by regulr expression? If so, give the regulr expression. If not, give short rgument why not. (4 points) No, becuse you need to be ble to count the numbers of x s nd z s to get the right number of y s, which regex cnnot do. (-2 points for no explntion) 4) Give grmmr tht cptures the following lnguge, which hs some number of s or b s, followed by the sme number of c s or d s (5 points) ( b) i (c d) i Mny possible nswers. Here s one: S! M M! AMC A! b C! c d

Prt 4: LL prsers (25 points) Answer the questions in this prt using the sme grmmr from Prt 3. 1) Give the First sets for ech non-terminl in the grmmr (8 pts) 2 points per set First(S) = {$, x, y} First(A) = {x, λ} First(B) = {y} First(C) = {y, λ} 2) Give the Follow sets for ech non-terminl in the grmmr (8 pts) 2 points per set Follow(S) = {} Follow(A) = {y, $} Follow(B) = {y, z, $} Follow(C) = {z, $} 3) Fill in the following prse tble (8 pts) 0.5 points per box x y z $ S 1 1 1 A 2 3 B 4 C 5 6 6 4) Is this grmmr LL(1) or not? Why or why not? (1 pt) Yes, becuse there re no conflicts in the prse tble.

Prt 5: LR(0) Prsers (35 points) Use the following grmmr for the next two questions: 1) Fill in the missing informtion for the for the following CFSM (including edge lbels) (14 points) 1 point per configurtion, 2 points for edge lbels Stte 0 S AA$ A xb A y 1.S! AA$ 2.A! xb 3.A! y 4.B! Az Stte 1 S A A$ A xb A y Stte 2 S AA $ Stte 3 S AA$ Stte 4 A y Stte 7 A xb Stte 5 A x B B Az A xb A y Stte 6 B A z Stte 8 B Az 2) List the reduce sttes in the bove CFSM, nd the shift sttes, ssuming stte 3 is n ccept stte. (4 points) Shift sttes: 0, 1, 2, 5, 6 Reduce sttes: 4, 7, 8 (3 ok) 3) Is this n LR(0) grmmr? Why or why not? (2 points) Yes. No S/R conflicts

4) Show the ctions tken by the prser s it prses xyzy$. Actions should either be of the form Shift X or Reduce R (goto X) If the prser gets to stte 3, it ccepts. You cn use the following tble to help show your work (you my not need ll of the rows) (15 points) -3 points per mistke (prtil credit given for crrying through errors) Prse stck Remining input Action 0 x y z y $ Shift 5 0 5 y z y $ Shift 4 0 5 4 z y $ Reduce 3 (goto 6) 0 5 6 z y $ Shift 8 0 5 6 8 y $ Reduce 4 (goto 7) 0 5 7 y $ Reduce 2 (goto 1) 0 1 y $ Shift 4 0 1 4 $ Reduce 3 (goto 2) 0 1 2 $ Shift 3 0 1 2 3 Accept

Prt 6: LR(1) Prsers (ECE 573 only) (20 points): Consider the following grmmr: 1) Fill in the missing informtion from this prtil LR(1) mchine (15 points) 1 point per configurtion Stte 0 S A$, {} A xyb, {$} A xb, {$} Stte 1 A x yb, {$} A x B, {$} B ya, {$} B y, {$} y x Stte 3 A xy B, {$} B y A, {$} B y, {$} B ya, {$} B y, {$} A xyb, {$} A xb, {$} y 1.S! A$ 2.A! xyb 3.A! xb 4.B! ya 5.B! y A B A Stte 4 S A $, {} $ Stte 4 S A$, {} Stte 4 A xyb, {$} B Stte 2 A xb, {$} x Stte 6 B y A, {$} B y, {$} A xyb, {$} A xb, {$} A Stte 5 B ya, {$} 2) Show wht the ction tble entries for Stte 3 would be (i.e., give the row for Stte 3). For reduce ctions, give wht rule would be reduced (4 points) x! Shift y! Shift $! Reduce(5) 3) Is this grmmrlr(0)? Why or why not? (1 point) No. Without lookhed, there would be shift/reduce conflicts in sttes 3 nd 6.