P0
P0
Project 0
Fecha: August 21, 2023
Throughout this course we will develop a project in several stages. The project consists
of managing and operating a language to program a factory robot in a two-dimensional
world. The robot is able to move in the world (delimited by an n × n matrix); the robot
moves from cell to cell. Cells are indexed by rows and columns. The top left cell is indexed
as (1,1). North is top; West is left. The robot interacts (picks and puts down) with two
different types of objects (chips and balloons). Additionally, note that the robot cannot
move on, or interact with obstacles in the world (gray cells).
Robot Description
In this project, Project 0, we will try to understand the robot language. That is, given
a program for the robot, we will like to see if this satisfies the language specification and
robot behavior, explained in the following.
Figure 1 shows the robot facing North in the top left cell. The robot carries chips and
balloons which he can put and pickup. Chips fall to the bottom of the columns. If there
are chips already in the column, chips stack on top of each other (there can only be one
chip per cell). Balloons float in their cell, there can be more than one balloon in a single
cell.
The attached Java project includes a simple interpreter for the robot. The interpreter
reads a sequence of instructions and executes them. An instruction is a command followed
by “;”.
A command can be any one of the following:
• M: to move forward
• R: to turn right
• C: to drop a chip
• B: to place a balloon
• c: to pickup a chip
• b: to grab a balloon
• P: to pop a balloon
• J(n): to jump forward n steps. It may jump over obstacles, but the final position
should not have an obstacle.
– A variable definition starts with the keyword defVar followed by a name fol-
lowed by an initial value.
– A procedure definition starts with the keyword defProc followed by by a name,
followed by a list of parameter in parenthesis separated by commas, followed
by a block of commands.
Task 1. The task of this project is to use Python or Java to implement a simple yes/no
parser. You may not use JavaCC to implement the parser. The program should read a
text file that contains a program for the robot, and verify whether the syntax is correct.
You must verify that used function names and variable names have been previously
defined or in the case of functions, that they are the function’s arguments. You must
allow recursion.
Spaces and tabulators are separators and should be ignored.
1 defVar nom 0
2 defVar x 0
3 defVar y 0
4 defVar one 0
6 defProc putCB (c , b )
7 {
8 drop( c ) ;
9 letGo ( b ) ;
10 walk( n )
11 }
13 defProc goNorth ()
14 {
18 }
20 defProc goWest ()
21 {
25 }
27 {
28 jump (3 ,3) ;
29 putCB (2 ,1)
30 }