Computer Science
Computer Science-2021.gz:143241
Computer Science
df0789edd3d10511d1dd2a92302dc7fde8b21207
A Methodology for Reliable Code Plagiarism Detection Using Complete and Language Agnostic Code Clone Classification

Code clone detection plays a vital role in both industry and academia. Last three decades have seen more than 250 clone detection techniques with lack of single framework that can detect and classify all 4 basic types of code clones with high precision. This serious lack of clone classification impacts largely on the universities and online learning platforms that fail to validate the projects or coding assignments submitted online. In this paper, we propose a complete and language agnostic technique to detect and classify all 4 clone types of C, C++, and Java programs. The method first generates the parse tree then extracts the functional tree to eliminate the need for the preprocessing stage employed by previous clone detection techniques. The generated parse tree contains all the necessary information for detecting code clones. We employ TF-IDF cosine similarity for the proper classification of clone types. The proposed technique achieves incredible precision rate of 100% in detecting the first two types of clones and 98% precision in detecting type-3 and type-4 clones for small codes of C, C++, and Java containing an average line count of 5. The proposed technique outperforms the existing tree-based clone detection tools by providing the average precision of 98.07% on the C, C++, and Java programs crawled from Github with an average line count of 15 which signifies that cosine similarity measure on ANTLR functional tree accurately detects all 4 types of small clones and act as proper validation tools for identifying the learning level in the submitted programming assignment.


Introduction
Code cloning is the process of creating functionally similar codes with syntactic modifications. It can also be defined as semantically similar code fragment pairs with or without syntactical change [1]. Many researchers refer this process with different terms like similar code [2], identical code [3] or duplicate code [4]. Large systems contain 10-15% and 20-50% of duplicate code in the codebase [5]. Based on the milestone, literature like [6,7,8,9], and based on the study of Wang, W. L. (2020) [1], the code clones are of 4 types that can be categorized into Type-1 which is also called as exact clones, Type-2 which is also called as renamed clones and Type-3 which is also called as near-miss clones. Semantically similar codes that are implemented differently are called as Type-4 clones.
Language agnostic code clone detection has a great role to play in building reliable code plagiarism detection. In order to provide justification to academic integrity, an attempt to code plagiarism detection has already started in late 1976. Based on the survey conducted by Chivers [10] The code plagiarism detection is based on the 3 different techniques a) attribute-based b) structure-based c) hybrid technique. Attribute counting technique was first conducted by Ottenstein [11] The study was based on metrics of Halstead [12] considering the number of unique operators and operands. In the year 1981 Grier [13] added 16 new attributes to the existing metrics of Ottenstein [11] that include looping statements, conditional statements, and tokens like white space, line. A study by J. L. Donaldson et al [14] is based on counting the programming constructs like looping and conditional statements. An empirical approach proposed by Faidhi and Robinson [15] for detection of program similarity is based on 24 metrics. These initial studies were completely based on the text or strings and counting the attributes present in the program. In a comparative study made by Whale [16] argue that more application-specific metrics and structural features of code need to be considered for accurate detection of code plagiarism. Existing plagiarism detection tools like MOSS, JPag calculates similarities in terms of percentage which can present the amount of similarity between two codes but fail to validate the submitted coding assignment when they are implemented differently with type 4 clones. Correlating clone type classifications (type 1, 2, 3, and 4) will give a better understanding of learning of students from submitted programming assignments. Type 1 and 2 are ugly practices that breach academic integrity. Type 3 is bad practice and type 4 is good practice as it increases the level of learning by making students implement functionally similar codes using different syntax. This research paper contributes in following way.


