The invention discloses a code
processing method and device fusing grammar structure and graph
structure learning, and the method comprises the steps: collecting high-performance project codes, extracting hot code segments, and analyzing the structural features of the hot code segments; converting the hot
code segment into an
abstract syntax tree AST file, performing
structured analysis, converting the file into Python
tree structure data, and expanding node attributes; converting the
tree structure data into graph structure data, generating edge, graph and node index files, and constructing the graph structure data and corresponding code structure labels; constructing a graph
attention network model for different code structures, and training a plurality of GAT models based on graph structure data and labels; and converting the
user input code, inputting the converted code into each GAT model for prediction, and integrating and outputting a
feature vector. According to the method, grammar logic is accurately captured through AST conversion and node expansion, multi-language AST is unified into a graph structure, the recognition accuracy of a complex code structure is improved through a GAT multi-
model architecture, full-process
automation is achieved, and the labor cost is reduced.