0% found this document useful (0 votes)
243 views4 pages

CFG

The document provides 20 problems related to context-free grammars (CFGs). The problems cover topics such as: proving languages are generated by CFGs; modifying CFGs so words are generated in only one way; finding CFGs for specific languages; eliminating nonterminals; and showing transposes of context-free languages are also context-free.

Uploaded by

mani khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
243 views4 pages

CFG

The document provides 20 problems related to context-free grammars (CFGs). The problems cover topics such as: proving languages are generated by CFGs; modifying CFGs so words are generated in only one way; finding CFGs for specific languages; eliminating nonterminals; and showing transposes of context-free languages are also context-free.

Uploaded by

mani khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Consider the CFG:

S-- aS I bb

Prove that this generates the language defined by the regular expression

a*bb

2. Consider the CFG:

S -- XYX

X aX I bXI A

Y -- bbb

Prove that this generates the language of all strings with a triple b in

them, which is the language defined by

(a + b)*bbb(a + b)*

3. Consider the CFG:

S-- aX

X- aX I bX IA

What is the language this CFG generates?

4. Consider the CFG:

S -- XaXaX

X aX I bX IA

What is the language this CFG generates?

5. Consider the CFG:

S -SS I XaXaX I A

X-- bXI A

(i) Prove that X can generate any b*.

262 PUSHDOWN AUTOMATA THEORY

(ii) Prove that XaXaX can generate any b*ab*ab*.

(iii) Prove that S can generate (b*ab*ab*)*.

(iv) Prove that the language of this CFG is the set of all words in (a + b)*

with an even number of a's with the following exception: We consider

the word A to have an even number of a's, as do all words with no


a's, but of the words with no a's only A can be generated.

(v) Show how the difficulty in part (iv) can be alleviated by adding the

production

S-- XS

6. (i) For each of the CFG's in Problems 1 through 5 determine whether

there is a word in the language that can be generated in two

substantially different ways. By "substantially," we mean that if

two steps are interchangeable and it does not matter which comes

first, then the different derivations they give are considered "substantially the same" otherwise they are
"substantially different."

(ii) For those CFG's that do have two ways of generating the same word,

show how the productions can be changed so that the language generated stays the same but all words
are now generated by substantially

only one possible derivation.

7. Consider the CFG:

S -XbaaX IaX

X -Xa I Xb I A

What is the language this generates? Find a word in this language that can

be generated in two substantially different ways.

8. (i) Consider the CFG for "some English" given in this chapter. Show

how these productions can generate the sentence:

Itchy the bear hugs jumpy the dog.

(ii) Change the productions so that an article cannot come between an

adjective and its noun.

9. (i) Show how in the CFG for "some English" we can generate the

sentence:

The the the cat follows cat.

(ii) Change the productions so that the same noun cannot have more than

one article. Do this for the modification in Problem 8 also.


CONTEXT-FREE GRAMMARS 263

10. Show that in the CFG for AE given in, this chapter we can eliminate

the nonterminal AE. In which other CFG's in this chapter can we eliminate a nonterminal?

Find a CFG for each of the languages defined by the following regular expressions.

11. ab*

12. a*b*

13. (baa + abb)*

Find CFG's for the following languages over the alphabet I = {a,b}.

14. (i) All words in which the letter b is never tripled.

(ii) All words that have exactly two or three b's.

15. (i) All words that do not have the substring ab.

(ii) All words that do not have the substring baa.

16. All words that have different first and last letters:

{ab ba aab abb baa bba . . . }

17. Consider the CFG:

S-- AA

A -- AAA

A -- bA I Ab Ia

Prove that the language generated by these productions is the set of all words

with an even number of a's, but not no a's. Contrast this grammar with the

CFG in Problem 5.

18. Describe the language generated by the following CFG:

S -- SS

S - XXX

X-- aX I Xa l b

264 PUSHDOWN AUTOMATA THEORY

19. Write a CFG to generate the language of all strings that have more a's

than b's (not necessarily only one more, as with the nonterminal A for

the language EQUAL, but any number more a's than b's).
{a aa aab aba baa aaaa aaab ... }

20. Let L be any language. Define the transpose of L to be the language

of all the words in L spelled backward (see Chapter 6, Problem 17).

For example, if

L = {a baa bbaab bbbaa}

then

transpose (L) = {a aab baabb aabbb}

Show that if L is a context-free language then the transpose of L is

context-free also.

You might also like