This is an old revision of the document!
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.
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.
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
The homework is individual. Any attempt of copying will result in 0p for the homework. Automated anti copying system will be used.
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.
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.
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
The robot starts from (0, 0, 90) meaning the position (0, 0) and the rotation 90 degrees.
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
Moves the robot forward with a number of pixels
FORWARD pixels
It takes exactly one parameter
* pixels - an integer number representing the number of pixels to go forward
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)
Moves the robot backward a number of pixels
BACKWARD pixels
It takes exactly one parameter
* pixels - an integer number representing the number of pixels to go backward
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)
Turns the robot left (counter clockwise) or right (clockwise) a number of degrees
TURN left/right, degrees
It takes exactly two parameters
* left or right - written exactly like this * degrees - an integer number that represents the degrees to turn
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)
Put the robot on a specific position. It does not matter what orientation it has.
JUMP x, y
It takes exactly two parameters
* x - the x position of the robot
* y - the x position of the robot
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)
Repeats some lines of commands until END
REPEAT times
REPEAT commands are not imbricated (REPEAT in REPEAT)
It takes exactly one parameter
* times - an integer number specifying the number of times to repeat the commands up to END
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
Ends a repeat loop
It takes no parameters
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
For an additional 0.5p, implement the REPEAT imbrication (REPEAT in REPEAT).
The homework will be tested automatically using a set of public and private 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.
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
When uploading the homework, we might have some private tests that it needs to pass. vmchecker will run them.
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.
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.
To upload your homework, please follow the following:
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