We use the capability of freely available ANTLR parser generator to extract functional tree by providing corresponding grammar files for the input programs. Extraction of functional tree eliminates the need for the preprocessing phase employed by earlier clone detection techniques.  Vector representation of the functional tree using TF-IDF is given as input to cosine similarity which proved to be a more accurate classification of all 4 clone types for the micro programs with line count of 5, 15 and 32.  Existing code plagiarism detection tools that work on similarity matching and report type 4 clones as plagiarism but with respect to academia, it is a good learning practice. We relate clone detection to academic code plagiarism to identify the good, the bad and ugly practices of students.

Background and Related Work
In this section, we present the examples to understand the various clone types, literature on clone detection and literature on code plagiarism. To justify our understanding of clone types, we present the examples based on [6]. According to [8], there are 9 types of clones. Based on the editing taxonomy there exist 4 basic clone types [6].

Background
In the following section we present small programs of our data set to define clone types.
Type-1 clone: Syntactical and semantically similar codes with a change in white space and comments [1]. main() // addition program { int first=10, second=20, sum; sum= first+ second; //logic printf("sum of two numbers=%d", sum); } Code-1 /* addition program */ main() { int first=10, second=20, sum; sum= first+ second; //logic printf("sum of two numbers=%d", sum); } Code-2 Code-1 and Code-2 are an example of type 1 clones. These are also called as exact clones or copy/paste clones. This practice of copying the program as it is from the peer needs to be detected to stop the ugly practice of learning in students and also breach software integrity in industry. Code-3 and 4 are examples of type 2 clones. These clones are also called as renamed clones. This practice of renaming the multiple entities in the program like identifier, method name, and the class name is a bad practice of coding by students which breaches academic integrity.

Type
Type 3: types-2 clones with addition and deletion of lines creates type-3 clones. below code-1 and code-5 are type-3 main() // addition program { int a=10,b=20,c; c=a+b; //logic printf("sum of two numbers=%d",c); } Code-1 main() // addition program { int a=10,b=20,c; c=a+b; //logic printf("program find addition") printf("sum of two numbers=%d", c); } Code-5 Type 3 clones are a matter of interest for many researchers in the past where many tools mentioned in [7] struggled to detect type3 clones. In academia, these are just superset of type2 clone which is considered as bad practice by students. Code-6 and Code-7 are type 4 clones. Type 4 clones are matter of interest to both industry and academia. Type 4 clone detection was out of the scope of many great scalable tools mentioned in the introduction. A major issue with existing code plagiarism detection tools is that/, they report these codes as clones but with respect to the academic point of view it improve the learning levels in students.

