Context free grammer, Schemes and Mind Maps of Theory of Automata

University: University of Gujrat (UOG) Department: BS Computer Science Course Name: Theory of Automata Topic: Context-Free Grammar Document Type: Past Paper / Practice Questions / Particles Questions Year: 2024 (or your relevant year) Professor: Sir Karam College: (Enter your affiliated college name here, e.g., Punjab College Gujrat Campus) Language: English and Urdu Mix (if applicable)

Typology: Schemes and Mind Maps

2024/2025

Uploaded on 05/06/2025

hafsa-kamran-1
hafsa-kamran-1 🇵🇰

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4

Partial preview of the text

Download Context free grammer and more Schemes and Mind Maps Theory of Automata in PDF only on Docsity!

CONTEXT-FREE GRAMMARS 261 PROBLEMS 1. Consider the CFG: S— aS | bb Prove that this generates the language defined by the regular expression a*bb 2. Consider the CFG: S— X¥YX X— aX | oX|A Y -> bbb Prove that this generates the language of all strings with a triple 6 in them, which is the language defined by (a + b)*bbb(a + b)* 3. Consider the CFG: S— ax X— aX|bX|A What is the language this CFG generates? 4. Consider the CFG: S — XaXaX X— aX | bX|A What is the language this CFG generates? 5. Consider the CFG: S— SS | XaXax | A X— bX|A (i) Prove that X can generate any b*. 262 (it) (iii) (iv) (vy) ii) PUSHDOWN AUTOMATA THEORY Prove that XaXaX can generate any b*ab*ab*. Prove that S can generate (b*ab*ab*)*. 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. Show how the difficulty in part (iv) can be alleviated by adding the production S— XS 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 “sub- stantially the same” otherwise they are “substantially different.” 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 gen- erated stays the same but all words are now generated by substantially only one possible derivation. Consider the CFG: 5S — XbaaX | aX X—> Ka|Xb|A What is the language this generates? Find a word in this language that can be generated in two substantially different ways. (i) (ii) 0) (ii) Consider the CFG for “some English” given in this chapter. Show how these productions can generate the sentence: lichy the bear hugs jumpy the dog. Change the productions so that an article cannot come between an adjective and its noun. Show how in the CFG for “some English” we can generate the sentence: The the the cat follows cat. Change the productions so that the same noun cannot have more than one article. Do this for the modification in Problem 8 also. 264 PUSHDOWN AUTOMATA THEORY 19. Write a CFG to generate the language of all strings that have more a’s than 6’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 ZL be any language. Define the transpose of Z to be the language of all the words in Z 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 Z is a context-free language then the transpose of L is context-free also. Proof Sketch: Take CFG for L Reverse all RHS of productior Is Example: S!aSb becomes S!b¢ grammar generates trans (L Since CFGs are closed under eversal, transpose(L) is CF