1 / 3

Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday)

Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday) Section 2; April 17 (Tuesday). ** Notice that this homework has 7 problems.

lorie
Download Presentation

Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday) Section 2; April 17 (Tuesday) ** Notice that this homework has 7 problems. 1. This problem is to clean up context-free grammar G shown below. Using the two algorithms presented in the class, we are going to eliminate all useless symbols from the following context-free grammar G. Answer the following two questions. (a) Using the algorithm in Lemma 1 for grammar G construct a context-free grammar G’ such that L(G) = L(G’) and every nonterminal symbol in G’ derives a string x (VT)*, where VT is set of terminal symbols of G. (b) Using the algorithm in Lemma 2 for grammar G’, the result of part (a), and construct a context-free grammar G’’ such that L(G) = L(G’’), and for each symbol X (which is either terminal or nonterminal symbol) in G’’, starting with the start symbol, it is possible to derive a string containing X. Your answer should include detailed procedure (steps of the algorithm) that you took to collect the information needed to get your answer. No grade will be given to an answer that only shows the final result. G: S BA | CDg B aEA A  DEd C  Ce D  Df |  E  Eg | g F  hF | h G cGCc I  cDEFab 2. Covert the following context-free grammar into a Chomsky Normal Form. S  abABCde A  aAa B  ba C  cab

  2. <IF-statement> <bool> <statement> <statement> then IF ( ) else a - b <statement> <IF-statement> <bool> c a + b d 3.(a) Show that the following grammar is ambiguous. S  S + S | S * S | T T  a | b (b) Let + be the addition and * be the multiplication. Then the above grammar generates mathematical expressions with the two operators on two variable a and b. Convert the above grammar to an unambiguous context-free grammar such that it generates the same language and * has higher precedence than +. (c)Convert the above grammar to an unambiguous context-free grammar such that - it generates the same language, - the two operators * and + have the same precedence, and - the evaluation is done right to left. 4. The following syntax flow graph is a simplified definition of the Pascal’s syntax flow graph for < IF statement>. Assume that all the strings in a circle are terminal symbols. (a) Convert this syntax flow graph for <If-statement> to a context-free grammar that generate the same language, and show that the grammar is ambiguous. (b) Convert your grammar to an unambiguous grammar that generates the same if statements. You should briefly describe your idea.

  3. 5. Using the pumping lemma we want to prove that language L = {xxR | x {a, b, c}* } is not regular as follows. Complete the proof by answering the questions. Proof. Suppose that L is regular. Then L should satisfy the pumping lemma. Let n be the constant of the lemma. Clearly, all the following strings belong to L. (a) abccba (b) a100b100b100a100 (c ) an/2bn/2b n/2an/2 (d) anbnbnan Question 1: Which string will you choose for z of the lemma? Why the other strings cannot be a candidate for z? If none of the above strings can be a candidate for z, what is your choice from L? Question 2: Let u, v, w {a, b, c}* be the strings of the lemma such that z = uvw. What will be in v? Shortly describe all possible contents of string v. Question 3: The pumping lemma says “For all i  0, string uviw  L.” How do you deal with this statement for your proof? Justify what you do. 6. Which of the following language are regular. Prove your answer. Your answer will be graded according to the logical completeness. L1 = {aibjak | i, j, k > 0 } L2 = {aibjai | i, j > 0 } 7. For a string x, let #a(x), #b(x), and #c(x) denote, respectively, the number of a’s, number of b’s and number of c’s in string x. Which of the following languages are context-free? Prove your answer. Your answer will be graded according to the logical completeness. L3 = { x | x {a,b,c}+, and #a(x) > #c(x) } L4 = { x | x {a,b,c}+, and #a(x) = #b(x) = #c(x) } L5 = {x | x {a,b,c}+, and #a(x) > #b(x) > #c(x) }

More Related