Software clone detection
Significant research has happened in finding the software clone types. In this section, we present the summary of clone detection tools/ techniques. Based on the milestone literature works of [6,8], we group all the clone detection approaches into 5 classes like Text-based, Token-based, Tree-based, PDG-based, Metric-based [7] .
Text-based approaches: Text based approaches compare two code fragments based on the input text or string. The tools like Duploc [4], simian [18], EqMiner [19], NICAD [20], DuDe [21]. Except for NICAD none of the tools address detecting even small instances of Type 3. Whereas tool proposed by Johnson, Duploc, DuDe, and SDD detect only type 1 and other tools were meant to find first two clone types.. The work of (Kim, 2018) detects type 1 and 2 of C and C++ code. Highly scalable tool VUDDY [22] detects first two clone types of C/C++. The tool CCCD [23] has made an attempt to detect type 3 and 4 clones of C language. The tool vfdtect [24] detects type 3 and type 4 clones of Java code.
Token-based Techniques: The technique works by performing lexical analysis to extract the tokens from source code. These extracted tokens are used to form the suffix tree or suffix array for matching. Tools like Dup [25], CCFinder [26], iClones [27], CP-Miner [28]. These tools have detected both type 1 and type 2. The tool Siamese [29] detects first three clone types of java code and the tool CP-Miner detects type 3 clones moderately. The work of [30] finds the first 3 clone types of IJDataset. The tool CCAligner [31] detects first 3 clone types of C and Java language. Higly scalable tool SourcererCC [32] detects first 3 clone types of IJDataset. The language agnostic tool CCfindersw [33] detects only first two clone types.
PDG-based Techniques These techniques prepare the program dependency graph to represent the control and data flow of source code [47]. The technique has addressed the detection of type 4 clones. Tools like PDG-DUP [48], Scorpio [49], Duplix [50], Choi [51] concentrate on finding first 3 types of clones.
Metrics-based Techniques like CLAN/Covet [52], Antoniol [53], Dagenias [54] that counts a number of different category of tokens and stores them in a matrix. Both matrixes are matched to get the clones. The tool Vincent [55] detects first 3 clone types of Java code. These tools suffer from false positives for detecting type 3 and 4 clones.
In table 1, we summarize the number of clone detection tools developed to address various clone types and language they support. With having a great number of studies in clone detection, we still find a lack in complete and accurate code clone detection techniques. Maximum of 68 tools work on java code, 30 tools work on C code and 13 tools work on C++ code for clone detection. We find only 4 language agnostic tools which is the big gap in clone detecion reasearch.
In order to provide justification to academic integrity, an attempt to code plagiarism detection was started in late 1976. From 2005 onwards detection of code plagiarism detection was based on string matching, fingerprinting, and tree-based. There are many state-of-art tools for conducting code plagiarism, those include JPlag [56], Marble, SIM, Plaggie, MOSS, Sherlock. JPlag works on tokenizing, greedy string tilling, and optimization. It supports C, C++, Java, C# and text files. Marble is structure-based tool, it works by the recursive splitting of the file till the top line reaches, then removes easily modifiable lexical patterns like class name, function name, identifier name, white space, and comments, and finally applies Linux diff to calculate the score of line similarity. Marble supports Java, Perl, PHP, and XSLT languages. MOSS works on the Linux platform based on document fingerprinting and supports more number of languages like C, C++, Java, C#, Python, VB, Javascript FORTRON, MIPS, and Assembly languages. Plaggie is the command line java application to find plagiarism in java codes. Tool SIM works by tokenizing the source code file then apply forward reference table for matching. It supports C, Java, pascal, Modula-2, Lisp, Mirad and text files.  [58] that works on C and Java codes. CPDP [59] works on Java to find copy/paste activities. This tool can be used in finding type 1, type 2 software clones. The study by [60] works on binary code to check file similarity, [61] works on any language to find file similarity. BCFinder [60] works on C/CP++. A tool PlaGate [62] uses Latent semantic analysis to improve the performance of current plagiarism detection tools. A more detailed and analytical comparative study was conducted by [55], which includes 30 code similarity analyzers including fuzzywuzzy and jellyfish. in his discussion he concludes by saying, the code similarity tools behave differently on pervasive code modification and boiler-plate code. Often used tool ccfx, and Python string matching algorithm, fuzzywuzzy work better on pervasive code modification. The experiment conducted on SOCO data sets for boilet-plate codes ranks jplag-text plagiarism detector followed by simjava, simian, jplag-java, and Deckard [55].

Proposed Methodology
Proposed work is based on the generation of ANTLR functional trees from the source code using corresponding language grammar. The proposed method works in 4 phases.
1. Repository Building and parse tree generation. 2. Functional tree generation. 3. Vector representation. 4. Measuring the functional tree similarity and displaying clone types.
Before we start explaining the methodology we present a brief introduction to ANTLR and similarity metrics.

