A Program Defect Detection Method Based on Multiple Syntax Features

Through a program defect detection method based on multiple grammatical characteristics and using a neural network model to predict potential defects, the deficiencies in detection accuracy and coverage of the static analysis method are solved, and more efficient program detection is achieved.

CN118259890BActive Publication Date: 2024-09-10HANGZHOU XUNZHEN TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410689812.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-30
Publication Date
2024-09-10
Estimated Expiration
2044-05-30

AI Technical Summary

Technical Problem

Existing static analysis methods are prone to produce false positives during program detection, and are difficult to fully simulate the dynamic behavior of the program, resulting in missing potential defects in complex code structures.

Method used

A program defect detection method based on multiple grammatical features is used to extract multiple features in the grammatical structure through the parser, associate these features, build a neural network model, and use defect samples to train the model to predict potential defects.

Benefits of technology

It improves the accuracy of detection, reduces the false alarm rate, can capture defects in the program more comprehensively, and improves detection efficiency and trust.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118259890B
    Figure CN118259890B
Patent Text Reader

Abstract

The present invention provides a method for detecting program defects based on multiple grammatical features, comprising the following steps: using a parser to parse the source code of a program; extracting multiple grammatical features from the grammatical structure obtained by parsing; associating multiple grammatical features to obtain multiple grammatical features; establishing a neural network model based on the multiple grammatical features, and using defect samples to train the neural network model; using the trained neural network model to predict potential defects in the target code. The present invention has the following beneficial effects: it combines technologies such as a parser and a neural network model, can improve detection accuracy while reducing the false alarm rate and improving detection efficiency, and is a relatively effective program defect detection solution.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of program detection, and in particular relates to a program defect detection method based on multiple grammar characteristics. Background Art

[0002] Program testing is the last step before a product is launched and plays a vital role in the product. Currently, program testing is often done by manually writing automated scripts, but this method requires pre-running the program, which consumes a lot of time when program compilation is more complicated.

[0003] In view of this, static analysis methods are proposed in the prior art for program detection. This is a method of analyzing source code without running the code. Static analysis tools check potential problems in the code, such as syntax errors, type mismatches, and undefined behaviors. They identify potential defects by scanning the source code and applying predefined rules or patterns, thereby reducing the cost of discovering and repairing program vulnerabilities.

[0004] But static analysis also has its own shortcomings and limitations:

[0005] Static analysis tools may produce false positives, i.e., false positive defects. For the sake of accuracy and coverage, some static analysis tools may use over-approximation methods, resulting in missing real defects or false positives on some complex code structures.

[0006] Static analysis mainly relies on the static structure of the code and cannot fully simulate the dynamic behavior of the program, resulting in the inability to capture and analyze certain runtime characteristics and behaviors. In addition, for codes containing complex control flow and data flow, static analysis has difficulty accurately identifying potential defects and problems. Summary of the invention

[0007] In view of this, the present invention aims to propose a program defect detection method based on multiple grammar characteristics, in order to solve at least one of the above-mentioned technical problems.

[0008] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0009] A first aspect of the present invention provides a method for detecting program defects based on multiple grammar characteristics, comprising the following steps:

[0010] Use a parser to parse the source code of the program;

[0011] Extracting multiple grammatical features from the parsed grammatical structure;

[0012] Associating multiple grammatical features to obtain multiple grammatical properties;

[0013] A neural network model is established based on multiple grammatical features, and defect samples are used to train the neural network model;

[0014] Use the trained neural network model to predict potential defects in the target code.

[0015] Furthermore, the process of parsing the source code of the program using the parser includes:

[0016] Define corresponding grammar rules for the target programming language or domain-specific language, and generate a parser according to the grammar rules, wherein the grammar rules are expressed by a context-free method;

[0017] Use the parser to parse the program source code as input to obtain a grammatical structure of the specified form.

[0018] Furthermore, the process of generating the parser according to the grammar rules includes:

[0019] Create a grammar file based on the grammatical characteristics of the source code and use the extended Backus-Naur form to describe the grammar rules;

