CSCI 3230, Fall 2016 Assignment 1
Posted: Jan. 16 Due before 11:00 pm, Sunday, Jan. 29, 2017
Upload to Assignment 1 folder in Folio Dropbox with file name Lastname-ID.pdf.
(Mandatory assignment coversheet; without it, your work will not be marked.)
Subm
1
Miscellaneous (6 points)
(a) Fill the missing right-hand side for the production of A in the grammar below such that the
rules form a LL(1) grammar.
S ! AaA|AbA
A !
Solution:
A!
Consider the following grammar:
S ! aS | bS | abaA
A ! " | aA | bA
(b) Is t
CS 164 Programming Languages and Compilers
Handout 9
1. Regular Expressions and Finite Automata (15 points)
Consider the design of a small language using only the letters z, o, and the slash character
/. A comment in this language starts with /o and ends
1. You are given an array A[1 . . . n] of items. An item x is called a majority element if it appears more
than n/2 times in A. Clearly, a majority element, if it exists, must be unique.
You are to design an algorithm that determines if A has a majority e
1
Regular Expressions and Finite Automata (20 points)
a) Draw a deterministic nite automaton (DFA) that recognizes the language over the alphabet
cfw_0, 1 consisting of all those strings that contain an odd number of 1s.
b) Write a regular expression for
Question 1
Let G = (V, E) be an undirected graph with vertex set V and edge set
E. A partition of a graph is a partition of V into two disjoint sets, i.e.,
V = V 0 [ V 00 and V 0 \ V 00 = ;. An edge is said to be cut by a partition, if
one of its endpoint
O,M,C
O,M,C
3
4
: Int
: Int
O,M,C
O,M,C
3 + (4 + 5) :
4+5
5
: Int
Bool
x:
P
O[P/x],M,C
O[P/x],M,C
O,M,C
Context:
M(P,foo) = (Bool, Int)
true
x.foo(true)
: Bool
: Int
let x:P in x.foo(true) :
Int
E(y) = L3
y
: Int(9),S
E(x) = L24
so, S, E
Context:
E(x) = L
1
Context-Free Grammars (15 points)
Consider the following grammar.
S ! SS
S ! 0
S !
a) Write a regular expression for the language that is accepted by this grammar.
Answer:
0
b) Give at least one reason why this grammar is not LL(1).
Answer:
It is ambi
CSE541
EXERCISE 1
SOLUTIONS
QUESTION 1 Describe a dierence between logical and semantical paradoxes. Logical paradoxes (antinomies) are paradoxes concerning the notion of a set. Example: Russel paradox. Consider the set A of all those sets X such that X i
1
Liveness (10 points)
Consider the following program fragment.
d
a := 1
a,d
c := 3
a,c,d
if a >= 2 goto L2
a,c,d
b := c + 1
a,b,d
c := b + 2
a,d,c
L1:
a,d,c
if a >= d goto L2
a
c
b := d
return a
L2:
a := c + 2
a,c,
d := c + 1
a,c,d
goto L1
(a) Draw horiz
Problem 1
There are many ways to solve this problem. One way is to use a DFS that is initiated
from a designated root vertex. Each vertex should store the distance to the most distant
leaf in its subtree. Then each vertex can pick the two children with th