Introduction to ANTLR (Another Tool for Language Recognition)
Terence Parr is the man behind ANTLR who is working with ANTLR since 1989. ANTLR is LL (*) parser generator that generates the parse trees for the program according to language freely available grammar [63]. Even though ANTLR is written in java, it generates lexer and parser that respectively perform lexical and semantic analysis to build the parse tree from the input files. In this research work, we generate the parse tree by using formal language description called grammar, along with lexer and parser. ANTLR generates various files like grammar tokens, lexer tokens, BaseListner, Listener, parse tree visitor and parse tree walker that can be used to process the parse tree according to our needs [64]. ANTLR parser creates lexer and parser based on the language grammar that later parses the input file based on the grammar. For example, we can write a grammar and include as file.g4 to parse the simple arithmetic expression like 100+2*34 as Upon installing the latest ANTLR 4.8-v4 version and java (JDK) classpath set in the system, we have following ANTLR tutorial available at ANTLR site to generate parse tree for the arithmetic expression 2+3*4+(7-2).
 Execute the antlr command as "antlr file.g4" at command prompt we get various files such as file.tokens, fileBaseListener.java, fileLexer.java, fileListener.java, fileParser.java, file.interp.  Compile all the generated java files to get the class files using the javac compiler.  Run the java org.antlr.v4.gui.TestRig for the input file to obtain the parse tree as follows.
All the 3 steps have to be performed manually at the command prompt or in memory compilations can be done by using the automated APIs of "inmemantlr-tool" which has 14 releases so far and available at Github (Thome). Once we perform step 2 and get class files, using tree Listener class we can implement our own application to process the parse tree by creating the methods like getFirstChild(), getLastChild(), deChild(), getSubtree(), replaceSubtree() to access the basic ANTLR tree class.

Introduction to similarity metrics
According to [65] there exist several similarity metrics to find the similarity of the documents. Table 2 presents various similarity measures that classify the documents based on the data. Smith-Waterman 7 Damerau-Levenstein 8 Jaro-wrinkler Token-based 9 Cosine similarity 10 Jaccard 11 Dice 12 Word/N-gram 13 Monge-Elkan Hybrid 14 Soft -TFIDF grammar E; start: (E NEWLINE)* ; These algorithms work by string matching or token matching by excluding the consideration about the position of tokens in the document hence they do not produce the proper results if applied on the input codes directly. Based on the motivation of [66] these metrics behave differently on the compiled and decompiled code.
We perform code similarity on the source code and corresponding ANTLR generated parse tree using a widely used code similarity metric cosine similarity which return 0 for no similarity and 1 for high similarity. The results of both similarity measures are shown in tables 3. Application of cosine similarity directly on two source codes addc and add1c gives matching similarity as 0.28 whereas we get similarity of 0.93 on the corresponding parse trees of addc and add1c. This significant difference is because of the fact that parse trees provide the syntactic and semantic information about the source code which provides evidence that application of cosine similarity on generated parse trees or subset of parse tree will work as accurate code clone detection technique. Table 3. Similarity measures on source code and parse tree using cosine similarity.

Sl.No
Source file Destination file Cosine similarity on source code Cosine similarity on parse tree (dot file)  Figure 3 presents the architecture of parse tree generation. It is the automated process of running the ANTLR tool through the java application that performs all the manual work explained in generating figure 2 from the input expression 2+3*4+(7-2). We have used "inmemantlr-tool-1.6" APIs available at maven central [67] to generate the parse tree in dot file. Since ANTLR provides grammars to parse all the language, the proposed method is language agnostic. We explain the clone detection and classification for C, CPP and Java codes that act as a evidence to language agnostic nature of the work. ANTLR tool generates various token and java files like Grammar.Tokens, Lexer.tokens, Lexer.java, Parser.java, Listner.java, BaseListner.java. All the java files are then compiled to get class files. Upon generation of java class files one has to provide input file (.C/.C++/.Java) files to generate the parse tree. This process can be done by writing the java application to read the grammar files and input file then calling the Listner class generated in the previous stage of ANTLR processing. This application can be made to work on the generated parse tree to extract the nodes of our interest.