[0020] Define lexical rules and grammar rules in the grammar file, and generate a parser based on the grammar rules in the grammar file.

[0021] Furthermore, the process of using the parser to parse the input program source code includes:

[0022] Use the parser to perform lexical analysis and syntax analysis on the source code. While performing syntax analysis, the parser processes lexical units one by one according to the grammatical rules and constructs a syntax tree in a bottom-up manner;

[0023] The nodes of the syntax tree include syntax units obtained through syntax analysis and replacement, and lexical units that cannot be replaced during syntax analysis.

[0024] Furthermore, the process of extracting multiple grammatical features from the parsed grammatical structure includes:

[0025] Analyze the declaration, use, and life cycle of variables in the program to obtain the role and scope of influence of the variables in the program; track the definition and call of functions, identify the control flow statements in the program, and analyze the paths and conditions of the control flow statements;

[0026] Track the assignment, transfer and reference of data in the program to obtain the dependency of data flow; identify the calling and data transfer relationship between program modules to obtain the dependency between modules.

[0027] Furthermore, the process of associating multiple grammatical features to obtain multiple grammatical properties includes:

[0028] Convert the extracted grammatical features into item sets or transaction sets;

[0029] Conduct frequent item set mining to obtain grammatical feature combinations with high co-occurrence frequency;

[0030] Based on the results of frequent item set mining, association rules are generated to obtain the association relationship between multiple grammatical features.

[0031] Furthermore, when analyzing the frequency of occurrence between individual data items, the item set form is used, and each grammatical feature is represented as a single item;

[0032] The transaction set form is used when analyzing the occurrence frequency of the entire data set, and each program fragment or source code file is represented as a transaction, where each transaction corresponds to a feature of the program source code.

[0033] Furthermore, the process of establishing a neural network model based on multiple grammatical features includes:

[0034] Convert multiple grammatical features into numerical data, and use graph embedding technology to convert structured features into vector representations;

[0035] Use LSTM layers to build models that receive transformed data and capture long-term dependencies in time series;

[0036] The binary cross entropy loss function and SGD algorithm are used to optimize the neural network model.

[0037] A second aspect of the present invention provides an electronic device, comprising a processor and a memory that is communicatively connected to the processor and is used to store instructions executable by the processor, wherein the processor is used to execute a program defect detection method based on multiple grammar features as described in the first aspect above.

[0038] The third aspect of the present invention provides a server, comprising at least one processor and a memory communicatively connected to the processor, the memory storing instructions executable by the at least one processor, the instructions being executed by the processor so that the at least one processor executes a program defect detection method based on multiple grammar features as described in the first aspect.

[0039] Compared with the prior art, the program defect detection method based on multiple grammar characteristics described in the present invention has the following beneficial effects:

[0040] Instead of relying solely on a single grammatical feature, it extracts features of multiple grammatical structures from the source code of the program, which can more comprehensively capture possible defects in the program.

[0041] By associating multiple grammatical features and building a neural network model, potential defects in the target code can be predicted more accurately. The training process of the neural network model allows it to learn the correlation between different grammatical features, thereby improving the accuracy of detection.

[0042] Since multiple grammatical features are taken into consideration, this method may reduce the false positive rate, that is, reduce the cases where normal code is misjudged as defective, and can increase the confidence of programmers in using the tool in actual work.

[0043] Compared with traditional manual detection methods, automated detection methods based on neural network models can greatly improve detection efficiency. Once the neural network model is trained, a large amount of target codes can be quickly detected, thus saving time and labor costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0045] Figure 1 The present invention is a flowchart of a method for detecting program defects based on multiple grammar characteristics according to an embodiment of the present invention. DETAILED DESCRIPTION

[0046] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0047] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and the like are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, features defined as "first", "second", and the like may explicitly or implicitly include one or more of the features. In the description of the present invention, unless otherwise specified, "multiple" means two or more.

[0048] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood by specific circumstances.

[0049] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0050] Embodiment 1: A method for detecting program defects based on multiple grammar characteristics, comprising the following steps:

[0051] S1. Use the parser to parse the source code of the program;

[0052] S2, extracting various grammatical features from the parsed grammatical structure;

