CS143 Midterm Spring 2014

Similar documents
Midterm I (Solutions) CS164, Spring 2002

CS143 Midterm Sample Solution Fall 2010

CS143 Midterm Fall 2008

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

Midterm I - Solution CS164, Spring 2014

CS164: Midterm I. Fall 2003

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

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

CS143 Final Fall 2009

UNIVERSITY OF CALIFORNIA

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

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

Computer Science Spring 98 Midterm Examination Professor L. Rowe

2068 (I) Attempt all questions.

LR Parsing LALR Parser Generators

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

CS 164 Programming Languages and Compilers Handout 8. Midterm I

CS606- compiler instruction Solved MCQS From Midterm Papers

LR Parsing LALR Parser Generators

CS143 Final Spring 2016

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

COP5621 Exam 3 - Spring 2005

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

BSCS Fall Mid Term Examination December 2012

Question Points Score

CSCE 531, Spring 2015 Final Exam Answer Key

Syntax-Directed Translation

CS154 Midterm Examination. May 4, 2010, 2:15-3:30PM

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

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

COP4020 Spring 2011 Midterm Exam

CS 44 Exam #2 February 14, 2001

CSE 401 Midterm Exam Sample Solution 2/11/15

CS164 Second Midterm Exam Fall 2014

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

Talen en Compilers. Johan Jeuring , period 2. January 17, Department of Information and Computing Sciences Utrecht University

Spring 2017 CS 1110/1111 Exam 1

Error Handling Syntax-Directed Translation Recursive Descent Parsing

Lexical and Syntax Analysis. Bottom-Up Parsing

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

BIRLA INSTITUTE OF TECHNOLOGY AND SCIENCE, Pilani Pilani Campus Instruction Division

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

Syntax Analysis. Chapter 4

CS 411 Midterm Feb 2008

Test 2 Version A. On my honor, I have neither given nor received inappropriate or unauthorized information at any time before or during this test.

CSE302: Compiler Design

CS244a: An Introduction to Computer Networks

HW 3: Bottom-Up Parsing Techniques

CSCI Compiler Design

In One Slide. Outline. LR Parsing. Table Construction

Lecture 12: Cleaning up CFGs and Chomsky Normal

Chapter 3: Lexing and Parsing

Lecture Notes on Bottom-Up LR Parsing

CS145 Midterm Examination

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

Abstract Syntax Trees & Top-Down Parsing

Abstract Syntax Trees & Top-Down Parsing

CS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:

Action Table for CSX-Lite. LALR Parser Driver. Example of LALR(1) Parsing. GoTo Table for CSX-Lite

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

CS415 Compilers. Lexical Analysis

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

Abstract Syntax Trees & Top-Down Parsing

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

Lecture Notes on Bottom-Up LR Parsing

CS164 Spring 1997 Midterm 1

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

ECE 468/573 Midterm 1 October 1, 2014

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

CS145 Midterm Examination

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 468/573 Midterm 1 September 30, 2015

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

Chapter 2 - Programming Language Syntax. September 20, 2017

CMSC 330, Fall 2018 Midterm 2

Computer Science 320: Final Examination

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

ECE468 Fall 2003, Final Exam

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

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

Bottom-Up Parsing. Lecture 11-12

MIDTERM EXAM (Solutions)

Compiler Design Overview. Compiler Design 1

Introduction to Lexing and Parsing

UNIT -2 LEXICAL ANALYSIS

Chapter 4. Lexical and Syntax Analysis

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

CS145 Final Examination

Programming Project II

Bottom-Up Parsing. Lecture 11-12

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

LR Parsing. Table Construction

MIDTERM EXAMINATION - CS130 - Spring 2003

CSE3322 Programming Languages and Implementation

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

Class Information ANNOUCEMENTS

GUJARAT TECHNOLOGICAL UNIVERSITY

CS131 Compilers: Programming Assignment 2 Due Tuesday, April 4, 2017 at 11:59pm

Problem Score Max Score 1 Syntax directed translation & type

Transcription:

