University of Leicester Department of Computer Science

CO7206 - Fall 2003 Assignment #4 (8%)

Due on Jan. 12, 2003 at 11:00 am

For this assignment, you have two options to choose from as described shortly. This is meant to value the effort by those who invested significant time and effort in the mini-project if they choose option one below. This assignment is optional. This means that according to the method of assessment described below, you have submitted 6 pieces of coursework that cover 50% of the mark of this module. If you like to eliminate you worst coursework mark and replace it with a better mark, then you can do this assignment. If you are happy with your coursework marks, you do not need to do it. However, this assignment is meant to be a practice on TXL programming and a reminder of the clone detection concept in preparation for the exam.

Method of Assessment for this Course (A little modification):

In the light of your feedback, the coursework weight was reduced to 50%, divided over 7 pieces of course work (3 Quizzes and 4 Assignments). Slightly different from what was suggested in an earlier email, the best 6 pieces of coursework will be selected for the student (this is 6*8 = 48%). Then the best of these six pieces will be scaled up from 8% to 10%. For example, if Ali got the following seven marks (3, 5, 8, 5.5, 7, 6, 7.5), the mark 3 will be excluded. His best mark is 8, and hence this will be scaled up by a factor 10/8, meaning he gets 10%. Thus his total will be 5 + 10 + 5.5 + 7 + 6 + 7.5 = 41.

Option 1:

If you have completed any of the two parts of the cancelled Mini-project, you can submit this as your assignment 4. This means you have to submit the full deliverables of this part. For the reverse engineering task, this means submitting Report 1. For the Web-enabling activity, this means submitting Report 2 and presenting the Web-enabled version of Indent to the lecturer.

Option 2:

Write a clone detector using TXL. It should satisfy the following requirements:

1.      The program grammar that will be used is the Command language grammar (assignments, declarations, 'if', 'case', 'while', 'goto' statements and labels). To download it, press the right mouse button and choose save target as. To compile it, use using command txlc.

2.      Your clone detector should implement the basic functionality and one of the optional functionalities.

3.      The basic functionality: It should be able to discover exact clones of some length, say 3, that you can specify in your program or pass as an input. We will not worry about counting how many copies are there, just any 2 similar fragments of the code that are of the same length are going to be reported. For example, the code below may result in discovering 3 clones, which are the 1st with the 2nd, the 1st with the 3rd and the 2nd with the 3rd. If you can do better and avoid this by reporting that there are 3 copies of the same fragment, this is better.

x:=x+1; % First Copy
y:=y+1;
:
x:=x+1; % Second
y:=y+1;
: 
x:=x+1; % Third
y:=y+1;
:

4.      The optional functionalities: Implement one of these functionalities.

          Omitting labels: Omit labels and discover clones without labels, that would not be discovered otherwise. For example, your program should be able to discover that these two fragments are the same without labels.

SomeLabel: x:=x+1; % First Copy
  y:=y+1;
 :
OtherLabel:x:=x+1; % First Copy
  y:=y+1;
 :

          Discover near clones with similar assignment statements if the left hand side is the same. For example, your program should be able to discover that these two fragments are similar.

x:=x+1; % First Copy
y:=y+1;
  if x>0 then goto b;
:
x:=z; % Second
y:=y+1;
  if x>0 then goto b;
 

          Discover exact clones even those within loops or if statements. For example, your program should be able to discover that the two bold underlined fragments are similar.

z:=x-1;
x:=x+1;
y:=y-1;
a: if x>0 then goto b;
 z:=x-1;
 x:=x+1;
 y:=y-1;
m: if y>0 then goto n;
 o:=y; 
goto m;
endif
n: goto a;
endif
b: x:=99;
 

Resources:

q       Amble Resources are found on the TXL page

q       TXL Documentation

q       A brief guide on how to write a TXL program

q       More examples