CS 321 Fall 2015 HW 8 Due *Sunday* 11/22 at 5pm on Canvas. Recitation on *Sunday* 11/22, 8pm in KEC 1001. Quiz 7 (last quiz) on Monday 11/23. Part I: CFG questions Note that the only way to prove the ambiguity of grammar is to draw two parse trees for the same sentence. 1. For this grammar in Quiz 6, E -> E + E | E * E | a | b | c there are the two types of ambiguities: precedence and associativity. (a) Illustrate each of them (using two separate examples). (b) Illustrate both of them using one example. 2. (a) write a grammar that eliminates the precedence ambiguity only, where * has lower precedence than + (contrary to the mathematical tradition!). (b) write a grammar that eliminates the associativity ambiguity only, where both + and * are right-associative, i.e., a+b+c = a+(b+c). (c) write a grammar that eliminates both ambiguities, where + is left-associative, * is right-associative, and + has lower precedence than *. 3. Write a grammar for the prefix notation (Polish) arithmetic expression, e.g. (15+6)*7 => * + 15 6 7 15+(6*7) => + 15 * 6 7 the operators are + and *, and the operands are non-negative decimal integers. No leading zeros are allowed (i.e. 0012 should be written as 12). The characters are {+, *, 0..9}. Wait, do you need some other character?? Is this grammar ambiguous? 4. (a) Compare the pros and cons of the three notations: infix, postfix, and prefix. (b) Which human languages in the world correspond to these three notations? (c) [optional] -- What are the pros and cons of SVO and SOV languages? (d) Which programming languages correspond to these three notations? 5. Convert the infix grammar (problem 1) and the postfix grammar (quiz 6) into CNF. 6. Given a grammar and a string, how do you know if this string is ambiguous? Describe an algorithm and analyze the running time. Extra Credit Problem now moved to a separate file. Part II: PDA questions 1. Construct a PDA for the following languages (or explain why it's impossible): (a) 0^n 1^n (b) w w^R (c) w w (d) same number of a's and b's (e) same number of ab's and ba's ...TO BE CONTINUED... 2. Is deterministic PDA equivalent to non-deterministic PDA? 3. Describe the basic algorithms for converting CFG <=> PDA.