Examination Formal Languages and Automata Theory TDDD14 (Formella Spr˚

advertisement
Examination
Formal Languages and Automata Theory
TDDD14
(Formella Språk och Automatateori)
2011–01–14, 08.00 – 12.00
1. Allowed help materials
• A sheet of notes - 2 sided A5 or 1 sided A4.
The contents is up to you.
The notes should be signed in the same way as the exam sheets
and returned together with the exam.
• English dictionary







Tillåtna hjälpmedel:

• Ett papper med valfria anteckningar - 2 sidor A5 eller 1 sida A4.
Anteckningarna ska signeras på samma sätt som tentamensarken och bifogas tentamen vid inlämnandet.
• Engelsk ordbok
2. You may answer in Swedish or English.
3. Total number of credits is 31.
3: 15 p, 4: 20 p, 5: 25 p.
4. Jour (person on duty): Jonas Wallgren, tel. (013 28) 26 82
GOOD LUCK !!
1






Make sure that you justify your answers! Unexplained answers will be
granted 0 points. (For example, assume that you are writing a grammar for
a given language. Then you should also explain that the grammar indeed
generates the language).
1. (2p) Using a standard method construct a DFA equivalent to the NFA
given by the diagram. (Its set of states
is Q = {0, 1, 2, 3, 4}, the input alphabet Σ = {a, b}, the start state is 0, and
3, 4 are the final states.)
b
ε
0
1
b
b
a,b
2
b
4
a
ε
3
a
2. (1p) Construct a DFA for the language L ⊆ { a, b }∗ of the strings not
containing a substring abb.
The justification of your answer should contain explanation of the role
of each state of your automaton.
3. (2p) Using a standard method, construct the minimal DFA equivalent
to your DFA for language L from the previous problem.
Your DFA may already be minimal. In such case you may provide a
proof that it is minimal (instead of constructing a minimal automaton
in a standard way).
4. (2p) Consider the relation ≡L on strings over Σ = {a, b}, defined by
x ≡L y ⇔ ∀z ∈ Σ∗ (xz ∈ L ⇔ yz ∈ L),
where L is the language from the previous two problems. How many
equivalence classes does ≡L have? Why? Choose one of the equivalence
classes, and give a DFA defining it.
5. (2p) Consider the DFA whose transition function is given by the table. (Its set of states
is Q = {A, B, C, D, E, F }, the input alphabet Σ = {0, 1}, the start state is A, and
E is the only final state.) Using a standard
method construct a regular expression defining the same language as the DFA.
2
→A
B
C
D
EF
F
0
1
B
C
E
E
F
F
E
E
D
A
F
F
6. (4p) One of the languages
L1 = { aj+m bl cm dj+l | j, l, m ≥ 0 },
L2 = { aj+m bm+l cn dj+l | j, l, m, n ≥ 0 }
is context-free and the other is not. Construct a context-free grammar
for the one that is. For the other one provide a proof that it is not
regular, or that it is not context-free.
For the proof, use the appropriate pumping lemma or employ reasoning similar to the proof of the lemma. For the grammar, explain the
set generated from each its nonterminal symbol, and the role of each
production.
Hints: Begin from finding the context-free language. Confirm that it is
context-free by constructing a grammar. Take into account that proving a
language to be non context-free is more difficult that proving it to be non
regular.
7. (5p) For each of the following languages answer whether it is regular,
context-free but not regular, or not context-free. A brief explanation
is sufficient.
(a) L1 = { w ∈ {a, b, c}∗ | #a(w) = #b(w) }
(#a(w) denotes the number of occurrences of symbol a in string w),
∗ #a(w) = #b(w),
(b) L2 = w ∈ {a, b, c} ,
w does not contain a substring ccc
∗ #a(w) is even, #b(w) ≡ 1 mod 5
(c) L3 = w ∈ {a, b, c} ,
w does not contain a substring ccc
(d) L4 = { w ∈ {a, b, c}∗ | #a(w) = #b(w) = #c(w) }.
8. (2p) Explain briefly the notion of decidable problem. Begin with
explaining what is the language of a problem. A problem is decidable
if and only if the language of the problem has a certain property; what
is the property?
What are practical consequences of a fact that a certain problem is
undecidable?
9. (3p) Let us say that a state of a Turing machine M is useless if it is
never reached in any computation of M .
Show that the problem “a state q of a Turing machine M is useless” is
undecidable. Use the fact that it is undecidable whether a given Turing
machine M accepts some string. (Equivalently, whether L(M ) 6= ∅.)
3
In other words, show that the language of the considered problem, this
means


Turing machine M


US = hM, qi does not reach state q


on any input
is not recursive, using the fact that the language
M is a Turing machine,
NONEMPTY = hM i and L(M ) 6= ∅
is not recursive.
10. (4p) Which of the following statements are true, which are false?
Justify your answers.
(a) If a Turing machine M does not halt on some input then the
language L(M ) is not recursive.
(b) If h is a homomorphism and L is an infinite language then h(L)
is infinite.
(c) There exists a non regular language whose all strings are not longer
than 77.
(d) The programming language Ada is a context-free language.
11. (1p) Explain why the grammar containing productions
A → aBc | Bd
B → aA | b
(and possibly some other productions) is not LL(1). (A, B are nonterminal symbols, and a, b, c, d are terminal symbols of the grammar.)
12. (3p) In an attempt to construct LR parsers for certain grammars,
we applied the standard method of constructing a DFA for the viable
prefixes of a grammar. Some fragments of the obtained DFA’s are given
below.
Complete the missing items in the given states, the missing lookahead
sets and the missing symbols labelling the arrows. In each case answer
the following questions. Justify your answers.
• Does the fragment of a DFA satisfy the conditions for the grammar
to be LR(0)?
• The same question about the conditions for LR(1).
4
You may skip adding missing items or lookahead sets if they are not needed to
answer the questions. For instance if you find the items in some state to violate the
LR(1) conditions then you do not need to complete the other states.
c, d are terminal symbols and S, A, B are nonterminal symbols of the grammars; S
is the start symbol.
(a)
S → •A
{
A → • BA {
}
}
A
−→
−→
The productions of the grammar are S → A, A → BA | c,
B → AB | d.
(b)
|
↓
A → AB • {$, d}
B → B • A {c, d}
c
−→
←−
The productions of the grammar are S → A, A → AB | c,
B → BA | d.
5
Download