This is an old revision of the document!


Homework 2 - Robot Language

Information

Deadline: 22th of March, 23:55
Points: 1 point out of the final grade
Upload the homework: vmchecker.cs.pub.ro
Late upload: 0.1 points / day (maximum 4 days)

What do you have to do

The purpose of the homework is to write an interpreter for the Robot language. The language is used to move a robot on a flat plane. The robot can go forward, backwards, turn or jump.

Write an interpreter that receives a file with commands as parameter and writes to the screen the position and rotation of the robot after each command.

  • If the command was successful, it will output OK x, y, r (exactly like this)
  • If there was an error, it will output ERROR LINE followed by the line number: and the error text.
node main.js robot_commands.s

This will run the robot_commands.s file and write to the screen the position and rotation of the robot after every command or an error for the lines that have errors.

Line endings in the commands file are Linux like, meaning just \n.

Example

For this robot.s file

# Move
FORWARD 200
COMMAND_WITH_ERROR 
BACKWARD 10

the interpreter should output

OK 200, 0, 90
ERROR LINE 2: Unknown command COMMAND_WITH_ERROR
OK 190, 0, 90

Rules

  1. You may not use RegEx or any other library that would use regular expressions
  2. Files must have “use strict”
  3. You files need to pass jshint (with node: true, esnext: true)
  4. Source code needs to be indented (-0.1p)
  5. You need to write a file named Readme and explain how you wrote the homework (-0.1p)

Copying

The homework is individual. Any attempt of copying will result in 0p for the homework. Automated anti copying system will be used.

Questions

If you have any questions related to the homework, please ask them by posting an issue on the github repository. You will need a github account for that.

DO NO POST ANY CODE. This is considered copying and will result in a 0p homework for you.

If you want to receive an email when issues are posted or when there are new messages, got to the github repository and click Watch.

Robot Language

Robot Position

The robot has a position and a rotation. The position is expressed by a (x, y) pair expressed as integer numbers. The rotation of the robot is expressed in degrees and varies between 0 and 360.

The status of the robot is expressed as (x, y, r), meaning: * x, y the position * r the rotation in degrees

Starting Point

The robot starts from (0, 0, 90) meaning the position (0, 0) and the rotation 90 degrees.

Commands format

Commands are stored inside a file. Each command is on a separate line.

The format for a robot command is the following:

  COMMAND parameter1,parameter2,etc

Commands may have any number of spaces before it's name, between parameters and any number of spaces after the last parameter. Here are some examples of valid commands:

  COMMAND p1,    p2,  p3
    COMMAND p1, p2,   p3    
  COMMAND     p1,p2,p3

Commands

FORWARD

Moves the robot forward with a number of pixels

Syntax
FORWARD pixels
Parameters

It takes exactly one parameter

* pixels - an integer number representing the number of pixels to go forward

Errors

Wrong number of parameters

ERROR LINE (line_number):FORWARD has 2 parameters, you wrote (number_of_written_parameters)

Wrong parameter type for pixels

ERROR LINE (line_number): FORWARD parameter 1 requires a number, you wrote (actual_written_parameter_value)

BACKWARD

Moves the robot backward a number of pixels

Syntax
BACKWARD pixels
Parameters

It takes exactly one parameter

* pixels - an integer number representing the number of pixels to go backward

Errors

Wrong number of parameters

ERROR LINE (line_number): BACKWARD has 1 parameters, you wrote (number_of_written_parameters)

Wrong parameter type for pixels

ERROR LINE (line_number): BACKWARD parameter 1 requires a number, you wrote (actual_written_parameter_value)

TURN

Turns the robot left (counter clockwise) or right (clockwise) a number of degrees

Syntax
TURN left/right, degrees
Parameters

It takes exactly two parameters

* left or right - written exactly like this * degrees - an integer number that represents the degrees to turn

Errors

Wrong number of parameters

ERROR LINE (line_number): TURN has 2 parameters, you wrote (number_of_written_parameters)

Wrong parameter for left/right

ERROR LINE (line_number): TURN parameter 1 requires a left/right, you wrote (actual_written_parameter_value)

