This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: ’9 Lumpy“ a LUI IlCAl‘I ‘EV: \JI nuln “I": (3) Build the derivation tree for the derivations in parts (a) and (b).
d) Use set notation to deﬁne L(G). . Lethethegrarnmar S—ySABH
A—)0A0
3—4me. a) Give a leftmost derivation of 0bb00b. b) Give two leftmost derivations of 00. c) Build the derivation tree for the derivations in part (b).
d) Give a regular expression for L(G). . Let DT be the derivation tree S
AAB
/\ /\
a A A B
1 1 I
0 0 b a) Give a leftmost derivation that generates the tree DT.
b) Give a rightmost derivation that generates the tree DT.
c) How many different derivations are there that generate DT? . Give the leftmost and rightmost derivations corresponding to each of the derivation trees given in Figure 3.3. For each of the following contextfree grammars, use set notation to deﬁne the language
generated by the grammar. a) SaaaSBIA d) SﬁaSblA
B—rbBlb AacAdcha'
BraBblab
b)S—>0$bbA e)S—>0.S‘BiaB
AﬁcAle Babblb
C) S—tabdeA
A—bL‘dAbﬂll Construct a grammar over {0, b, 0} whose language is {anbhcm In, in > 0}. 11mean in, Construct a grammar over {0, b, c} whose language is {a at :v 0}. . Construct a grammar over {0, b, c} whose language is {0"me I0 5 n + m 5 i}. n—umun — — . Construct a grammar over {0, 17} whose language is {amb"  0 5 n 5 m 5 3n}.
. Construct a grammar over {0, b} whose language is {0”‘b‘0” { i = m + n}.
. Construct a grammar over {0, b} whose language contains precisely the strings with the same number of 0’s and b’s. . Construct a grammar over {0, b} whose language contains precisely the strings of odd length that have the same symbol in the ﬁrst and middle positions. For each of the following regular grammars, give a regular expression for the language
generated by the grammar. a) S—>0A c)S—>0S{bA
AeaAIbAlb A—rbB
B—HIBIJL
b) S—>0A d) SeaSleIA
A—)0AbB A—>0A{bs
B+bB];t 'l Exercises 15 through 25, give a regular grammar that generates the described language. The set of strings over {0, b, c} in Which all the 0’s precede the 5’s, which in turn
precede the e’s. It is possible that there are no 0’s, 17’s. or c’s. The set of strings over {0, b} that contain the substring 00 and the substring bb. " The set of strings over {0, b} in which the subslring 00 occurs at least twice. (Hint:
. Beware of the substring 000.) The set of strings over {0, b} that contain the substring 0b and the substring £70. The set of strings over {0, b} in which the number of 0’s is divisible by three. The set of strings over {0, b} in which every 0 is either immediately preceded or
immediately followed by b, for example, baab, aba, and b. _. The set of strings over {0, b} that do not contain the substring aha.
_‘.'_ The set of strings over {0, b} in which the substn'ng 00 occurs exactly once.
The set of strings of odd length over {0, b} that contain exactly two b’s. _t The set of strings over {0, b, c} with an odd number of occurrences of the substring
0b. The set of strings over {0, b} With an even number of 0’s or an odd number of 17’s. The grammar in Figure 3.1 generates (b‘ab‘ab‘ﬁ, the set of all strings with a positive,
even number of 0’s. Prove this. . Prove that the grammar given in Example 3.2.2 generates the prescribed language.
. Let G be the grammar S—+0SbB
a—tbsw. Prove that L(G) = {0"b’”  0 5 n < m}. . 5. Give the state diagram of a PDA M that accepts {aﬁb‘ﬁ  0 5 j 5 i} with acceptance
by empty stack. Explain the role of the stack symbols in the computation of M. Trace
the computations of M with input aabb and aaaabb. 6. The machine M alt/A bAﬁt % brill g accepts the language L = {nibi  i a 0} by ﬁnal state and empty stack.
a) Give the state diagram of a PDA that accepts L by empty stack.
b) Give the state diagram of a PDA that accepts L by ﬁnal state. 7. Let L be the language {to e {(3, b}*  to has a preﬁx containing more b’s than a’s}. For
example, baa, abba, abbaaa E L. but aab, aabbab 9! L. a) Construct a PDA that accepts L by ﬁnal state.
b) Construct a PDA that accepts L by empty stack. 8. Let M = (Q, E, l", 5, go. F) be a PDA that accepts L by ﬁnal state and empty stack.
Prove that there is a PDA that accepts L by ﬁnal state alone. 9. Let M = (Q, E, F, 6, go, F) be a PDA that accepts L by ﬁnal state and empty stack.
Prove that there is a PDA that accepts L by empty stack alone. 10. Let L = {aﬁbi 1 t" 2 0}.
3) Construct a PDA M1 with L(Ml) = L.
b) Coastruct an atomic PDA M2 with L(Mz) = L.
c) Construct an extended PDA M3 with L(M3) = L that has fewer transitions than M]. (:1) Trace the computation that accepts the string cab in each of the automata con
structed in parts (a), (b), and (c). 11. Let L = {elite3“  1' z 0}.
a) Construct a PDA M1 with L(Ml) = L.
b) Construct an atomic PDA M2 with L(MZ) = c) Construct an extended PDA M3 with L(M3) = L that has fewer transitions than M1. d) Trace the computation that accepts the string aabbb in each of the antomata con
structed in parts (a), fb), and (c). 12. Use the technique of Theorem 7.3.1 to construct a PDA that accepts the language of
the Greibach normal form grammar SaaABAIaBB
A—ybAlb
B—chlc. 13 Let G be a grammar in Greibach normal form and M the PDA constructed from G. Prove that if [(10, u. A] l— [qp A. w] m M. then there' is a derivation S => aw in G.
This completes the proof of Theorem 7. 3. l. ' .LethethePDA Q = {tint 91, ‘12} “909 a, l) = {lim All
= {0. bl 8(th. b, A) 2 {[QI 1]} F = {A} 3(91: b, A) = {[92, Al} F = {42} “42:17: A) = {[91, ll} a) Give the state diagram of M.
' b) Give a settheoretic deﬁnition of L(M). c) Using the technique from Theorem 7.3.2, build a contextfree grannnar G that
__ generates L(M).
' (1) Trace the computation of aabbbb in M. _ e) Give the derivation of aabbbb in G. LetM be the FDA in Example 7.1.1. . a) Trace the computation in M that accepts bbcbb. b) Use the technique from Theorem 1.3.2 to construct a grammar G that accepts L(M).
c) Give the derivation of bbcbb in G. __ f. Theorem 7.3.2 presented a technique for constructing a grammar that generates the
. language accepted by an extended PDA. The transitions of the PDA pushed at most two
"£5: variables onto the stack. Generalize this construction to build grammars from arbitrary
. extended PDAs. Prove that the resulting grammar generates the language of the PDA. Use the pumping lemma to prove that each of the following languages is not context
' free. a) {at  k is a perfect square} b) {aibfcidi  t, j a 0} c) {teak}:i It a 0}
Id) {a*‘bic"0<i <j<k~<zi} e) {wwa  w e {0, b}*} f) The set of ﬁnitelength preﬁxes of the inﬁnite string abaabcaabaaaab. . . ba"ba"+lb . . . . .. . a) Prove that the language L] = {ainicl l 1'. j 2 0} is contextfree.
b) Prove that the language L; = {Oibica  i, j Z O} is contextfree.
c) Prove that Lln L; is not contextfree.  _ — _.... 'D“_D"' 19. a) Prove that the language L. = {a‘ bi oldl ti, j 2 0} is contextfree.
b) Prove that the language L2 = {ajblc‘dk  i, j, k 2 0} is contextfree.
c) Prove that LID L3 is not contextfree. 20. Let L be the language consisting of all strings over {a, b} with the same number of (1’5
and b’s. Show that the pumping lemma is satisﬁed for L. That is. show Ihat every string
2 of length It or more has a decomposition that satisﬁes the conditions of the pumping
lemma. 21. Let M be a PDA. Prove that there is a decision procedure to determine whether
a) L(M) is empty.
b) L(M) is ﬁnite.
0) LM) is inﬁnite.
* 22. A grammar G = (V, 2, P, S) is called linear if every rule has the form A—Hr
11—»qu where u, v e 2* and A, B e V. A language is called linear if it is generated by a linear
grammar. Prove the following pumping lemma for linear languages. Let L be a linear language. Then there is a constant k such that for all z e L with
length(z) 2: k, 2 can be written 2 = uvwxy With i) lengtMuvxy) 5 k,
ii) lengthwx) > 0, and
iii) uvlwxiy e L, fori 3 0.
23. a) Construct a DFA N that accepts a]! strings in {a, b}* with an odd number of a’s.
b) Construct a PDA M that accepts {.93le l i 2 0}. c) Use the technique from Theorem 15.3 to construct a PDA M’ that accepts
L(N) n L(M). (1) Trace the computations that accept cash in N, M, and M’.
24. Let G = (V, E. P, S) be a contextfree grammar. Deﬁne an extended PDA M as follows:
Q = {9'0} 5010,19 A) = {[90, 5]}
E=EG 5010.1. A)={[¢on wllAﬁwEP}
F=EGUV 5(qn,a,a)={[qu,l]aeE}.
F=l40l Prove that L(M) = L(G).
25. Complete the proof of Theorem 7.5.3. ve that the set of contextLﬁ'ee languages is closed under reversal. t L be a contextfree language over 2‘. and a e 2. Deﬁne erﬂ(L) to be the set obtained y removing all occurrences of a from strings of L. The language err“(D is the language
with a erased. For example, if abab, bacb, an e L, then bb, herb, and A E erﬂ(L).
Prove that era(L) is contextfree. Hint: Convert the grammar that generates L to one u. generates areas).
' e notion of a string homomorphism was introduced in Exercise 6.19. Let L be a
contextfree language over E and let I: :E“ —> 2* be a homomorphism. _) Prove that h(L) = {h(w)  w e L} is contextfree, that is, that the contextfree
I languages are closed under homomorphisms. ) Use the result of part (a) to show that erﬂfL) is context~free. c) Give an example to show that the homomorphic image of a noncontextfree language
' may be context—free. _  h : 2* > )3’ be a homomorphism and L a contextfree language over 2. Prove that
{iii ] h(w) E L} is contextfree. In other words. the family of contextfree languages is
closed under inverse homomorphic images. Use closure under homomorphic images and inverse images to show that the following
guages are not contextfree. z) stowed} H. j 2 0}
'_ ' {aibﬂc'ﬁ i z 0}
“ ,{tabr'tbcx‘tcar I i 2 0} raphic Notes ,9 own automata were introduced in Oettinger [1961]. Deterministic pushdown au
' were studied in Fischer {1963] and Schutzenberger [1963] and their acceptance
Aanguages generated by LR(k) grammars is from Knuth [1965]. The relationship be
context—free languages and pushdown automata was discovered by Chomsky {1962],
.2 1963], and Schutzenberger [1963]. The closure properties for contextfree languages
'  in Section 7.5 are from BarHillel, Perles, and Shamir [1961] and Scheinberg
.9}. A solution to Exercises 28 and 29 can be found in Ginsburg and Rose [1963b]. e pumping lemma for contextfree languages is from BarHillel, Perles, and Shamir
1]. A stronger version of the pumping lemma is given in Ogden [1968]. Parikh’s
:.''m [1966] provides another tool for establishing that languages are not contextfree. ...
View
Full Document
 Spring '08
 Ehrich,R

Click to edit the document details