[0053] S3, associate multiple grammatical features to obtain multiple grammatical properties;

[0054] S4, establishing a neural network model based on multiple grammatical features, and using defective samples to train the neural network model;

[0055] S5. Use the trained neural network model to predict potential defects in the target code.

[0056] The defect sample described in S4 is: code with program vulnerabilities.

[0057] The specific process of using the parser to parse the source code of the program in S1 includes:

[0058] Define corresponding grammar rules for the target programming language or domain-specific language, and generate a parser according to the grammar rules, wherein the grammar rules are expressed by a context-free method;

[0059] Use the parser to parse the program source code as input to obtain a grammatical structure of the specified form.

[0060] The process of generating the parser according to the grammar rules includes:

[0061] Create an ANTLR grammar file based on the grammatical characteristics of the source code, and use the extended Backus-Naur form to describe the grammar rules; in the ANTLR grammar file, you can define lexical rules (decompose the input text into lexical units) and grammar rules (build a syntax tree), and generate a parser based on the grammar rules in the ANTLR grammar file.

[0062] User-defined grammar rules include the following:

[0063] Keywords and identifiers: specifies the form and usage of keywords and identifiers in the language;

[0064] Expressions and Operators: defines the structure of expressions, as well as the precedence and associativity of different operators;

[0065] Statements and Control Structures: describes the various types of statements in the language (such as assignment statements, conditional statements, loop statements, etc.) and their grammatical structures;

[0066] Data types and variable declarations: Specifies the data types supported in the language, as well as how to declare and use variables;

[0067] Function and method definition: defines the syntax structure of the function or method, including parameter list, return type, etc.

[0068] Modules and Imports: Describes how modules are defined and imported in modular programming;

[0069] Notes: specifies the format and usage of notes;

[0070] Special grammatical structures: defines special grammatical structures in the language, such as macro definitions, generics, exception handling, etc.

[0071] The process of using the generated parser to parse the input program source code is:

[0072] 1) Lexical analysis:

[0073] The parser performs lexical analysis on the input source code and splits it into a sequence of lexical units (tokens). The lexical units include keywords, identifiers, operators, and separators. The specific process is as follows:

[0074] The parser first scans the input program source code, reads the source code character by character, and decomposes the character sequence into lexical units (tokens);

[0075] After identifying a lexical unit, the parser generates a corresponding lexical unit object, each of which contains the type of the lexical unit (keyword, identifier) ​​and attributes (name of the identifier, value of the constant);

[0076] When generating token objects, the parser filters out irrelevant characters, such as whitespace (spaces, tabs), and comments;

[0077] When encountering a character sequence that does not conform to the lexical rules or an unrecognizable lexical unit, the parser generates an error message or skips the error part and continues parsing;

[0078] After completing lexical analysis, the parser returns a sequence of tokens.

[0079] 2) Syntax analysis:

[0080] The parser performs grammatical analysis on the input source code, including identifying the start and end of the grammatical structure and determining the nesting relationship of the structure. The specific process is as follows:

[0081] The parser traverses all tokens, replaces one or more tokens with a higher-level grammatical unit, or adds a token to the current grammatical structure;

[0082] When the grammar rule cannot be matched or the input code has a grammatical error, the parser will report an error and skip the current error code;

[0083] After completing grammatical analysis, the parser returns a sequence of grammatical units.

[0084] 3) Syntax tree construction:

[0085] While performing grammatical analysis, the parser processes lexical units one by one according to the grammatical rules and builds a grammar tree starting from the leaf nodes and working upwards (bottom-up);

[0086] The nodes of the syntax tree include syntax units after lexical units are replaced by syntax analysis, and lexical units that cannot be replaced during syntax analysis.

[0087] The specific process of extracting various grammatical features from the parsed grammatical structure in S2 includes:

[0088] Identify variable declarations and usage in a program: Identify all variable declaration statements, including variable name, type, and scope; track variable usage, including variable assignment, reference, and modification; and analyze the variable life cycle, i.e., its effective scope in a program.

