Question: Translate the following four BL programs into their executable form in the tables next to each example using the code generation patterns discussed in class(especially
Translate the following four BL programs into their executable form in the tables next to each example using the code generation "patterns" discussed in class(especially slides 30-47).
http://web.cse.ohio-state.edu/software/2231/web-sw2/extras/slides/28.Code-Generation.pdf
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.) Note that the tables may be bigger than the actual length of the generated code.
PROGRAM Example1 IS BEGIN IF next-is-wall THEN turnright turnright infect END IF END Example1 |
|
PROGRAM Example2 IS BEGIN IF next-is-wall THEN turnright turnright infect ELSE infect move END IF END Example2 |
|
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 |
|
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 |
|
Step by Step Solution
There are 3 Steps involved in it
Translating the given BL BugsWorld Language programs into their executable form involves converting highlevel instructions into a sequence of bytecode instructions that the BugsWorld Virtual Machine c... View full answer
Get step-by-step solutions from verified subject matter experts
