This is an old revision of the document!
The purpose of the homework is to write an interpreter for the Design language. The language is used to draw geometric figures and and points.
Write an interpreter that receives a file with statements as parameter and writes a SVG file. If there was an error, it will output ERROR LINE followed by the line number: and the error text.
The program receives two parameters:
A usage example:
node main.js design.dsn canvas.svg
This will run the design.dsn file and write the drawing into the canvas.svg file.
For this design.dsn file
& Move LOCATION: 200, 200 COMMAND_WITH_ERROR DRAW_LINE: location 300, 350
the interpreter should output
LINE 2 HAS ERROR: Command not existing COMMAND_WITH_ERROR
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 with the title format [design] <your question title>. 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 language is actually moving a pen. The pen's initial position is 0, 0. When drawing, the pen will move to the new position.
The commentaries are preceded by &.
& There is a comment on this line STATEMENT: p1 p2 STATEMENT: p1 p2
All statements accept as parameters numbers or variables. Variables have the following format:
$variable
Before it can be used, a variable needs to be assigned a value (using the init statement).
Statements are stored inside a file. Each statement is on a separate line.
The format for a statement is the following:
STATEMENT : parameter1 parameter2 etc
Statements may have any number of spaces before their name, between parameters and any number of spaces after the last parameter. Here are some examples of valid statements:
STATEMENT: p1 p2 p3 STATEMENT : p1 p2 p3 STATEMENT:p1 p2 p3
All statements and parameters are case insensitive.
Moves the pen to a position, without drawing anything.
The parameters are x and y.
LOCATION: 150 150 POSITION: $here $there & $here and $there are variables that are previously assigned
Wrong number of parameters
LINE (line_number) HAS ERROR: LOCATION uses 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter type
LINE (line_number) HAS ERROR: LOCATION parameter (the number of the parameter) needs to be a variable or a number, you wrote (actual_written_parameter_value)
Draws a line from the current position to a specified position or length and angle. This will be the new position of the pen.
DRAW_LINE: x y location DRAW_LINE: l a polar
It takes exactly three parameters
Wrong number of parameters
LINE (line_number) HAS ERROR: DRAW_LINE command needs 3 parameters, you wrote (number_of_written_parameters)
Wrong parameter type for the type of the command
LINE (line_number) HAS ERROR: DRAW_LINE parameter 3 needs to be one of (location, polar), you wrote (actual_written_parameter_value)
Wrong parameter type
LINE (line_number) HAS ERROR: DRAW_LINE parameter (the number of the parameter) needs to be a number or a variable, you wrote (actual_written_parameter_value)
Draw a circle
This does not move the current position.
DRAW_CIRCLE: r x y
It takes exactly three parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: DRAW_CIRCLE needs 3 parameters, you wrote (number_of_written_parameters)
Wrong parameter type
LINE (line_number) HAS ERROR: DRAW_CIRCLE parameter (the number of the parameter) needs to be a number or a variable, you wrote (actual_written_parameter_value)
Draw an ellipse
This does not move the current position.
DRAW_ELLIPSE: r1 r2 x y
It takes exactly four parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: DRAW_ELLIPSE needs 3 parameters, you wrote (number_of_written_parameters)
Wrong parameter type
LINE (line_number) HAS ERROR: DRAW_ELLIPSE parameter (the number of the parameter) needs to be a number or a variable, you wrote (actual_written_parameter_value)
Draw a rectangle
This does not move the current position.
DRAW_RECTANGLE: x1 y1 x2 y2
It takes exactly four parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: DRAW_RECTANGLE needs 4 parameters, you wrote (number_of_written_parameters)
Wrong parameter type
LINE (line_number) HAS ERROR: DRAW_RECTANGLE parameter (the number of the parameter) needs to be a number or a variable, you wrote (actual_written_parameter_value)
Selects the drawing color. This will be the new position of the pen.
The initial pen color is black. The initial fill color is white.
SET_COLOR: r g b pen SET_COLOR: r g b fill
It takes exactly four parameters
Values are between 0 and 255.
Wrong number of parameters
LINE (line_number) HAS ERROR: SET_COLOR needs 4 parameters, you wrote (number_of_written_parameters)
Wrong parameter type for type
LINE (line_number) HAS ERROR: SET_COLOR parameter 4 needs to be one of (pen, fill), you wrote (actual_written_parameter_value)
Wrong parameter type
LINE (line_number) HAS ERROR: SET_COLOR parameter (the number of the parameter) needs to be a number or a variable, you wrote (actual_written_parameter_value)
Value of of range
LINE (line_number) HAS ERROR: SET_COLOR parameter (the number of the parameter) needs to be a number or a variable between [0, 255], you wrote (actual_written_parameter_value, if it is a variable write the value of the variable)
Repeats some lines of statements until REPEAT
FOR_LOOP: times
FOR_LOOP statements are not imbricated (FOR_LOOP in FOR_LOOP)
It takes exactly one parameter
* times - an integer number or a variable specifying the number of times to repeat the statements up to REPEAT
Wrong number of parameters
LINE (line_number) HAS ERROR: FOR_LOOP needs 1 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: FOR_LOOP parameter 1 needs to be a number or a variable, you wrote (actual_written_parameter_value)
The file ends and there still is at least one LOOP without REPEAT
You have number_of_repeats FOR_LOOP without REPEAT
Repeats some lines of statements until REPEAT
WHILE: variable
WHILE statements are not imbricated (WHILE in WHILE)
It takes exactly one parameter
* variable - a variable, if the variable is different from 0, repeat the statements up to REPEAT
Wrong number of parameters
LINE (line_number) HAS ERROR: WHILE needs 1 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: WHILE parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
The file ends and there still is at least one WHILE without REPEAT
You have number_of_repeats WHILE without REPEAT
Ends a loop or a while
It takes no parameters
Wrong number of parameters
LINE (line_number) HAS ERROR: REPEAT needs 0 parameters, you wrote (number_of_written_parameters)
REPEAT is used without a previous FOR_LOOP or WHILE
LINE (line_number) HAS ERROR: REPEAT and no WHILE/FOR_LOOP
Execute some lines of statements until ELSE or END
IF: variable
IF statements are not imbricated (IF in IF)
It takes exactly one parameter
* variable - a variable, if the variable is different from 0, execute the statements up to ELSE or END (if there is no ELSE)
Wrong number of parameters
LINE (line_number) HAS ERROR: IF needs 1 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: IF parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
The file ends and there still is at least one IF without ELSE or END
You have number_of_repeats IF without END
Else part of the if
It takes no parameters
Wrong number of parameters
LINE (line_number) HAS ERROR: ELSE needs 0 parameters, you wrote (number_of_written_parameters)
END is used without a previous IF
LINE (line_number) HAS ERROR: ELSE and no IF
Ends an if
It takes no parameters
Wrong number of parameters
LINE (line_number) HAS ERROR: END needs 0 parameters, you wrote (number_of_written_parameters)
END is used without a previous IF
LINE (line_number) HAS ERROR: END and no IF
Sets the value of a variable
INIT: variable value
It takes exactly two parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: INIT needs 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: INIT parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
Wrong parameter for times
LINE (line_number) HAS ERROR: INIT parameter 2 needs to be a number or a variable, you wrote (actual_written_parameter_value)
Add a value to the value of a variable
ADDITION: variable value
It takes exactly two parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: ADDITION needs 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: ADDITION parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
Wrong parameter for times
LINE (line_number) HAS ERROR: ADDITION parameter 2 needs a number or a variable, you wrote (actual_written_parameter_value)
Subtract a value from the value of a variable
SUBTRACTION: variable value
It takes exactly two parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: SUBTRACTION needs 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: SUBTRACTION parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
Wrong parameter for times
LINE (line_number) HAS ERROR: SUBTRACTION parameter 2 needs to be a number or a variable, you wrote (actual_written_parameter_value)
Multiply a variable's value with a value.
MULTIPLY: variable value
It takes exactly two parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: MULTIPLY needs 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: MULTIPLY parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
Wrong parameter for times
LINE (line_number) HAS ERROR: MULTIPLY parameter 2 needs to be a number or a variable, you wrote (actual_written_parameter_value)
Divide the value of a variable with a value
DIVISION: variable value
It takes exactly two parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: DIVISION needs 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: DIVISION parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
Wrong parameter for times
LINE (line_number) HAS ERROR: DIVISION parameter 2 needs to be a number or a variable, you wrote (actual_written_parameter_value)
Divide the value of a variable with a value (integer value)
IDIVISION: variable value
It takes exactly two parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: IDIVISION needs 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: IDIVISION parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
Wrong parameter for times
LINE (line_number) HAS ERROR: IDIVISION parameter 2 needs to be a number or a variable, you wrote (actual_written_parameter_value)
The remainder of the division of a variable with a value
MODULO: variable value
It takes exactly two parameter
Wrong number of parameters
LINE (line_number) HAS ERROR: MODULO needs 2 parameters, you wrote (number_of_written_parameters)
Wrong parameter for times
LINE (line_number) HAS ERROR: MODULO parameter 1 needs to be a variable, you wrote (actual_written_parameter_value)
Wrong parameter for times
LINE (line_number) HAS ERROR: MODULO parameter 2 needs to be a number or a variable, you wrote (actual_written_parameter_value)
For an additional 0.20p, implement the FOR_LOOP, WHILE and IF imbrication.
The homework will be tested automatically using a set of public and private tests.
Coming soon…
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