CSE 321 Homework 14


Translate the following six BL programs into their executable form in the tables next to each example (i.e., as we did in class, use only the primitives: MOVE, TURNLEFT, TURNRIGHT, INFECT, SKIP, and HALT; unconditional jump: JUMP; and the conditional jumps: JUMP_IF_NOT_NEXT_IS_EMPTY, JUMP_IF_NOT_NEXT_IS_NOT_EMPTY, etc.)

PROGRAM Example1 IS
BEGIN
    IF next-is-wall THEN
        turnright
        turnright
        infect
    END IF
END Example1
0  
1  
2  
3  
4  
5  
6  
7  
8  
8  
10  

PROGRAM Example2 IS
BEGIN
    IF next-is-wall THEN
        turnright
        turnright
        infect
    ELSE
        infect
        move
    END IF
END Example2
0  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  








PROGRAM Example3 IS
BEGIN
    WHILE next-is-not-empty DO
        IF next-is-wall THEN
            turnright
            turnright
            infect
        ELSE
            infect
            move
        END IF
    END WHILE
END Example3
0  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  

PROGRAM Example4 IS

    INSTRUCTION TurnBackAndInfect IS
        turnright
        turnright
        IF next-is-enemy THEN
            infect
        END IF
    END TurnBackAndInfect

BEGIN
    WHILE true DO
        TurnBackAndInfect
    END WHILE
END Example4
0  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  




PROGRAM Example5 IS

    INSTRUCTION TryToInfect IS
        IF next-is-enemy THEN
            infect
        END IF
    END TryToInfect

    INSTRUCTION AdvanceIfPossible IS
        IF next-is-empty THEN
            move
        ELSE
            IF next-is-wall THEN
                turnleft
                turnleft
            END IF
        END IF
    END AdvanceIfPossible

BEGIN
    WHILE true DO
        TryToInfect
        AdvanceIfPossible
    END WHILE
END Example5
0  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  


















PROGRAM Example6 IS

    INSTRUCTION TurnBackAndInfect IS
        TurnBack
        TryToInfect
    END TurnBackAndInfect

    INSTRUCTION TryToInfect IS
        IF next-is-enemy THEN
            infect
        END IF
    END TryToInfect

    INSTRUCTION TurnBack IS
        turnright
        turnright
    END TurnBack

    INSTRUCTION AdvanceIfPossible IS
        IF next-is-empty THEN
            move
        ELSE
            TryToInfect
            TurnBackAndInfect
        END IF
    END AdvanceIfPossible

BEGIN
    WHILE true DO
        AdvanceIfPossible
    END WHILE
END Example6
0  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20