[0089] Analyze the calling relationship between functions: identify all function definitions and function call statements, including function names, parameter lists, and return values; track the calling relationship between functions, including parameter passing and return value processing; analyze whether the context of function calls is executed under the correct conditions.

[0090] Extract control flow structures in programs: Identify control flow statements such as conditional statements (if, else), loop structures (for, while), etc.; analyze control flow paths and conditions to detect logical errors or inconsistencies.

[0091] Analyze the data flow path in the program: track the assignment, transfer and reference of data to obtain the data flow path; analyze the dependencies of data flow to identify potential data errors or abnormal situations.

[0092] Analyze the dependencies between program modules: identify the calling relationships and data transfer relationships between modules.

[0093] It is worth noting that the following optimizations can be introduced to speed up the process of extracting various grammatical features from the parsed grammatical structure and reduce the resources used:

[0094] Optimization 1. Optimize the parser algorithm and data structure:

[0095] Use compact data structures to represent syntax trees or syntax structures, avoid unnecessary pointers or additional metadata, and use arrays instead of dynamic data structures such as linked lists to reduce memory allocation and management overhead;

[0096] Using memory pool technology can reduce the number of memory allocation and release, thereby reducing memory fragmentation and improving memory usage efficiency. By pre-allocating memory blocks of a certain size and obtaining them from the memory pool when needed, frequent memory allocation and release operations can be avoided.

[0097] Use pointers or references to pass data instead of making explicit copies of data;

[0098] Frequently accessed or used parsing results are cached and reused to avoid repeated parsing of the same code snippets or files. By caching parsing results, repetitive work is reduced and overall processing efficiency is improved.

[0099] Optimization 2: Use incremental compilation technology to recompile changed files and their dependencies:

[0100] Build a dependency graph for the entire project, including dependencies between files and compilation order, and monitor changes in source code files by monitoring changes in the file system;

[0101] When a change in a source code file is detected, the dependency graphs before and after the change are compared to identify the affected files and their dependencies;

[0102] Update the compilation task queue based on the affected files and their dependencies, add the files that need to be recompiled to the queue, and ensure that dependencies are handled correctly to ensure that the files are recompiled in the correct order;

[0103] Perform an incremental compilation process, recompile only the files in the queue and their dependencies, and update the target file through incremental updates instead of regenerating the entire target file for the already compiled files;

[0104] After incremental compilation is completed, update the build results and outputs, and clean up no longer needed intermediate files and target files to release resources and reduce disk usage.

[0105] The process of associating multiple grammatical features in S3 to obtain multiple grammatical properties includes:

[0106] The extracted grammatical features are converted into a form suitable for Apriori algorithm processing, including item sets and transaction sets. Item sets are suitable for analyzing the frequent occurrence patterns between single data items, while transaction sets are suitable for analyzing the frequent patterns of the entire data set. Specifically:

[0107] 1) Use item set form to represent each grammatical feature as a single item, including:

[0108] Variable declarations and usage are represented as items containing the variable name, scope, and data type;

[0109] The function call relationship is represented as an item containing the caller function name, the callee function name, and the parameter list;

[0110] Control flow structures are represented as items containing conditional statement types and loop statement types;

[0111] The data flow path is represented as items containing data source, data receiver, and data flow;

[0112] The dependency relationship between program modules is represented as items including dependency source, dependency target, and dependency type.

[0113] 2) Use the transaction set form to represent each program fragment or source code file as a transaction. Each transaction contains all items that appear in the current program fragment or file, that is, each transaction corresponds to a feature of the program source code.

[0114] Generate a set of all possible single items as candidate item sets, and use the properties of frequent item sets to gradually generate candidate item sets containing more items until no new candidate item sets can be generated;

[0115] Scan the generated candidate item sets and count their support in the transaction set, that is, the frequency of their co-occurrence;

[0116] According to the minimum support threshold, the candidate item sets are pruned and the item sets with support lower than the threshold are removed to obtain frequent item sets.

[0117] For each frequent item set, all possible association rules are generated. For a frequent item set, multiple association rules can be generated, and each rule has a different combination of antecedents and consequents.