CS143 Midterm Spring 2014 Please read all instructions (including these) carefully. There are 5 questions on the exam, most with multiple parts. You have 75 minutes to work on the exam. The exam is open note. Please write your answers in the space provided on the exam, and clearly mark your solutions. You may use the backs of the exam pages as scratch paper. Please do not use any additional scratch paper. Solutions will be graded on correctness and clarity. Each problem has a relatively simple and straightforward solution. You may get as few as 0 points for a question if your solution is far more complicated than necessary. Partial solutions will be graded for partial credit. NAME: In accordance with both the letter and spirit of the Honor Code, I have neither given nor received assistance on this examination. SIGNATURE: Problem Max points Points 1 10 2 15 3 15 4 20 5 15 TOTAL 75 1

1. Lexical Analysis (10 points) Consider the following flex-like lexical specification: a*b { print "1" } ca { print "2" } a*ca* { print "3" } Given the following input string what does the lexer print? abcaacacaaabbaaabcaaca 132311132 2

2. Top-Down Parsing (15 points) One of your coworkers at PGP (Pretty Good Parsing) spills coffee on her LL(1) parsing table, obliterating the row labels. Besides the surviving portion of the table, she remembers the following facts about the grammar: 2 Follow(Z ) ɛ First(M ) ɛ First(J ) First(M ) First(K ). Label each row of the table with one of the non-terminals M, K, Z, J or C such that the parsing table is consistent and the facts above are satisfied. 1 2 3 4 5 $ K MC MC C 2K ɛ ɛ M JZ 5Z J 1K4 Z ɛ 3M ɛ ɛ 3

3. Grammars (15 points) Give an example of a grammar that generates an infinite language where there is a unique derivation for every parse tree. For full credit, give a grammar that is as simple as possible. S -> as S -> epsilon State a characteristic property of every grammar where every parse tree has a unique derivation. Every production has at at most one non-terminal on the right-hand side. Can a grammar where every parse tree has a unique derivation be ambiguous? If the answer is yes, give an example grammar. If the answer is no, explain why not. S -> X S -> Y X -> a Y -> a 4

4. Bottom-Up Parsing (20 points) Below is the skeleton of an LR parsing automaton, showing just the states and transitions. Write a grammar that has this state diagram. Fill in the states with the LR(0) sets of items from your grammar and label the edges with the correct transition symbol. There should be no shift-reduce or reducereduce conflicts in your automaton (under LR(0) parsing rules). For full credit, use the minimum number of terminals and non-terminals. 5

Grammar: S - > S S - > asa S - > b S - > as.a a S - > asa. S - > S. S S S - >.S S - >.asa S - >.b a S - > a.sa S - >.asa S - >.b b b a S - > b. 6

5. Syntax-Directed Translation (15 points) Complete the actions for the following syntax-directed translation. A program P is a sequence of statements separated by semicolons. Each statement assigns the value of an expression E to the variable x. An expression is either the sum of two expressions, the constant 1, or the current value of x. Statements are evaluated in left-to-right order. For the ith statement x = E i, the value of references to x inside E i is the value assigned to x in the previous statement x = E i 1. For the first statement x = E 1 the value of references to x in E 1 is 0. The value of a program is the value assigned to x by the last statement. Each action should be a set of equalities of the form a 0 = F (a 1,..., a n ) where F is some function of the attributes a i. Assume the parser will figure out the order in which to solve the equations, computing the right-hand side before assigning it to the attribute named on the left-hand side. Do not use anything but attribute equations and do not use any global state. Your solution should assign P.val the value of the program generated by P. Introduce whatever other attributes you need to compute the value of a program; indicate for each attribute whether it is inherited or synthesized. x is an inherited attribute val is a synthesized attribute P 0 P 1 ; x = E {E.x = P 1.val P 0.val = E.val} P ɛ {P.val = 0} E x {E.val = E.x} E 1 {E.val = 1} E 0 E 1 + E 2 {E 0.val = E 1.val + E 2.val E 1.x = E 0.x E 2.x = E 0.x} 7