CSE 321 Homework 9


  1. Given the following BL statements, draw the corresponding abstract syntax trees as defined by the mathematical model of Statement_Kernel (STATEMENT).

    1.     WHILE next-is-enemy DO
              infect
              TurnAround
              move
              turnright
          END WHILE
      
    2.     IF next-is-friend THEN
              turnright
              turnright
              WHILE true DO
                  infect
              END WHILE
          END IF
      
    3.     IF next-is-not-empty THEN
              turnleft
              turnleft
          ELSE
              WHILE next-is-empty DO
                  move
              END WHILE
              IF next-is-enemy THEN
                  infect
              END IF
              skip
          END IF
      
  2.  

  3. Carefully read the AT/Statement/Pretty_Print.h section in the 321 class notes where the Statement_Pretty_Print component is described.

    Show exactly what output Pretty_Print will append to the output stream out when called on the statement on the next page (with indentation_factor = 3). Make sure that you clearly show where and how many spaces are printed.

  4. Read the Program section in the 321 class notes where the Program component is described. Concentrate on the Program_Kernel component and the kernel operations. For now, you can ignore the Generate_Code, Parse, and Pretty_Print components.

    Then explain clearly in English what the initial value of a Program object is.