CSE 305 Programming Languages Fall, 2003 Professor Shapiro Homework 2 Maximum Points: 15 Due 9:30 am, Thursday, September 18, 2003 at the start of Lecture Write the answers to this homework set on one or more 8.5 x 11 inch sheets of paper, and turn them in at the start of lecture on the date given above. If you need more than one sheet of paper, use one side only, and staple the sheets together at the upper left-hand corner. Identify your answers clearly with the course, your name, and your recitation (R1, R2, or R3). Illegible answers will be considered incorrect. If your answer to some question is based on some source material, including a book or web site, cite the source as part of your answer. The point value of each question is shown in parentheses. 1. (3) (3.2a of the text) Write an EBNF grammar for a Java class definition header. (For example the class definition header of the program Echo.Java, from hw1, is public class Echo ) 2. (3) (3.3 of the text) Rewrite the BNF of Example 3.4 to give + precedence over * and force + to be right associative. 3. (3) (3.4 of the text) Rewrite the BNF of Example 3.4 to add the ++ and -- unary operators of Java. (Clarification, 9/15/03, both prefix and postfix ++ and --.) 4. (3) (3.7.d of the text) Using the grammar in Example 3.4, show a parse tree for the statement, A = B * (C * (A + B)) 5. (3) Using the unambiguous grammar at the top of page 128 of the text, show a parse tree for the sentence shown in Figure 3.5 of the text. Clarification (9/15/03): Use this grammar: -> | -> if then else | -> if then | if then else On this sentential form: if then if then else