Exercises
[17/94%]Recall the CFG that we gave in Example 2.4. For convenience, let's rename its variables with single letters as follows.
Give parse trees and derivations for each string.
a
((a))
Use the languages and together with Example 2.36 to show that the class of context-free languages is not closed under intersection.
Use part (a) and DeMorgan's law (Theorem 0.20) to show that the class of context-free languages is not closed under complementation.
ᴬ Answer each part for the following context-free grammar .
What are the variables of ?
What are the terminals of ?
Which is the start variable of ?
Give three strings in .
Give three strings not in .
True or False: .
True or False: aba.
True or False: .
True or False: .
True or False: aba.
True or False: aba.
True or False: .
True or False: .
True or False: .
Give a description in English of .
Give context-free grammars that generate the following languages. In all parts, the alphabet is 0,1.
ᴬ
ᴬ
The empty set
Give informal descriptions and state diagrams of pushdown automata for the languages in Exercise 2.4. In all parts, the alphabet is 0,1.
The empty set
Give context-free grammars generating the following languages.
ᴬ The set of strings over the alphabet with more a's than b's
The complement of the language
ᴬ
ᴬ Give informal English descriptions of PDAs for the languages in Exercise 2.6.
ᴬ Show that the string the girl touches the boy with the flower has two different leftmost derivations in grammar on page 103. Describe in English the two different meanings of this sentence.
Give a context-free grammar that generates the language
Is your grammar ambiguous? Why or why not?
Give an informal description of a pushdown automaton that recognizes the language in Exercise 2.9.
Convert the CFG given in Exercise 2.1 to an equivalent PDA, using the procedure given in Theorem 2.20.
Convert the CFG given in Exercise 2.3 to an equivalent PDA, using the procedure given in Theorem 2.20.
Let be the following grammar. ; and is the set of rules:
Describe in English.
Prove that is not regular.
Convert the following CFG into an equivalent CFG in Chomsky normal form, using the procedure given in Theorem 2.9.
Give a counterexample to show that the following construction fails to prove that the class of context-free languages is closed under star. Let be a CFL that is generated by the CFG . Add the new rule and call the resulting grammar . This grammar is supposed to generate .
Show that the class of context-free languages is closed under the regular operations, union, concatenation, and star.
Use the results of Exercise 2.16 to give another proof that every regular language is context free, by showing how to convert a regular expression directly to an equivalent context-free grammar.