- Details
- Parent Category: Programming Assignments' Solutions
We Helped With This Programming Homework: Have A Similar One?

Category | Programming |
---|---|
Subject | Other |
Difficulty | Undergraduate |
Status | Solved |
More Info | Programming Assignments Help |
Short Assignment Requirements
Assignment Description
COMP284Assignment 1
COMP284 Scripting Languages (2017-18) -- Assignment
1: Perl and CGI
Your task for this practical assignment consists of two parts:
1. Develop a Perl script using CGI.pm that performs a statistical analysis of program code and provides functionality stated in the Requirements section below.
2. Make the Perl script that you have created accessible and usable via the URL http://cgi.csc.liv.ac.uk/cgi-bin/cgiwrap/<your user name>/analysis.pl
Take care that the access rights for the file analysis.pl are neither too restrictive nor too permissive.
Requirements
Your Perl script should perform a statistical analysis of program code that the user provides via a web interface either by supplying a URL that indicates where the code can be retrieved or by entering the code directly into a text area.
The script should display a web page that contains a form with a text field, a text area, and a `Submit' button. The text field should allow the user to enter a single URL. The text area should allow a user to enter program code.
• If the user enters both a URL into the first text field and code into the text area and then presses the `Submit' button, then the system should indicate an error and allow the user to start again.
• If the user neither enters a URL nor enters code into the text area and then presses the `Submit' button, then the system should indicate an error and allow the user to start again.
• If the user only enters a URL into the text field and then presses the `Submit' button, then your script should retrieve the code that the URL points to. You do not need to check beforehand whether the URL is syntactically well-formed, but you should cater for the possibility that the URL is not valid, i.e., that there is nothing to retrieve at that URL, and indicate an error to the user in such a case. The code may not only contain ASCII characters but also UTF-8 characters and your script should handle those characters correctly when performing the analysis.
• If the user only enters program code into the text area and then presses the 'Submit button, then your script should simply take that code and proceed. Again, you should assume that the code may contain UTF-8 characters.
An example of the kind of program code that your script is expected to analyse is the following:
/* This is a
multi-line comment */ if ($counter > 0) {
print("$counter is zero") // comment to the end of the line
} else {
# single-line comment print("$counter is not zero")
}
You do not need to check whether the code is syntactically correct (in any programming language).
Your script should then determine the amount of comments in the code:
• Single-line comments either start with # or with // and run until the end of the line. The number of nonempty lines of comment for a single-line comment is 1 if the comment contains at least one Unicode word character and 0 otherwise.
• Multi-line comments start with /* and end with */ and span one or more lines between /* and */. The number of non-empty lines of comment for a multi-line comment is the number of lines of that comment that contain at least one Unicode word character.
• The number of words in a comment, for both single-line and multi-line comments, is simply the number of words in a comment where we assume that a word is a non-empty sequence of Unicode word characters separated by non-word characters.
• Finally, the number of non-trivial comments is the number of single-line and multi-line comments that is at least five words long (note: here a multi-line comment counts 1 no matter how many lines it has, if it contains at least five word).
• You can assume that comments cannot be nested.
If you remove all comments from the code, including the characters that start and end comments, as well as any empty lines and any lines containing only spaces and tabs, what remains are the instructions of the code.
We are interested in the number of elements of instruction and the number of lines of instruction:
• An element of instruction is either an identifier, that is, a non-empty sequence of the characters a-z, A-Z, 0-9, and underscore _ that does not start with a digit, or a symbolic operator, that is, a non-empty sequence of the symbols +, *, -, %, !, =, >, <, &, |. A symbolic operator can separate two identifiers, for example, length3-length4 consists of three elements of instruction ('length3', '-', 'length4'). Similarly, any character that can neither occur in an identifier nor in a symbolic operator, separates elements of instruction, for example, push("peter",123,stack) consists of three elements of instruction ('push', 'peter', 'stack').
• A line of instruction is a line in the instructions that contains at least one element of instruction. After performing this analysis, your script should first output the code it has received as input, in a way that preserves the layout and all elements of the code. If the code was retrieved from a URL, then the URL should also be shown.
Your script should then output the results of the analysis as a table indicating
• the number of lines of instruction,
• the number of elements of instruction,
• the number of non-empty lines of comment,
• the number of non-trivial comments,
• the number of words of comment,
• the ratio of the number of non-empty lines of comment to the number lines of instruction,
• the ratio of the number of non-trivial comments to the number lines of instruction,
• the ratio of the number of words of comment to the number of elements of instruction. Ratios should be rounded to 1 digit after the decimal point.
For the code example above the output would be:
Number of lines of instruction | 4 |
Number of elements of instruction | 13 |
Number of non-empty lines of comment | 5 |
Number of non-trivial comments | 2 |
Number of words of comment | 16 |
Ratio of non-empty lines of comment to lines of instruction | 1.2 |
Ratio of non-trivial comments to lines of instruction | 0.5 |
Ratio of words of comment to elements of instruction | 1.2 |
Code Analysis
Your code should follow the COMP284 Coding Standard. This includes pointing out which parts of your code have been developed with the help of on-line sources or textbooks and references for these sources.
Test data
Test data, together with the expected results, can be found at http://cgi.csc.liv.ac.uk/~ullrich/COMP284/tests-2017-18N/.
Submission
Submit your Perl script via the departmental submission system at https://sam.csc.liv.ac.uk/COMP/Submissions.pl?module=comp284 (COMP284-1: Perl). Do not forget to also complete the second part of the assignment.
Deadline
The deadline for this practical assignment is
Friday, 2 March 2018, 17:00
Earlier submission is possible, but any submission after the deadline attracts the standard lateness penalties.
Please remember that a strict interpretation of `lateness' is applied by the Department, that is, a submission on Friday, 2 March 2018, 17:01 is considered to be a day late (analogously for submissions that are delayed further).
Assessment
This practical assignment will address the following learning outcomes of the module:
• rapidly develop simple applications, both computer and web-based, using an appropriate scripting language;
• document and comment applications written using a scripting language.
This practical assignment will contribute 30% to the overall mark of COMP284. Failure on this assignment may be compensated by higher marks on other assignments for this module.
Marks will be awarded according to the following scheme:
• The Perl script is accessible via the required URL, works without producing script errors, all required files were submitted, the files accessible via the web are identical to those that were submitted, and the access rights of the files in your filestore must be such that no other user can view their contents in the filestore: 10
• Creating a web page, using CGI.pm, for user input, input checking and URL retrieval: 23
• Performing the code analysis: 37
• Creating a web page, using CGI.pm, showing the program code and the results of the analysis: 18
• Formatting, commenting, and quality of code: 12
As stated above, the University policy on late submissions applies to this assignment as does the University policy on Academic Integrity, which can be found at http://www.liv.ac.uk/student-administration/studentadministration-centre/policies-procedures/academic-integrity/. You should follow the COMP284 Lab Rules to ensure that you do not breach that policy.
© University of Liverpool - a member of The Russell Group
Departmental Contacts | University Contacts | Map | Legal | Accessibility