[0118] The support and confidence of the generated association rules are calculated. The support represents the frequency of the rule in the transaction set, and the confidence represents the accuracy of the rule. The rules are screened and evaluated according to the support and confidence thresholds to obtain multiple grammatical features.

[0119] The process of building a neural network model based on multiple grammatical features in S4 includes:

[0120] Multiple grammatical features are converted into numerical data. For structured features (such as control flow and data flow graphs), graph embedding technology is used to convert them into vector representations. Specifically:

[0121] View control and data flow as graphs, where nodes may represent statements or operations in a program, and edges represent the direction of control or data flow;

[0122] Each node is encoded as a vector, which contains the information of the node itself and its neighbors;

[0123] Use DiffPool to aggregate multiple node vectors into a graph-level vector representation, that is, to encode the entire control flow or data flow graph into a single vector;

[0124] For specific features in the control flow and data flow (depth of loops, complexity of conditional branches), these numerical features are directly computed and provided as additional input features to the neural network.

[0125] The LSTM layer is used to build a model to capture long-term dependencies in time series. The basic architecture of the model is as follows:

[0126] Input layer: receives encoded feature data;

[0127] LSTM layer: Multiple LSTM layers can be used to enhance the learning ability of the model;

[0128] Fully connected layers: Dense layers are added after the LSTM layer to further extract features from the output of the LSTM.

[0129] Output layer: Use one neuron and sigmoid activation function as the output layer.

[0130] The binary cross entropy loss function and SGD algorithm are used to optimize the model, specifically:

[0131] 1) The binary cross entropy loss function is a commonly used loss function when dealing with binary classification problems. Its main purpose is to quantify the difference between the probability distribution predicted by the model and the distribution of the actual label. The mathematical expression of this function is as follows:

[0132]

[0133] in, is the true label of the i-th sample, is the probability predicted by the model, and N is the total number of samples. This function penalizes predictions where the predicted probability differs greatly from the actual label, thereby prompting the model to improve the accuracy of the prediction.

[0134] 2) Stochastic gradient descent algorithm, which is used to optimize the parameters of the machine learning model to minimize the loss function. Its update rule is as follows:

[0135]

[0136] Among them, θ represents the model parameters, η is the learning rate, and ∇ θ J is the gradient of the loss function J with respect to the parameter θ, x (i) and $y (i) is a randomly selected training sample and its label;

[0137] SGD uses only one (or a small batch of) examples per update, which makes the algorithm run faster and helps the model escape from local minima.

[0138] 3) The main hyperparameters include:

[0139] Learning rate: controls the amplitude of each parameter update. If the learning rate is too high, the model may oscillate or diverge near the optimal solution; if it is too low, it will lead to slow convergence.

[0140] Batch size: determines the number of samples used for each parameter update. A smaller batch size can improve the generalization ability of model training, but may increase the noise and instability of the training process.

[0141] Time steps: The time step number determines the length of the input sequence considered by the model. Inappropriate time steps may lead to missing or redundant information.

[0142] Adjust the hyperparameters based on the model's performance to make the model's prediction results more accurate.

[0143] Embodiment 2: An electronic device comprises a processor and a memory connected to the processor for storing instructions executable by the processor, wherein the processor is used to execute a program defect detection method based on multiple grammar characteristics of the above embodiment 1.

[0144] Embodiment 3: A server comprises at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor so that the at least one processor executes a program defect detection method based on multiple grammar features as in Embodiment 1.

[0145] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.

