Parse Trees Construct a parse tree for a * (a + a) using the grammar. E -> E + T | T T -> T * F | F F -> ( E ) | a Ambiguity What's an Ambiguous Grammar? How can you show that a grammar is ambiguous? Use the string 2*3+6 to show the grammar is ambiguous. E -> E + E E -> E * E E -> ( E ) E -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Does this ambiguity cause any problems? Suppose a grammar gives two different derivations for the same string. Does this show the grammar is ambiguous? NO, derivations may differ in order of replacing variables What's a Leftmost Derivation? leftmost variable replaced at every step What's an Ambiguous Grammar? two or more leftmost derivations for the same string What's an Inherently Ambiguous Language? language that can only be generated by ambiguous grammar What's Chomsky Normal Form (CNF)? every rule is of the form A -> BC A -> a also allow S -> epsilon A, B, C are variables a is a terminal B, C cannot be start symbol Why is Chomsky Normal Form useful? algorithms that operate on grammars can be simpler proofs involving grammars can be simpler Chomsky Normal Form places restrictions on grammars. How can you prove that CNF grammars are equivalent to Context-Free Grammars? How can you prove that any Context-Free Language can be generated by a grammar in Chomsky Normal Form? What are the steps for converting a Context-Free Grammar into CNF? 1. Add new start symbol 2. Remove epsilon rules 3. Remove unit rules 4. Split rules into parts 5. Replace terminals with variables