commmand -> commmand THEN commmand | commmand AFTER commmand | ( commmand ) | basic basic -> FORWARD n | LEFT n | RIGHT n | BACK nwhere n is any positive whole number. The robot is always facing north, south, east or west; the meaning of the commands is as follows:
| c1 THEN c2 | Perform c1 followed by c2 |
| c1 AFTER c2 | Perform c2 followed by c1 |
| FORWARD n | Move forward n steps |
| LEFT n | Turn left through 90o, and move n steps |
| RIGHT n | Turn right through 90o, and move n steps |
| BACK n | Turn through 180oand move n steps |
Assume that the robot starts in position (0,0) facing north. Write a program that calculates the distance a robot travels from the origin after a sequence of commands.
Solution: infix-to-prefix, infix-to-postfix