============= HW5 Questions ============= ------------------------------------------------ (Q8) Given the following Context Free Grammar: E -> E = E E -> E && E E -> ID Select the grammar below that correctly encodes the Java operator precedence and associativity for the two operators. http://www.cs.bilkent.edu.tr/~guvenir/courses/CS101/op_precedence.html = is right associative and has the lowest level of precedence in Java && is left associative and has precedence higher than = E1 -> E4 -> E15 -> ID ------------------------------------------------ (Q7) Given the following Context Free Grammar: Stm -> "print" Stm -> "print" What needs to be done to the grammar to enable parsing with an LL(1) parser? (A) Left refactoring (B) Encoding of associativity (C) Removal of Left Recursion (D) Encoding of precedence ------------------------------------------------ (Q1) Which of the following properly pattern matches against ONLY a WhileNode? Assume the following data structure declaration: data AST = WhileNode AST AST (A) codegen _ = ... (B) codegen (AST WhileNode) = ... (C) codegen WhileNode AST AST = ... (D) codegen (WhileNode) check body = ... (E) codegen (WhileNode check body) = ... (F) codegen n = ... ------------------------------------------------ (Q6) Which of the following properly pattern matches against ONLY a WhileNode? Using the MainParseToAST.hs code provided in a Piazza post on October 4th, what does the AST for the following input file look like when passed to print? print Meggy.Color.BLUE print Meggy.Color.BLUE print Meggy.Color.RED Question options: (A) StmList NIL (StmList (PrintStm 5) (StmList (PrintStm 5) (PrintStm 1))) (B) StmList (PrintStm 5) (StmList (PrintStm 5) (StmList (PrintStm 1) NIL)) (C) StmList [PrintStm 5, PrintStm 5, PrintStm 1] (D) StmList (PrintStm 1) (StmList (PrintStm 5) (StmList (PrintStm 5) NIL)) -------------------------------------------------- (Q2) Assume the following binary tree declaration: data BT = Leaf String | Node String BT BT Which of the following functions will print the strings associated with the nodes and leaves of the tree in order. printTree :: BT -> String printTree (Leaf s) = s printTree (Node s left right) = let left_string = printTree left right_string = printTree right in