[0146] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A program defect detection method based on multiple grammar characteristics, characterized in that: The method comprises the following steps: using a parser to parse the source code of a program; extracting a plurality of grammatical features from the grammatical structure obtained by parsing; Associating multiple grammatical features to obtain multiple grammatical features; establishing a neural network model based on the multiple grammatical features, and using defect samples to train the neural network model; using the trained neural network model to predict potential defects in the target code; the process of extracting and parsing multiple grammatical features in the grammatical structure obtained includes: analyzing the declaration, use and life cycle of variables in the program to obtain the role and scope of influence of the variables in the program; tracking the definition and call of functions, identifying the control flow statements in the program and analyzing the paths and conditions of the control flow statements; tracking the assignment, transfer and reference of data in the program to obtain the dependency of data flow; identifying the call and data transfer relationship between program modules to obtain the dependency between modules; the process of extracting and parsing multiple grammatical features in the grammatical structure obtained also includes a first optimization scheme and a second optimization scheme; wherein the first optimization scheme is to optimize the parser algorithm and data structure, specifically including: using a compact data structure to represent a grammatical tree or a grammatical structure; building a memory pool, First, allocate a memory block of a certain size and obtain it from the memory pool when needed; use pointers or references to pass data and disable explicit data copying; cache and reuse the parsing results that are frequently accessed or used; the second optimization solution is to use incremental compilation technology to recompile the changed files and their dependencies, specifically including: establishing a dependency graph for the entire project, including the dependencies and compilation order between files, and monitoring changes in source code files by listening to changes in the file system; when changes in source code files are detected, compare the dependency graphs before and after the changes to identify the affected files and their dependencies; based on the affected files and their dependencies, update the compilation task queue and add the files that need to be recompiled to the queue; during the incremental compilation process, only recompile the files and their dependencies in the queue, and for files that have already been compiled, update the target files through incremental updates; after the incremental compilation is completed, update the build results and outputs, and clean up intermediate files and target files that are no longer needed.

2. The method for detecting program defects based on multiple grammar characteristics according to claim 1, characterized in that: The process of using a parser to parse the source code of a program includes: defining corresponding grammar rules for a target programming language or a domain-specific language, and generating a parser based on the grammar rules, wherein the grammar rules are represented by a context-free method; using the parser to parse the program source code as input to obtain a grammatical structure of a specified form.

3. The method for detecting program defects based on multiple grammar characteristics according to claim 2, characterized in that: The process of generating the parser according to grammatical rules includes: creating a grammar file according to the grammatical characteristics of the source code, using extended Backus-Naur form to describe the grammatical rules; defining lexical rules and grammatical rules in the grammar file, and generating a parser according to the grammatical rules in the grammar file.

4. The method for detecting program defects based on multiple grammar characteristics according to claim 2, characterized in that: The process of using a parser to parse the input program source code includes: using the parser to perform lexical analysis and syntactic analysis on the source code. While performing syntactic analysis, the parser processes lexical units one by one according to grammatical rules and constructs a syntax tree in a bottom-up manner; wherein the nodes of the syntax tree include grammatical units replaced by grammatical analysis and lexical units that have not been replaced in the grammatical analysis.

5. The method for detecting program defects based on multiple grammar characteristics according to claim 1, characterized in that: The process of associating multiple grammatical features to obtain multiple grammatical properties includes: converting the extracted grammatical features into item sets or transaction sets; performing frequent item set mining to obtain grammatical feature combinations with a high frequency of co-occurrence; generating association rules based on the results of frequent item set mining to obtain the association relationship between multiple grammatical features.

6. The method for detecting program defects based on multiple grammar characteristics according to claim 5, characterized in that: When analyzing the frequency of occurrence between single data items, the item set form is used to represent each grammatical feature as a single item; when analyzing the frequency of occurrence of the entire data set, the transaction set form is used to represent each program fragment or source code file as a transaction; wherein each transaction corresponds to a feature of the program source code.

7. The method for detecting program defects based on multiple grammar characteristics according to claim 1, characterized in that: The process of establishing a neural network model based on multiple grammatical features includes: converting multiple grammatical features into numerical data, and converting structured features into vector representations using graph embedding technology; using the LSTM layer to build a model to receive the converted data and capture long-term dependencies in time series; and using the binary cross entropy loss function and SGD algorithm to optimize the neural network model.

8. An electronic device, comprising a processor and a memory connected to the processor for storing instructions executable by the processor, characterized in that: The processor is used to execute a program defect detection method based on multiple grammar characteristics as described in any one of claims 1-7.

9. A server, characterized in that: It includes at least one processor and a memory communicatively connected to the processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the processor so that the at least one processor executes a program defect detection method based on multiple grammar features as described in any one of claims 1-7.