Wrong parameter for degrees

ERROR LINE (line_number): TURN parameter 2 requires a number, you wrote (actual_written_parameter_value)

JUMP

Put the robot on a specific position. It does not matter what orientation it has.

JUMP x, y
Parameters

It takes exactly two parameters

* x - the x position of the robot

  • the value may be ~ (tilde) or an integer number
  • ~ means it keeps its previous x position

* y - the x position of the robot

  • the value may be ~ (tilde) or an integer number
  • ~ means it keeps its previous y position
Errors

Wrong number of parameters

ERROR LINE (line_number): JUMP has 2 parameters, you wrote (number_of_written_parameters)

Wrong parameter for x

ERROR LINE (line_number): JUMP parameter 1 requires a number, you wrote (actual_written_parameter_value)

Wrong parameter for y

ERROR LINE (line_number): JUMP parameter 2 requires a number, you wrote (actual_written_parameter_value)

REPEAT

Repeats some lines of commands until END

REPEAT times

REPEAT commands are not imbricated (REPEAT in REPEAT)

Parameters

It takes exactly one parameter

* times - an integer number specifying the number of times to repeat the commands up to END

Errors

Wrong number of parameters

ERROR LINE (line_number): REPEAT has 1 parameters, you wrote (number_of_written_parameters)

Wrong parameter for times

ERROR LINE (line_number): REPEAT parameter 1 requires a number, you wrote (actual_written_parameter_value)

The file ends and there still is at least one REPEAT without END

You have number_of_repeats REPEAT without END

END

Ends a repeat loop

Parameters

It takes no parameters

Errors

Wrong number of parameters

ERROR LINE (line_number): END has 0 parameters, you wrote (number_of_written_parameters)

END is used without a previous REPEAT

ERROR LINE (line_number): END and no REPEAT

Bonus

For an additional 0.5p, implement the REPEAT imbrication (REPEAT in REPEAT).

Bonus will be awarded only if all other tests pass.

Testing

The homework will be tested automatically using a set of public and private tests.

Public Tests

You can download the public tests from the GitHub repository.

To run the tests, download the contents of the repository in the folder with the homework. Enter the verify folder and run ./run_all.sh.

cd verify
./run_all.sh

You will need bash for that. You can use either Linux or Windows Linux Subsystem.

To install nodejs in Linux or Windows Linux Subsystem, do the following:

wget https://nodejs.org/dist/v6.10.0/node-v6.10.0-linux-x64.tar.xz
tar xvfJ node-v6.10.0-linux-x64.tar.xz
cd node-v6.10.0-linux-x64
sudo cp -R * /usr

Private Tests

When uploading the homework, we might have some private tests that it needs to pass. vmchecker will run them.

You may always upload the homework as many times you want until the deadline. This will run all the tests for you and display the result.

Upload the homework

The homework needs to be uploaded to vmchecker. Login with your moodle user name, select the Automates et Langages Formelles (FILS) course and upload the homework archive.

Readme

The readme file has the following format:

Your full name
Group

An explanation how you wrote your homework, what did you use, what are the main ideas.

Homework Archive

To upload your homework, please follow the following:

  1. Create a zip (not rar, ace, 7zip or anything else) archive containing:
    • your main file (main.js)
    • your javascript files (*.js)
    • yarn.lock (if you are using yarn)
    • the package.json file
    • the Readme file
  2. sign in with vmchecker
  3. select the Automates et Langages Formelles (FILS) course
  4. select 1. Langage Robot
  5. upload the archive

The archive needs to contain the files in its root, not in a folder. DO NOT archive a folder with those file, archive DIRECTLY those files.

DO NOT include node_modules.

When the archive is uploaded, vmchecker will run:

unzip archive.zip homework
cd homework
# if the file yarn.lock exists
yarn
# else
npm install
echo '{ "node":true, "esnext":true }' > .jshintrc
jshint *.js
alf/teme/tema_en_2.1583677770.txt.gz · Last modified: 2020/03/08 16:29 by alexandru.radovici
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0