The objective for this part of the assignment is to implement the Pretty_Print extension to the Statement component.
You will be implementing the Pretty_Print extension for statements.
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.
cp -r /class/sce/now/321/labs/catalogs/lab2-part1 /project/c321axnn
cd /project/c321axnn/lab2-part1 chmod -R g-l,g+rwX . set-group-ID .
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
rcpp-submit c321?? lab2-part1If 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.
The objective for this assignment is to layer an implementation of the Statement component over the Tree component.
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).
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.
cp -r /class/sce/now/321/labs/catalogs/lab2-part2 /project/c321axnn
cd /project/c321axnn/lab2-part2 chmod -R g-l,g+rwX . set-group-ID .
The test driver is the same used in Part 1.
rcpp-submit c321?? lab2-part2If 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.