This is an old revision of the document!


Homework 2 - Design Language

Information

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

What do you have to do

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:

  • the file with statements
  • the svg output file

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.

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

Example

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

Initial values

  • The initial position is 0, 0.
  • The initial pen color is black.
  • The initial fill color is white.
  • The pen width is 1.

Rules

  1. Files must have “use strict”
  2. You files need to pass jshint (with node: true, esnext: true)
  3. Source code needs to be indented (-0.1p)
  4. 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 with the title format [design] <your question title>. 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.

Design Language

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.

Commentaries

The commentaries are preceded by &.

& There is a comment on this line 
STATEMENT: p1 p2
STATEMENT: p1 p2

Variables

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 format

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.

Statements

LOCATION

Moves the pen to a specific location, without drawing anything.

Syntax

The parameters are x and y.

LOCATION: 150 150
LOCATION: $here $there
& $here and $there are variables that are previously assigned
Errors

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)

DRAW_LINE

Draws a line from the current position to a specified position or length and angle. This will be the new position of the pen.

Syntax
DRAW_LINE: x y location 
DRAW_LINE: l a polar
Parameters

It takes exactly three parameters

  • x - if type is position, the x coordinate of the new position
  • y - if type is position, the y coordinate of the new position
  • l - if type is polar, the length of the line
  • a - if type is polar, the angle (from the trigonometric circle) in degrees
  • type - is either location either polar
Errors

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_CIRCLE

Draw a circle

This does not move the current position.

Syntax
DRAW_CIRCLE: r x y
Parameters

It takes exactly three parameter

  • r - the radius
  • x - the x coordinate for the center
  • y - the y coordinate for the center
Errors

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_ELLIPSE

Draw an ellipse

This does not move the current position.

Syntax
DRAW_ELLIPSE: r1 r2 x y
Parameters

It takes exactly four parameter

  • r1 - the horizontal radius
  • r2 - the vertical radius
  • x - the x coordinate for the center
  • y - the y coordinate for the center
Errors

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_RECTANGLE

Draw a rectangle

This does not move the current position.

Syntax
DRAW_RECTANGLE: x1 y1 x2 y2
Parameters

It takes exactly four parameter

  • x1 - the x coordinate of the top left corner
  • y1 - the y coordinate of the top left corner
  • x2 - the x coordinate of the lower right corner
  • y2 - the y coordinate of the lower right corner
Errors

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)

SET_COLOR

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.

Syntax
SET_COLOR: r g b pen
SET_COLOR: r g b fill
Parameters

It takes exactly four parameters

  • r - the red component of the color
  • g - the green component of the color
  • b - the blue component of the color
  • type - is either pen (the color of the line or broder) either fill (the color inside)

Values are between 0 and 255.

Errors

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)

FOR_LOOP

Repeats some lines of statements until REPEAT

FOR_LOOP: times

FOR_LOOP statements are not imbricated (FOR_LOOP in FOR_LOOP)

Parameters

It takes exactly one parameter

* times - an integer number or a variable specifying the number of times to repeat the statements up to REPEAT

Errors

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

WHILE

Repeats some lines of statements until REPEAT

WHILE: variable

WHILE statements are not imbricated (WHILE in WHILE)

Parameters

It takes exactly one parameter

* variable - a variable, if the variable is different from 0, repeat the statements up to REPEAT

Errors

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

REPEAT

Ends a loop or a while

Parameters

It takes no parameters

Errors

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

IF

Execute some lines of statements until ELSE or END

IF: variable

IF statements are not imbricated (IF in IF)

Parameters

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)

Errors

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

Else part of the if

Parameters

It takes no parameters

Errors

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

END

Ends an if

Parameters

It takes no parameters

Errors

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

INIT

Sets the value of a variable

INIT: variable value
Parameters

It takes exactly two parameter

  • variable - a variable
  • value - the value, may be a number or another variable
Errors

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)

ADDITION

Add a value to the value of a variable

ADDITION: variable value
Parameters

It takes exactly two parameter

  • variable - a variable
  • value - the value to add, may be a number or another variable
Errors

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)

SUBTRACTION

Subtract a value from the value of a variable

SUBTRACTION: variable value
Parameters

It takes exactly two parameter

  • variable - a variable
  • value - the value to subtract, may be a number or another variable
Errors

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

Multiply a variable's value with a value.

MULTIPLY: variable value
Parameters

It takes exactly two parameter

  • variable - a variable
  • value - the value to multiply the variable's value with, may be a number or another variable
Errors

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)

DIVISION

Divide the value of a variable with a value

DIVISION: variable value
Parameters

It takes exactly two parameter

  • variable - a variable
  • value - the value to divide the variable's value with, may be a number or another variable
Errors

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)

IDIVISION

Divide the value of a variable with a value (integer value)

IDIVISION: variable value
Parameters

It takes exactly two parameter

  • variable - a variable
  • value - the value to divide the variable's value with, may be a number or another variable
Errors

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)

MODULO

The remainder of the division of a variable with a value

MODULO: variable value
Parameters

It takes exactly two parameter

  • variable - a variable
  • value - the value to divide the variable's value with, may be a number or another variable
Errors

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)

Bonus

For an additional 0.20p, implement the FOR_LOOP, WHILE and IF imbrication.

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

Coming soon…

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 2. Design Language
  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.1551802018.txt.gz · Last modified: 2019/03/05 18:06 by teodor.deaconu
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