Computer Science 456/656 -- Spring 1998 -- Midterm March 23, 1998
Name:
No books, notes, or scratch paper. Use pen or pencil, any color.
Use the rest of this page and the backs of the pages for scratch paper.
If you need more scratch paper, it will be provided.
The entire test is 150 points.}
-
True or False. [5 points each]
-
Any subset of a regular language is a regular language.
-
The complement of any context-free language is context-free.
-
The left hand side of a production of any context-free grammar must have
exactly one symbol.
-
Every PDA that accepts by final state is equivalent to
some PDA that accepts by empty stack.
-
Every context-free language over the unary alphabet {1} is regular.
-
It is decidable whether a given CFG generates the empty language.
-
If G is an ambiguous CFG, then L(G) is definitely not a DCFL.
-
The set of regular expressions over a given alphabet Sigma is a regular
language.
-
Fill in each blank with one word.
[5 points each]
-
The intersection of any context-free language with any
_____________ language is context-free.
-
A _______________ machine has at most one legal move from any configurationa.
-
The right hand side of any production of any _____________ Normal Form grammar
has either one terminal or two variables.
-
The class of NFA's accepts the class of _______________ languages.
-
A _____________ is a machine that writes an output string,
and given as input w in L, where L is a CFL, it outputs a derivation
of w.
-
Give a definition of each of the following terms.
[10 points each]
-
Regular expression over a given alphabet Sigma.
-
L(M), where
M is a non-deterministic machine whose input alphabet is Sigma.
(You are not told whether M is an NFA, or a PDA, or a TM, or some other
kind of machine that we have not discussed yet.) Your answer should contain
the word "configuration" or the phrase "instantaneous description" (these
mean the same thing).
-
Minimal DFA.
-
[30 points]
Let Sigma={a,b,c,+,-,*,/,(,)}. Let L be the language over Sigma of
all "valid" algebraic expressions, where variables are always a single
letter, where * and / are used to denote multiplication and
division, and where + and - always mean addition and subtraction
(that is, there is no unary operator).
Construct a CFG G which generates L, and which has the following additional
properties:
-
G is unambiguous.
-
The parse tree over G of any string w in L respects the usual semantics
of the string. That means that if a, b, and c have stored values, then
every internal node in the parse tree has a value which is derivable from the
values of its children in the obvious way, in such a manner that the value
at the root is the value of w interpreted as an expression.
You must be careful to keep in mind that multiplication and division have
precedence over addition and subtraction, and that among operators of
equal hierarchy, the leftmost has precedence.
-
[25 points]
Let Sigma={a,b,c}.
Let L = {w in Sigma* | n_a(w)=n_b(w)=n_c(w)}.
(For example, the string aaababccbcacbcb is in L.)
Is L a context free language? If so, construct a CFG which generates L.
If not, give a proof that L is not context-free.