Repository Building and parse tree generation
Parse tree generation: as a case study we have considered small academic programs containing 135 C programs, 99 CPP programs and 33 codes of Java stored in a separate directory. The proposed method makes total of 9180 pair wise matching for C codes, 4950 comparisons for CPP codes and 561 comparisons for Java codes. The advantage of using functional tree extraction is that, it automatically performs pre-processing step adopted by previous clone detection techniques to eliminate program header, and comments. Since the size of generated functional tree is very long, we take small example of printing "hello world" from our data set. The basic principle of ANTLR is to generate the complete parse tree that includes the node information of all the lines present in the input code. Functional tree is the subset of parse tree that includes the generation of nodes only for the line number 4 to 6 for the above C-code, line number 4-7 for above CPP-code and line number 4-8 for above Java-code. These are the statements that represent the main functionality of the code, and hence the tree generated by including all the information in the main function of C and CPP code and the class body of java code is named as functional tree. Figure 4, 5 and 6 respectively shows the ANTLR parse tree for the above case studies of C, CPP and java code. Functional tree for both C and CPP code starts with the node name statementseq that contains node information for line number 5 for C and line number 5 and 6 for CPP. Sub tree generated by extracting only the lines of function definition is termed as functional tree in our paper. The parse tree of java code starts with node name compilationunit followed by left subtree importDeclartion that corresponds to importing the packages. A class definition starts from the right subtree with node name typeDeclartion followed by classDeclaration, classBody, classBodyDeclaration. The left children of this node correspond to modifier public static. The class definition starts from the rightmost child memberDeclaration followed by methodDeclaration. So far all the nodes of the parse tree represent in building the header information for the java class. These nodes just bring structural information of java code.
We first allow ANTLR to generate the complete parse tree by calling the base class method of antlr tree on the listener variable dt.
TreeListner dt; dt.getParseTree() creates the ANTLR parse tree. We use common grammar file CPP14.g4 to parse C and CPP code to get parse tree. Parse tree for C and CPP code starts with node name translationunit followed by declarationseq, declaration, functiondefinition, functionbody and so on.

Functional tree generation
This section provides the technical details to extract the functional tree from the parse tree. From the figure 4 and 5 we find that parse tree of C and CPP code starts with the node name translation unit followed by declarationseq, declaration, functiondefintion along with all these nodes till the left descending children of functiondefintion corresponds to C/CPP header. These rules do not contribute to finding the functional similarity of any program. The main computation or functionality of the code starts from line number 5 which corresponds to the the node name "statementseq" in the parse tree. Hence we generate the functional tree by extracting the subtree with node name statementseq for C/CPP parse tree. The code for extracting the functional tree from ANTLR generated parse tree is presented below.

parseTree=dt.getParseTree().getSubtrees(n-> n.getRule().equals("statementseq")).iterator().next();
similarly the parse tree of java code starts with node name compilationunit followed by left subtree importDeclartion that corresponds to importing the packages. A class definition starts from the right subtree with node name typeDeclartion followed by classDeclaration, classBody, classBodyDeclaration. The left children of this node corresponds to modifier public static. The class definition starts from the rightmost child memberDeclaration followed by methodDeclaration. So far all the nodes of the parse tree represent in building the header information for the java class. These nodes just bring structural information of java code. The functionality of the java code is written inside the two curly braces of the main method from the line number 7 of Java code. Hence functional tree for Java code can be extracted by passing the argument as node name "block" to equals method on getRule() as follows.

Finding the functional tree similarity and displaying clone types
The parse Functional tree generated in the previous phase can be stored in dot file using the APIs of "inmemantlrtool" (Thome) that can be used for comparison using any of the natural language processing techniques such as Levenstein distance, Edit distance, Hamming distance, Longest Common Subsequence. By looking at the fact that parse tree generates a lot of information through repetitive rules we consider term frequency inverse document frequency with cosine similarity to find the similarity between two different parse tree representations in a dot file. The sequence of finding the functional tree similarity is shown in the figure 7. The Cosine Similarity function [68] Is widely used to compute the similarity between two given term vectors. Which is ratio of the inner product (v1•v2) to the product of vector length. Similarity between two vectors v1, v2 is given by Following pseudo code, statements find cosine similarity between vectors v1 and v2 [68].
Finally, we get similarity between Doc A and Doc B as

