Docsity

CS 164: Spring 2008 Exam - Computer Science University of California, Exams of Programming Languages

Toggle sidebar
bg1
UNIVERSITY OF CALIFORNIA
Department of Electrical Engineering
and Computer Sciences
Computer Science Division
CS 164 P. N. Hilfinger
Spring 2008
CS 164: Test #1
Name: ________________________________________________ Login: _________
You have fifty minutes to complete this test. Please put your login on each sheet, as
indicated, in case pages get separated. Answer all questions in the space provided on the
exam paper. Show all work (but be sure to indicate your answers clearly.) The exam is
worth a total of 20+ points (out of the total of 200), distributed as indicated on the
individual questions.
You may use any notes or books you please––anything unresponsive. We suggest that
you read all questions before trying to answer any of them and work first on those about
which you feel most confident.
You should have 4 problems on 4 pages.
1. _______________ / 6
2. _______________ / 6
3. _______________ /
4. _______________ / 8
TOT ______________ / 20
pf3
pf4
pf5

Partial preview of the text

Download CS 164: Spring 2008 Exam - Computer Science University of California and more Exams Programming Languages in PDF only on Docsity!

UNIVERSITY OF CALIFORNIA

Department of Electrical Engineering and Computer Sciences Computer Science Division

CS 164 P. N. Hilfinger Spring 2008

CS 164: Test #

Name: ________________________________________________ Login: _________

You have fifty minutes to complete this test. Please put your login on each sheet, as indicated, in case pages get separated. Answer all questions in the space provided on the exam paper. Show all work (but be sure to indicate your answers clearly.) The exam is worth a total of 20+ points (out of the total of 200), distributed as indicated on the individual questions. You may use any notes or books you please––anything unresponsive. We suggest that you read all questions before trying to answer any of them and work first on those about which you feel most confident. You should have 4 problems on 4 pages.

1. _______________ / 6

2. _______________ / 6

3. _______________ /

4. _______________ / 8

TOT ______________ / 20

1. [6 points] Consider a really simplified set of regular expressions (call them RSREs) consisting of letters ‘a’ and ‘b’, concatenation, union (using the symbol ‘|’), epsilon (represented by the letter e), and Kleene star, but without parentheses. So, for example,

a ab ab | b | ba*

are valid RSREs.

a. Write a regular expression that recognizes RSREs. Use just the basic operators supplied by Flex or JFlex.

b. Draw a DFA that recognizes RSREs.

3. [1 point] I noticed that a certain kind of prepackaged snack sold in our local coffee shops has the slogan “The ones you remember,” which I thought was mildly clever. Why? 4. [8 points] Consider the parse tree below. All terminal symbols are written at the same level on the bottom row.

a. Show as much of the grammar as one can deduce from this parse tree.

More questions on the next page

b. Show a reverse rightmost derivation corresponding to this tree, as performed by a shift-reduce parser. (However, you need not mention the shifts and reductions, just the sentential forms that get you back to the start symbol from the input).

c. Show that the grammar is ambiguous by giving a string that has (at least) two parses and giving two distinct parse trees for it.

Continued on next page.