0% found this document useful (0 votes)
27 views6 pages

P0

The document describes a programming language and robot simulator for a project. The language allows defining variables, procedures, and programs to control a robot in a 2D grid. A valid program example is provided that includes variable and procedure definitions to move the robot and drop/place objects. The task is to implement a parser in Python or Java that verifies the syntax and checks for correctly defined names in a given robot program file.

Uploaded by

Carlos Diaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

P0

The document describes a programming language and robot simulator for a project. The language allows defining variables, procedures, and programs to control a robot in a 2D grid. A valid program example is provided that includes variable and procedure definitions to move the robot and drop/place objects. The task is to implement a parser in Python or Java that verifies the syntax and checks for correctly defined names in a given robot program file.

Uploaded by

Carlos Diaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ISIS-1106 Lenguajes y máquinas

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.

Figure 1: Initial state of the robot’s world


ISIS-1106 Lenguajes y máquinas
Project 0
Fecha: August 21, 2023

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.

• G(x,y): to go to position (x,y). Position (x,y) should not have an obstacle.

The interpreter controls the robot through the class uniandes.lym.robot.kernel.


RootWorldDec
Figure 2 shows the robot before executing the commands that appear in the text box
area at the bottom of the interface.
Figure 3 shows the robot after executing the aforementioned sequence of commands.
The text area in the middle of the figure displays the commands executed by the robot.
Below we define a language for programs for the robot.
A program for the robot is simply a sequence of blocks of commands and definitions.

• A definition can be a variable defintion or a procedure definition.

– 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.

• A block of commands is a sequence of commands separated by semicolons within


curly brackets .
ISIS-1106 Lenguajes y máquinas
Project 0
Fecha: August 21, 2023

Figure 2: Robot before executing commands

Figure 3: Robot executed commands


ISIS-1106 Lenguajes y máquinas
Project 0
Fecha: August 21, 2023

• A value is a number or a previously defined variable

• Command can be a simple command, a control structure or a procedure call

– A simple command can be any one of the following:


∗ An assignment which is of the form name = v where name is a variable’s
name and n is a value. The result of this instruction is to assign the value
of to the variable.
∗ jump(x,y) – where x and y are values. The robot should go to position
(x, y).
∗ walk(v) – where v is a value. The robot should move v steps forward.
∗ walk(v, D) – where v is a value. D is a direction, either front, right, left,
back. The robot should move n positions to the front, to the left, the right
or back and end up facing the same direction as it started.
∗ walk (v, O) – where v is a value. O is north, south, west, or east. The
robot should face O and then move n steps forward.
∗ leap(v) – where v is a value. The robot should jumo v steps forward.
∗ leap(v, D) – where v is a value. D is a direction, either front, right, left,
back. The robot should jump n positions to the front, to the left, the right
or back and end up facing the same direction as it started.
∗ leap (v, O) – where v is a value. O is north, south, west, or east. The
robot should face O and then move n steps.
∗ turn(D) – where D can be left, right, or around. The robot should turn 90
degrees in the direction of the parameter.
∗ turnto(O) – where O can be north, south, east or west. The robot should
turn so that it ends up facing direction O.
∗ drop(v) – where v is a value. The robot should drop v chips.
∗ get(v) – where v is a value. The robot should pickup v chips.
∗ grab(v) – where v is a value. The robot should pick v balloons.
∗ letGo(v) – where v is a value. The robot put v balloons.
∗ nop() The robot does not do anything.
– a procedure is invoked using the procedure’s name followed by followed by its
arguments in parenthesis separated by commas.
– A control structure can be:
Conditional: if condition Block1 else Block2 – Executes Block1 if condition
is true and Block2 if condition is false.
ISIS-1106 Lenguajes y máquinas
Project 0
Fecha: August 21, 2023

Loop: while condition Block – Executes Block while condition is true.


RepeatTimes: repeat v times Block – Executes Block n times, where v is
a value.
– A condition can be:
∗ facing(O) – where O is one of: north, south, east, or west
∗ can(C) – where C is a simple command. This condition is true when the
simple command can be executed without error.
∗ not: cond – where cond is a condition

Spaces, newlines, and tabulators are separators and should be ignored.


The language is not case-sensitive. This is to say, it does not distinguish between
upper and lower case letters.
Remember the robot cannot walk over obstacles, and when leaping it cannot land on
an obstacle. The robot cannot walk off the boar or land off the board when leaping.

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.

Below we show an example of a valid program.


ISIS-1106 Lenguajes y máquinas
Project 0
Fecha: August 21, 2023

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 {

16 while can(walk (1 , north ) ) { walk (1 , north ) }

18 }

20 defProc goWest ()
21 {

23 i f can(walk (1 , west ) ) { walk (1 , west ) } e l s e nop ()

25 }

27 {
28 jump (3 ,3) ;
29 putCB (2 ,1)
30 }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy