CS 321 Fall 2015 HW7 Due Thursday Nov 12, at 5pm on Canvas. Wednesday Nov 11 is a holiday. Quiz 6 on Friday Nov 13. 1. Write down the definitions of the following levels of ambiguity: (a) ambiguous string (b) ambiguous grammar (c) ambiguous language Now answer the following (justify your answer): (d) does an ambiguous grammar always produce at least one ambiguous string? (e) does an ambiguous language always contain at least one ambiguous grammar? (f) is it the case that all strings in an ambiguous language also ambiguous? (g) is it possible to know if a string is ambiguous (given a grammar)? (h) is it possible to know if a grammar is ambiguous? (i) is it possible to know if a language is ambiguous? (j) is C++/Java/Python ambiguous? (k) is English/Chinese ambiguous? 2. Write down a single grammar that works for _all_ the following sentences: (a) I saw a boy with a telescope (b) I saw boys with girls (c) I eat sushi with tuna And draw two parse trees for each sentence. 3. Now write two unambiguous grammars for the above problem, one with the PP modifying NP, and one with the PP modifying VP. 4. Give an example of ambiguous language. Write a CFG for it and demonstrate why it is ambiguous. 5. Write a CFG for the language over {a,b} which has same number of a's as b's. Is this CFG ambiguous? Justify. 6. Write a CFG for {a^m b^n | m != n, and m,n >= 0 }. 7. Write a CFG for {a^n b^n a^m b^m | m,n >= 1} \cup {a^n b^m a^m b^n | m,n >= 1 }. If your grammar is ambiguous, prove it. What about we replace the \cup with \cap? 8. Draw a DFA for the strings over {a,b} with every pair of a's followed by at least one b. Then convert this DFA to a right-linear CFG (regular grammar). In a right-linear CFG, all rules are either in the form of A->aB or A->a. 9. Convert this CFG S -> 0S0 | 1S1 | \epsilon to Chomsky Normal Form (CNF). Note that The CNF defined on the slides is missing one minor detail -- what is it? 10. Write a CFG for the complement of copy language, and justify your answer. (If you can write a formal proof, great, but just explaining it would also help). Extra credit (but important for Quiz 6) 11. For each of the following CFG, (a) describe (in English) the language it generates (b) decide whether the language is regular (c) if it is regular, write a right-linear grammar (i.e., regular grammar) for it. (A) S -> SaS | b (B) S -> aSb | bSa | \epsilon (C) S -> SSS | a | ab Debriefing (required!): -------------------------- 1. Approximately how many hours did you spend on this assignment? 2. Would you rate it as easy, moderate, or difficult? 3. Did you work on it mostly alone, or mostly with other people? 4. How deeply do you feel you understand the material it covers (0%–100%)? 5. Any other comments?