Examination Formal Languages and Automata Theory TDDD14 (Formella Språk och Automatateori) 2011–08–26, 14.00 – 18.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): Wlodek Drabent, tel. (013 28) 89 29. 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 table. (Its set of states is Q = {A, B, C, D}, the input alphabet Σ = {0, 1}, the start state is D, and B is the only final state.) 2. (2p) a b c →1 2F 3 4 5F 6 2 3 4 5 6 1 3 2 3 3 5 6 0 1 A ∅ {A, B} ∅ B F {C} {B} {A} ∅ {D} {C} C {A} ∅ {C} →D Using a standard method, construct the minimal DFA equivalent to the DFA given by the table. (Its set of states is Q = {1, 2, 3, 4, 5, 6}, the input alphabet Σ = {a, b, c}, the start state is 1, and {2, 5} is the set of final states.) 5 2 6 5 2 3 3. (2p) Let L be the language accepted by the DFA from the previous problem. Consider the relation ≡L on strings over Σ = {a, b}, defined by x ≡L y ⇔ ∀z ∈ Σ∗ (xz ∈ L ⇔ yz ∈ L). How many equivalence classes does ≡L have? Why? Choose two of the equivalence classes, and give two DFA’s defining them. 4. (2p) Consider the DFA given by the table. (Its set of states is Q = {A, B, C, D}, the input alphabet Σ = {0, 1}, the start state and the final state is A.) Using a standard method, construct a regular expression defining the same language. →AF B C D 0 1 B C C A C B D C 5. (2p) Construct a context-free grammar generating the language specified by regular expression (a) a(b + c + ε)∗ d, (b) (a(b + c)∗ d)∗ . Make it clear what are the sets generated by the nonterminal symbols of your grammars, and what is the role of each production. 2 6. (6p) For each of the following languages answer whether it is regular, context-free but not regular, or not context-free. A brief, informal explanation is sufficient. A ← α is a production of some (a) L1 = Aα ∈ (N ∪ Σ)∗ . context-free grammar (We assume some fixed alphabets N of nonterminals and Σ of terminal symbols.) (b) L2 = { aj bm cj+1 d2m | m > 0, j > 3 }. (c) L3 = { aj bm x | m > 0, j > 3, x ∈ {c, d}∗ , |x| = j + 1 + 2m }. (d) L4 = { aj bm cm+1 d2j | m > 0, j > 3 }. (e) L5 = { aj bm c2j dm+1 | m > 0, j < 3 }. 7. (3p) Prove that a language L6 = { z ∈ {a, b, c}∗ | #a(z) < #b(z) < #c(z) } is not regular or that it is not context-free. Use the appropriate pumping lemma or employ reasoning similar to the proof of the lemma. 8. (1p) Explain briefly Church’s thesis (also called the Church-Turing thesis). 9. (3p) Let A be a symbol from the tape alphabet of a Turing machine M . We say that M on some input writes A, when M writes A on the tape at some step of the computation started with some string on the tape. (Assume that this includes writing A into a cell already containing A.) Show that the problem “a Turing machine M on some input writes A” is undecidable. In other words, show that the language of the problem, Turing machine M WP = hM, Ai , on some input writes A is not recursive. Use the fact that it is undecidable whether a given Turing machine halts on some input. The language of this version of halting problem is Turing machine M HP2 = hM i , halts on some input (and is not recursive). 3 10. (4p) Which of the following statements are true, which are false? Justify your answers. (a) If L1 is a regular language and L2 is a subset of L1 then L2 is a regular language. (b) There exists a context-free language which is not generated by any context-free grammar in Chomsky normal form. (c) Every regular language is generated by some context-free grammar. (d) The language WP from problem 9 is recursively enumerable. 11. (1p) Explain why the grammar with A → Bb | Ca B → aC | bC C → cBb | bBc among its productions is not LL(1). (A, B, C are nonterminal symbols, and a, b, c 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). 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. a, b, c are terminal symbols and S, A, B are nonterminal symbols of the grammars; S is the start symbol. 4 (a) A → b • Ba { b } A a −→ −→ The productions of the grammar are S → A, A → Ab | bBa, B → aAb | aAc | a. (b) | ↓ A → a • Ab {$} A → a • Ac {$} b A −→ ←− The productions of the grammar are S → A, A → aAb | aAc | b. 5