Vector Representation
The Term Frequency Inverse Document frequency (tf.idf) [69] is a hash map-like data structure that finds frequencies of term occurrence in a document with the relative location. It is the SVM based metric that is used for document processing and comparison. Term frequency gives the count of each token in a document and inverse document frequency gives the uniqueness of each token in a document. The advantage of using this approach is it gives the relative position of every token in a document.
Equation (1) Where N is the total number of documents? Table 4 shows the results obtained by combining TF and IDF for the below code-A and code-B.
Significance of using TF-IDF is term frequency identifies the words having a unique occurrence of word in the documents. Term frequency is calculated by counting the tokens in the respective documents like for int in code-A is calculated as 1/7 which denotes the term int occurs once among 7 readable tokens. Similarly for a, b, c, and z in a code-A is 2/7, 2/7, 2/7, and 0/7 respectively. In the same way the term frequencies for all the tokens in code-B is calculated and presented in 5 th columns of table 4. Inverse document frequency for each tokens of code-A and code-B are presented in column 6 and 7 respectively. Finally tf-idf value 0.4837 signifies uniqueness of token c in code-A and token z in code-B.

Classification of clone types
As the last step, we classify clone types by manually validating the matching percentage of all four clone types according to the following thresholds. The following judgment criteria are based on the validation of more than 4000 known clone pairs taken from sanfoundry.com. The classification threshold is based on the similarity value as shown in the table 5.

Experimental Setup and Dataset Creation
The experiment is conducted on the Windows 7 operating system with Intel core 2 duos CPU having 2 GHZ speed and 2GB RAM on three sets of data samples. We plan 3 set of case studies as shown below.
i) Dataset-1: To understand the parsing ability of ANTLR, and clone classification accuracy of cosine similarity, we initially validated our approach on 135 of C codes, 99 C++ codes and 33 java codes with average line count of 5. We recorded time taken to parse the various inputs files. ii) Dataset-2: We have collected sample of C, C++ and Java codes from sanfoundry.com which contains 1000 algorithm based codes of C, C++ and Java. We have edited all the codes according to clone type definitions to get total of 4234 true clone pairs of each code samples. iii) Dataset-3: Next we perform systematic GitHub-web scrapping on 73,075 active repositories of C and 86,505 active repositories of C++ to collect 12,600 sample clone pairs of C and 14,480 clone pairs of C++ with average line count of 15. Since BigCloneBench is the standard data set for java, we use the sample dataset similar to that of (Wang, 2020) which contains 9,134 java codes type. The table 6 presents the details of three datasets on various known clone pairs.

Results and Analysis
In section 3, we have applied TF-IDF cosine similarity directly on the C source files and found the results in table 3. The obtained similarity measure can only be used to find the type 1 clones and do not support detection of other three Recall tries to find how many positives are identified correctly.

Recall= True Positive / True Positive + False Negative
In terms of precession and recall by selecting the few results randomly from C, CPP and Java to understand clone classification accuracy is as follows.

Results on Dataset-1
We present few samples of dataset 1 for both C and C++ in table 7 and 8 respectively using CPP14.g4 grammar.  Table 9 shows the similarity of two functional tree's of ANTLR generated functional tree for Java files using JavaLexer.g4 and JavaParser.g4 grammar. The experiment was extended to total of 135 C codes with 9180 comparisons, 99 C++ codes with 4950 comparisons and 33 Java codes with 561 comparisons were made to record the following precision and recall is shown in the table 10. The results show excellent precision and recall for type 1 and 2 but yields false positive values for type 3 and 4. The table 10 shows the improvement in the precision and recall of type 3 and type4. One noted good thing about TFID-cosine similarity is that it takes just 40 seconds to compare 9180 C code comparisons and takes 78 minutes to compare equivalent functional trees which make it computationally infeasible for exhaustive comparisons.

