CSE 321 Lab 2


Lab 2 Table of Contents


Part 1 - Table of Contents


Objective

The objective for this part of the assignment is to implement the Pretty_Print extension to the Statement component.


Overview

You will be implementing the Pretty_Print extension for statements.


Materials Provided

The set up instructions will provide you with a user catalog containing the following components and auxiliary items:

You will need to:

Feel free to add private operations as needed. To use a demonstration version of the test driver, just execute the command 321_Statement_Demo.


Set Up

  1. Copy the lab2-part1 course catalog to your group project directory (/project/c321axnn, where "x" is your section letter and "nn" is your team number):
    cp -r /class/sce/now/321/labs/catalogs/lab2-part1 /project/c321axnn
    
  2. Make sure that the new catalog will be accessible to your partner. Perform this action now and as your last act whenever you finish a working session. Note that 'l' in the chmod command is the letter 'l' ("el"), as in "lock":
    cd /project/c321axnn/lab2-part1
    
    chmod -R g-l,g+rwX .
    
    set-group-ID .
    
  3. Look around the new user catalog to familiarize yourself with its contents.


Using the Test Driver

Make sure that you fully understand the requires clauses for the Statement_Kernel operations before you use the test driver.

The test driver initializes an array from 0 through 9 of Statement. When using the driver, it will ask for the number of the object to which you would like to apply an operation. You should always respond with a value in the range 0 through 9. Here is an example:

Run in interactive mode (y/n)? y


Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: c
Compose into which object? 0
  ... instruction? infect

--------------------------------------------
                   |  instruction = infect
--------------------------------------------
statements0.Compose_Call (infect);  |
--------------------------------------------
                   |  instruction = 
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: a
Add to which object? 1
  ... position? 0
  ... object? 0

--------------------------------------------
                   |  position = 0
--------------------------------------------
statements1.Add_To_Block (position, statements0);  |
--------------------------------------------
                   |  position = 0
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: c
Compose into which object? 2
  ... instruction? turnleft

--------------------------------------------
                   |  instruction = turnleft
--------------------------------------------
statements2.Compose_Call (turnleft);  |
--------------------------------------------
                   |  instruction = 
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: a
Add to which object? 3
  ... position? 0
  ... object? 2

--------------------------------------------
                   |  position = 0
--------------------------------------------
statements3.Add_To_Block (position, statements2);  |
--------------------------------------------
                   |  position = 0
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: e
Compose into which object? 4
  ... operator value, enter
          a ... for NEXT_IS_EMPTY
          b ... for NEXT_IS_NOT_EMPTY
          c ... for NEXT_IS_WALL
          d ... for NEXT_IS_NOT_WALL
          e ... for NEXT_IS_FRIEND
          f ... for NEXT_IS_NOT_FRIEND
          g ... for NEXT_IS_ENEMY
          h ... for NEXT_IS_NOT_ENEMY
          i ... for RANDOM
          j ... for TRUE
      ? g
  ... if body object? 1
  ... else body object? 3

--------------------------------------------
                   |  condition = NEXT_IS_ENEMY
--------------------------------------------
statements4.Compose_If_Else (cond, statements1, statements3);  |
--------------------------------------------
                   |  condition = NEXT_IS_EMPTY
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: a
Add to which object? 5
  ... position? 0
  ... object? 4

--------------------------------------------
                   |  position = 0
--------------------------------------------
statements5.Add_To_Block (position, statements4);  |
--------------------------------------------
                   |  position = 0
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: w
Compose into which object? 6
  ... operator value, enter
          a ... for NEXT_IS_EMPTY
          b ... for NEXT_IS_NOT_EMPTY
          c ... for NEXT_IS_WALL
          d ... for NEXT_IS_NOT_WALL
          e ... for NEXT_IS_FRIEND
          f ... for NEXT_IS_NOT_FRIEND
          g ... for NEXT_IS_ENEMY
          h ... for NEXT_IS_NOT_ENEMY
          i ... for RANDOM
          j ... for TRUE
      ? j
  ... body object? 5

--------------------------------------------
                   |  condition = TRUE
--------------------------------------------
statements6.Compose_While (cond, statements5);  |
--------------------------------------------
                   |  condition = NEXT_IS_EMPTY
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: p
Pretty_Print which object? 6
  ... indentation factor (>= 0)? 5

--------------------------------------------
statements6 = 
     WHILE true DO
         IF next-is-enemy THEN
             infect
         ELSE
             turnleft
         END IF
     END WHILE

--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: k
Kind for which object? 6

--------------------------------------------
                   |  kind = ?
--------------------------------------------
kind = statements6.Kind ();    |
--------------------------------------------
                   |  kind = WHILE
--------------------------------------------

Command: s [Swap]
         p [Pretty_Print]
         a [Add_To_Block]
         r [Remove_From_Block]
         l [Length_Of_Block]
         i [Compose_If]
         I [Decompose_If]
         e [Compose_If_Else]
         E [Decompose_If_Else]
         w [Compose_While]
         W [Decompose_While]
         c [Compose_Call]
         C [Decompose_Call]
         k [Kind]
         q [Quit]: q


What To Submit

Once you and your partner are convinced that all implementations are working correctly, get into your group's lab2-part1 directory /project/c321axnn/lab2-part1 in an xterm window and use the rcpp-submit command to submit your solution as follows (noting that you will need to use the appropriate suffix in place of ?? in this command, as posted next to your instructor's name on the CSE 321 Home Page):
rcpp-submit c321?? lab2-part1
If you get an error message rather than a confirmation of success, please read the message; it contains useful information! Do not just run the same command again. Save the e-mail you get as a receipt of submission, just in case.


Part 2 - Table of Contents


Objective

The objective for this assignment is to layer an implementation of the Statement component over the Tree component.


Overview

You will be implementing the Statement kernel component.

In implementing Statement_Kernel_1, you will be using a tree as the representation of statements. The items in the representation tree will be records with three fields: one field for the kind of statement, one field for a condition (used when the statement is an if, if-else, or while), and one field for an instruction (used when the statement is an instruction call).


Materials Provided

The set up instructions will provide you with a user catalog containing the following components and auxiliary items:

You will need to:

Feel free to add private operations as needed. To use a demonstration version of the test driver, just execute the command 321_Statement_Demo.


Set Up

  1. Copy the lab2-part2 course catalog to your group project directory (/project/c321axnn, where "x" is your section letter and "nn" is your team number):
    cp -r /class/sce/now/321/labs/catalogs/lab2-part2 /project/c321axnn
    
  2. Make sure that the new catalog will be accessible to your partner. Perform this action now and as your last act whenever you finish a working session. Note that 'l' in the chmod command is the letter 'l' ("el"), as in "lock":
    cd /project/c321axnn/lab2-part2
    
    chmod -R g-l,g+rwX .
    
    set-group-ID .
    
  3. Look around the new user catalog to familiarize yourself with its contents.


Using the Test Driver

The test driver is the same used in Part 1.


What To Submit

Once you and your partner are convinced that all implementations are working correctly, get into your group's lab2-part2 directory /project/c321axnn/lab2-part2 in an xterm window and use the rcpp-submit command to submit your solution as follows (noting that you will need to use the appropriate suffix in place of ?? in this command, as posted next to your instructor's name on the CSE 321 Home Page):
rcpp-submit c321?? lab2-part2
If you get an error message rather than a confirmation of success, please read the message; it contains useful information! Do not just run the same command again. Save the e-mail you get as a receipt of submission, just in case.