=============================== 2nd Midterm and PA3 Post Mortem =============================== -------------------------------------------------------- Logistics If want to ask for any regrades then leave midterm with me. HW8 is due Monday. PA4 is due a week from Monday. Friday's recitation will be 1.5 hour HW8 and PA4 help session from 10-11:30. -------------------------------------------------------- Question 1 from Midterm Creating LL(1) expression grammars. Starting point (ambiguous expression grammar): E -> E + E | E = E | E - E | E * E | -E | (E) | NUM Steps to follow (1) Look up the precedence levels and order them from lowest to highest precedence. (2) Create a non-terminal in the grammar for each precedence level. Each precedence level should include a production for each operator at that level and a production that goes directly to the next higher-level of precedence. E1 -> ... | E2 E2 -> ... | E3 ... (3) The productions with operators need to be self recursive and if they are binary operators should also reference the next highest level of precedence. E1 -> E2 = E1 | E2 E2 -> E2 + E3 | E2 - E3 | E3 ... (4) Then the grammar needs converted to LL(1) through the use of left factoring and the removal of left recursion. ==> show that removing left recursion can be done in two ways Reference information: Eliminating ambiguity in expression grammars. Reading that was posted for October 4th. http://itu.dk/~mogel/SPLC2011/lectures/eliminatingAmbiguity.pdf Good text notes about this that take the approach of changing the left recursion into right recursion and the left factoring. https://www.cs.rochester.edu/~brown/173/readings/05_grammars.txt -------------------------------------------------------- Question 4 from Midterm Why don't we need to pass down the left AST for a right associative operator? We don't for unary right associative operators. However, we actually do for binary right associative operators? -------------------------------------------------------- Question 5 from Midterm Nullable, FIRST, FOLLOW, and Predictive parse table for the following: (1) prog -> stmtlist EOF (2) stmtlist -> stmtlist stmt (3) | epsilon (4) stmt -> EAT NUM mallow (5) | SAVE NUM mallow (6) mallow -> PINK STARS (7) | BLUE DIAMONDS ------------------------ mstrout@cs.arizona.edu, 11/1/16