logo

Perl Script for Code Analysis

   

Added on  2019-09-25

4 Pages1356 Words50 Views
 | 
 | 
 | 
Perl and CGImain body start Your task for this practical assignment consists of two parts:1Develop a Perl script using CGI.pm for that performs a statistical analysis of program code and provides functionality stated in the Requirements section below.2Make 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 taking care that the access rights forthe file analysis.pl are neither too restrictive nor too permissive.RequirementsYour 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 field.The script should display a web page that contains a form with two text fields and a `Submit' button. The first text field should allow a user to enter a single URL. You do not need to check whether the URL is syntactically well-formed.If a user enters a URL into the first text field and presses the `Submit' button, then your script should retrieve the code that the URL points to. 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 ASCII characters but also UTF-8 characters and your script should handle those characters correctly when performing the analysis.The second text field allows the user to directly enter program code. Again, you should assume that the code may contain UTF-8 characters. If a user presses the `Submit' button, then your script should simply take the code that has been entered and proceed.An example document 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
Perl Script for Code Analysis_1

print("$counter is not zero)}You do not need to check whether the code is syntactically correct (in any programming language).A user may enter both a URL into the first text field and code into your second text field and then press the `Submit' button. In such a case yoursystem should indicate an error and allow the user to start again.Your script should determine the amount of comments in the code and the amount of instructions and other constructs that are not comments there are in the code:Single-line comments either start with # or with // and run until the end of the line. The number of non-empty 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 length of a comment, for both single-line and multi-line comments, isthe number of Unicode word characters in a comment. 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 wordis 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 linesit 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 andthe 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 non-empty sequence of the symbols +, *, -, %, !, =, &, |. A line of instruction is a line in the instructions that contains at least one element of instruction.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. Your script should then determine and output as a tablethe number of lines of instruction,the number of elements of instruction,the number of non-empty lines of comment,
Perl Script for Code Analysis_2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
CGI-based Perl Script for Code Analysis
|4
|1356
|440

Booking System with MySQL Database
|5
|1729
|211

Programming a Parser in different paradigms
|3
|1194
|607