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.)
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
Consider the following grammar:
S ! aS | bS | abaA
A ! " | aA | bA
(b) Is t
CS 164 Programming Languages and Compilers
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
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
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
3 + (4 + 5) :
M(P,foo) = (Bool, Int)
let x:P in x.foo(true) :
E(y) = L3
E(x) = L24
so, S, E
E(x) = L
Context-Free Grammars (15 points)
Consider the following grammar.
S ! SS
S ! 0
a) Write a regular expression for the language that is accepted by this grammar.
b) Give at least one reason why this grammar is not LL(1).
It is ambi
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
Liveness (10 points)
Consider the following program fragment.
a := 1
c := 3
if a >= 2 goto L2
b := c + 1
c := b + 2
if a >= d goto L2
b := d
a := c + 2
d := c + 1
(a) Draw horiz
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