Results on Dataset-2
This section presents the classification results for the known clone pairs of dataset-2 containing exactly 4234 clone pairs of C, C++ and Java codes as shown in table 5. We have applied exhaustive comparison on the each dot file containing functional tree using TF-IDF cosine similarity. The results of clone classification for entire dataset-2 are presented in table 11 below. The results presented in table 11 proves that the proposed method works very well in detecting the clone types 1 and 2 on all three languages with almost 100% precision. We have also obtained excellent results in detecting type 3 and 4 with precision of 98.26% and 97.14% respectively that outperforms the existing tree based clone detection tools for detecting type 3 and 4 clone types.

Results on Dataset-3
This section presents the classification results for the known clone pairs of dataset-3 containing exactly 12,600 sample clone pairs of C and 14,480 clone pairs of C++ with average line count of 15 and 9,134 java codes from BigCloneBench as shown in table 5. We have applied exhaustive comparison on the each dot file containing functional tree using TF-IDF cosine similarity. The results of clone classification for entire dataset-3 are presented in table 12 below. The results presented in table 12 proves that the proposed method works very well in detecting the clone types 1 and 2 on all three languages with almost 98.93% precision. We have also obtained encouraging results in detecting type 3 and 4 with average precision of 97.18%.

Comparative Study
In this section, we present the recent tree based techniques on the two important parameters such as clone type classification and language supported by tool. The comparison is presented on    [72] and Wang, 2020 [1] have classified all 4 clone types but the major issue is they are limited to Java code for clone detection. Apart from this both the works are computationally infeasible. We are the first to apply the clone detection and classification to three languages. The evidences of current study gives the hint that since the grammars for parsing all the languages are freely made available by ANTLR, the current methodology can be extended to include all the programming languages that are in practice by all the universities in the world.
Next, we present table 14 to compare our study with the open source tree based techniques to record the precision in detecting the clone pairs on our dataset-3. We have considered Deckard [35], iclones [27], ccfx [75] and re-use the accuracy data presented in FA-AST+GMN [1] to validate our approach. From the above table 14, we can conclude that, the proposed method is the more reliable, complete and language agnostic in detecting clone with the excellent average precision of 98.07% in detecting all four clone types thereby act as a proper validation tool for detecting learning levels by the students in submitted code assignments. The string based document comparison techniques for plagiarism detection in Arabic languages presented by Mohd. Binai [76] and plagiarism detection for Kurdish language proposed by Karzan Wakil et al. [77] can only detect type 1 and type 2 clones but fail to detect type 3 and type 4 clones because of the semantic factor involved in detecting code plagiarism hence cannot be applied to code plagiarism detection.

Conclusion
This research paper proposes more realiable code plagiarism detector by implementing complete and languageagnostic clone detection for C, C++ and Java languages on the datasets containing average line count of 5, 15, and 32 respectively. The technique works by extracting a functional tree from the ANTLR generated parse tree to eliminate the need of preprocessing stage employed by previous clone detection tools. We employ TF-IDF cosine similarity on the generated functional tree in dot file that takes less than 3 seconds to match the clone pairs of 1396 codes which provides evidence that the method works on large scale repositories. The results prove that classification of clone types-1 and 2 are done with 100% precision and precision of 98.50 and 98.12 respectively for detecting type 3 and type 4 clones on 30 small codes of C, C++, and Java. Proposed technique exhibits the precision of 99.9% for type-1, 97.96% for type-2, 96.7% for type-3, and 97.66% for type-4 clone detection on the C, C++ and Java programs crawled from active repositories of Github. As ANTLR grammars are made available freely, the proposed model can be extended to include other existing programming languages to detect code plagiarism with clone types classified to get proper validation in submitted coding assignments.