# Deep Clustering of Student Code Strategies Using Multi-View Code Representation (CMVAE)
## 3 Methodology
### Pre-Training to Learn Code Representations  
#### 3.3.1 Conversion of Code Tree Graph  
The parsing flow of the tree diagram is illustrated in Figure 2. Taking a Python (version 3.8) code fragment as an example, first use a static code analysis tool to parse the source code into the corresponding AST. In this paper, we utilize the ast package (the ast module in the Python standard library is used for parsing Python code and generating ASTs. Official documentation: [[https://docs.python.org/3/library/ast.html](https://docs.python.org/3/library/ast.html)]([https://docs.python.org/3/library/ast.html](https://docs.python.org/3/library/ast.html)), accessed on 21 July 2024) for parsing Python code. For other commonly used programming languages in programming education, tools such as Tree-sitter (Tree-sitter is a parsing framework that supports various programming languages for code analysis and editor plug-in development. Official documentation: [[https://tree-sitter.github.io/tree-sitter/](https://tree-sitter.github.io/tree-sitter/)]([https://tree-sitter.github.io/tree-sitter/](https://tree-sitter.github.io/tree-sitter/)), accessed on 21 July 2024) or Joern (Joern is a code analysis tool based on code attribute maps, designed for vulnerability detection and code understanding. Official documentation: [[https://joern.io](https://joern.io)]([https://joern.io](https://joern.io)), accessed on 21 July 2024) can be used to parse source code. The AST obtained through parsing represents the overall structure of the source code in a tree form, where different node types, such as FunctionDef, If, etc., correspond to different syntactic elements, and edges between parent and child nodes represent the hierarchical structure of the code. Figure 2: Tree graph parsing process, where Step 1 shows the initial source code snippet, Step 2 represents the construction of the S-AST, and Step 3 shows the final constructed tree diagram. To parse all the source codes in the dataset, we extract the node types and count the number of occurrences. Based on this, a node type mapping table is created, mapping node type names to corresponding integer identifiers according to their frequency of occurrence. For example, using Python code, a mapping table with 50 node types is constructed, plus an additional node for unknown types. This results in an undirected tree graph containing 51 nodes. The hierarchical arrangement of branches and loops is fundamental to the code's flow control. The edges that represent these branches and loops help illustrate the code's logical framework. Therefore, based on the basic AST, we introduce the following enhancements:  
1. Conditional judgment enhancement edges: Add enhancement edges between conditional expressions and branch nodes. Conditional judgments include various structures, such as if statements, else statements, elif (else-if) statements, and switch (case) statements. These control flow structures are the basis for directing the flow of program execution based on specific conditions. The decision logic and hierarchy of the code's control flow can be better captured by adding augmented edges between conditional expressions and the corresponding branch nodes. 2. For loop enhancement edges: Add enhancement edges from the loop variable to the loop body node. In the case of for loops, loop variables are an important part of the iteration process, controlling the number of iterations and the data that are iterated over. By adding enhancement edges from the loop variable to the corresponding loop body node, you can emphasize the relationship between the role of the variable in the loop and the actions performed in the loop body. This is important for understanding the overall logic of the program. 3. While loop enhancement edge: Add an enhancement edge from the loop condition to the loop body node. Similar to for loops, while loops rely on a condition to determine whether the loop body should execute repeatedly.