Low-code visual programming system based on bidirectional AST dynamic parsing
Through the user code optimization module, the user's modification characteristics and weights are analyzed, and the code enhancement model is used to optimize the code automatically generated by the low-code system, which solves the problem that the system needs to automatically generate codes and improves the efficiency of efficient user style matching and low-code development.
Patent Information
- Application Number
- CN202510781255.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2045-06-12
AI Technical Summary
In the low-code development process, in the low-code visual programming system based on bidirectional AST dynamic analysis, the code automatically generated by the system has not been deeply optimized, resulting in multiple modifications from users, which increases the overhead of forward resolution and the cost of visual programming. Each update of the user will lead to global updates, and the overhead of dynamic analysis process is too high.
Through the user code optimization module, the code mark sequence and AST structure before and after user modification are obtained, similarity and complexity change indicators are analyzed, code modification characteristics and weights are determined, and the code automatically generated code is optimized using the trained code enhancement model to reduce the user modification frequency and analysis overhead.
It effectively reduces users' multiple code modification needs, reduces the overhead of forward parsing, improves development efficiency and code consistency, and facilitates maintenance of optimized code that conforms to user style.
Smart Images

Figure CN120335861B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electronic digital data processing technology, and in particular to a low-code visual programming system based on bidirectional AST dynamic parsing. Background Art
[0002] With the development of information technology, the demand for software development is growing. Traditional programming methods require developers to possess specialized programming knowledge and skills, but they suffer from drawbacks such as large amounts of code, long development cycles, and high costs. To address this issue, low-code development platforms have emerged. These platforms enable the rapid construction of application systems through graphical interfaces and minimal code, aiming to reduce the complexity and cost of software development while improving development efficiency and flexibility.
[0003] Currently, in the low-code development process, low-code visual programming systems based on bidirectional AST (Abstract Syntax Tree) dynamic parsing have certain advantages in improving development efficiency and lowering technical barriers. The bidirectional AST dynamic parsing mechanism is divided into forward parsing and reverse parsing. Forward parsing converts visual operations (drag and drop, configuration) into AST nodes in real time to generate executable code; reverse parsing is to dynamically update the AST and synchronize it to the visual interface when directly modifying the code to achieve bidirectional consistency. During forward parsing, because the code automatically generated by the system may not have been deeply optimized, when the executable code automatically generated by the system does not meet the user's requirements, the user will make multiple changes on their own, which in turn increases the cost of the entire visual programming and the overhead of forward parsing. In addition, during the bidirectional AST dynamic parsing process, each user update will be globally updated at the visual interface and code level, resulting in excessive overhead in the dynamic parsing process. Summary of the Invention
[0004] In order to solve the above technical problems, the purpose of the present invention is to provide a low-code visual programming system based on bidirectional AST dynamic parsing. The technical solutions adopted are as follows:
[0005] In a first aspect, the present invention provides a low-code visual programming system based on bidirectional AST dynamic parsing, the system including a user code optimization module, the user code optimization module including:
[0006] The data acquisition module is used to obtain the tag sequence of the code before and after each modification and the AST structure formed by the tag sequence when the user modifies the system-generated code in the code editor;
[0007] The module for obtaining indicators before and after modification is used to determine the similarity between the AST structures before and after each modification, as well as the complexity change indicators of the tag sequences before and after each modification;
[0008] A modification feature acquisition module, configured to: determine a code modification feature corresponding to each modification based on the similarity and the complexity change index;
[0009] A weight acquisition module is used to determine a code modification feature learning weight corresponding to each modification based on the code modification feature;
[0010] The model acquisition module is used to: train the constructed code enhancement model based on the code before and after several modifications and the code modification feature learning weights to obtain a trained code enhancement model;
[0011] The code optimization processing module is used to optimize the code automatically generated for each user visual operating system during the drag-and-drop interface construction process using the trained code enhancement model.
[0012] In conjunction with the first aspect above, in some possible implementations, the module for obtaining pre- and post-modification indicators includes:
[0013] A similarity acquisition unit is used to determine the similarity between the AST structures before and after each modification based on the difference in the number of nodes and the difference in the number of layers between the AST structures before and after each modification;
[0014] The complexity change index acquisition unit is used to: determine the number of code complexity skeletons and the code complexity of the marker sequence, and determine the complexity change index of the marker sequence before and after each modification based on the difference in the number of code complexity skeletons and the difference in code complexity between the marker sequences before and after each modification.
[0015] In combination with the first aspect above, in some possible implementations, the similarity acquisition unit includes:
[0016] A first processing value acquisition subunit is configured to determine a first absolute value of a difference in the number of nodes between the AST structures before and after each modification, and perform negative correlation mapping processing on the first absolute value of the difference to obtain a first negative correlation mapping processing value;
[0017] A second processing value acquisition subunit is configured to determine a second absolute value of a difference in the number of layers between the AST structures before and after each modification, and perform negative correlation mapping processing on the second absolute value of the difference to obtain a second negative correlation mapping processing value;
[0018] The similarity acquisition subunit is used to determine the product of the first negative correlation mapping processing value and the second negative correlation mapping processing value as the similarity between the AST structures before and after each modification.
[0019] In conjunction with the first aspect above, in some possible implementations, the complexity change indicator acquisition unit includes:
[0020] The code complexity skeleton quantity obtaining subunit is configured to: determine a first total quantity of keywords and separators contained in the tag sequence as the code complexity skeleton quantity of the tag sequence;
[0021] A code complexity acquisition subunit is used to: match the values in the value field corresponding to the keywords and delimiters contained in the tag sequence with the values in the value field corresponding to the keywords in the preset keyword set and the delimiters in the delimiter set, to determine a second total number of matching keywords and delimiters; and determine the ratio of the second total number to the code complexity skeleton number as the code complexity of the tag sequence.
[0022] In combination with the first aspect above, in some possible implementations, the complexity change index obtaining unit further includes:
[0023] The skeleton quantity difference obtaining subunit is used to: determine the absolute value of the third difference in the number of code complexity skeletons between the tag sequence before and after each modification, and obtain the code complexity skeleton quantity difference;
[0024] The mapping value acquisition subunit is used to: determine a positive correlation mapping value of the difference between the code complexity of the tag sequence before each modification and the code complexity of the tag sequence after the modification;
[0025] The complexity change index acquisition subunit is used to: normalize the product of the difference in the number of code complexity skeletons and the positive correlation mapping value to obtain the complexity change index of the tag sequence before and after each modification.
[0026] In combination with the first aspect above, in some possible implementations, the modification feature acquisition module is used to: determine the ratio of the similarity and the complexity change index before and after each modification as the code modification feature corresponding to each modification.
[0027] In combination with the first aspect above, in some possible implementations, the weight acquisition module includes:
[0028] an accumulated value obtaining unit, configured to: determine an accumulated value of all the code modification features;
[0029] The learning weight obtaining unit is used to determine the ratio of each code modification feature to the accumulated value as the code modification feature learning weight corresponding to each modification.
[0030] In combination with the first aspect above, in some possible implementations, the model acquisition module includes:
[0031] A loss function determination unit, used to: determine the loss function of the code enhancement model during the training process;
[0032] The model training unit is used to: use the code before each modification as the input of the code enhancement model, use the code after each modification as the output of the code enhancement model, and set the weight value of the code before each modification to the product of the code modification feature learning weight and the preset overall weight, and train the code enhancement model to obtain a trained code enhancement model.
[0033] In combination with the above first aspect, in some possible implementations, the code enhancement model is a neural network model.
[0034] In combination with the above-mentioned first aspect, in some possible implementations, the neural network model is a CodeT5 model.
[0035] In a second aspect, the present invention further provides a user code optimization method applied to a low-code visual programming system based on bidirectional AST dynamic parsing, the method comprising:
[0036] Obtaining the token sequence of the code before and after each modification and the AST structure formed by the token sequence when the user modifies the system-generated code in the code editor;
[0037] Determine the similarity between the AST structures before and after each modification, as well as the complexity change index of the token sequence before and after each modification;
[0038] Determining a code modification feature corresponding to each modification based on the similarity and the complexity change index;
[0039] Determining a code modification feature learning weight corresponding to each modification based on the code modification feature;
[0040] Based on the code before and after several modifications and the code modification feature learning weights, the constructed code enhancement model is trained to obtain a trained code enhancement model;
[0041] The trained code enhancement model is used to optimize the code automatically generated for each user visual operating system during the drag-and-drop interface construction process.
[0042] The present invention has the following beneficial effects: the present invention analyzes the tag sequence of the code before and after each modification by the user and the AST structure formed by the tag sequence, and determines the code modification feature learning weight corresponding to each modification based on the similarity between the AST structures before and after each modification and the complexity change index of the tag sequence before and after each modification, and trains the constructed code enhancement model based on the code before and after the modification and the code modification feature learning weight, so that the code enhancement model learns the user's code modification features to obtain a trained code enhancement model, and finally uses the trained code enhancement model to optimize the code automatically generated for each user's visual operating system during the drag-and-drop interface construction process. The present invention deeply optimizes the code automatically generated by the system based on the user's code modification style, thereby avoiding the user's own multiple modifications to the code, effectively reducing the cost of the entire visual programming and the overhead of forward parsing. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0044] Figure 1 Schematic diagram of the composition of the AST structure of an embodiment of the present invention;
[0045] Figure 2 This is a schematic diagram of the structure of a user code optimization module according to an embodiment of the present invention;
[0046] Figure 3 This is a schematic diagram of an embodiment of the present invention before code optimization;
[0047] Figure 4 This is a schematic diagram of code optimization according to an embodiment of the present invention;
[0048] Figure 5 This is a flowchart of the steps of a user code optimization method applied to a low-code visual programming system based on bidirectional AST dynamic parsing according to an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In order to clearly illustrate the technical features of this solution, the present invention is described in detail below through specific implementation methods in conjunction with the accompanying drawings.
[0050] Embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments of the present invention are for illustrative purposes only and are not intended to limit the scope of protection of the present invention.
[0051] It should be understood that the various steps described in the method embodiments of the present invention may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0052] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.
[0053] It should be noted that the concepts of "first" and "second" mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0054] Although operations or steps are described in a particular order in the drawings in the embodiments of the present invention, this should not be understood as requiring that these operations or steps be performed in the particular order shown or in a serial order, or that all of the operations or steps shown be performed to obtain a desired result. In the embodiments of the present invention, these operations or steps may be performed serially; they may also be performed in parallel; or a portion of these operations or steps may be performed.
[0055] At the same time, it is understood that the data involved in the technical solutions of the present invention (including but not limited to the data itself, the acquisition or use of the data) must comply with the requirements of relevant laws, regulations and relevant provisions. Unless otherwise defined, all technical and scientific terms used in this invention have the same meanings as those commonly understood by those skilled in the art to which this invention belongs, and all parameters or indicators in the formulas involved in this invention are normalized values to eliminate dimension effects.
[0056] The following will introduce in detail a low-code visual programming system based on bidirectional AST dynamic parsing provided by an embodiment of the present invention in conjunction with the accompanying drawings.
[0057] This embodiment of the present invention provides a low-code visual programming system based on bidirectional AST dynamic parsing. This low-code visual system comprises a front-end layer, a parsing layer, and an execution layer. The front-end layer includes a visual editor (including a component library or logic canvas) and a code editor (supporting syntax highlighting and real-time AST feedback). The parsing layer includes an AST generator, a bidirectional mapping module, and a dynamic optimization engine. The execution layer includes a JIT compiler and a distributed task scheduler.
[0058] The low-code visualization system implements the bidirectional AST dynamic parsing process, which includes forward parsing and reverse parsing:
[0059] Forward parsing: Generates an AST based on visual operations. Specifically, when a user drags a component, a corresponding AST node is generated based on the component type and its properties are populated. The AST consists of nodes, each representing a grammatical structure. Nodes typically contain a type, a value, and other relevant information.
[0060] Reverse parsing: When the user modifies the code, the AST of the code is reconstructed and displayed synchronously on the visual editor.
[0061] The low-code visualization system mainly includes four stages for low-code project development: selecting project templates, visual design, learning user code styles, and performing user visual operations. The following is a detailed introduction to these four stages:
[0062] 1. Select a project template: Select a preset project template (such as web application, mobile form, IoT data processing, etc.) according to the required business scenario. The system automatically generates the initial AST structure and associated code framework. Figure 1 A schematic diagram showing the composition of the AST structure.
[0063] 2. Visual Design: This is divided into drag-and-drop interface construction and code editor construction. Drag-and-drop interface construction focuses on visual operations and AST generation, while code editor construction focuses on the two-way conversion between text and AST. The two achieve seamless collaboration through dynamic AST parsing. The following is a detailed introduction to the main implementation process of drag-and-drop interface construction and code editor construction:
[0064] (2.1) Drag-and-drop interface construction: Users drag UI elements (such as buttons, tables, and input boxes) from the component library to the canvas, and the system automatically generates corresponding AST nodes (such as <uibutton id="btnSubmit">), and component properties and logic arrangement (such as conditional judgment, API call, loop control, etc.) can be set on the canvas.
[0065] During the drag-and-drop UI construction process, each visual operation (such as moving components, modifying logical branches, etc.) triggers a global update of the AST, which requires forward parsing and a global AST update. This results in excessive overhead for the overall dynamic parsing process, leading to the following actions:
[0066] For each visual operation, first determine the corresponding component and its corresponding dependencies. When a user performs a visual operation, the specific name of the visual operation (e.g., "Modify Button 1 Properties") is obtained through the event listening mechanism. Then, the component designed for this visual operation and its corresponding dependencies are determined. For example, if the visual operation is to modify Button 1 Properties, the component designed for this visual operation is Button 1, and the corresponding operation is Modify Properties (Modify Properties corresponds to UI Rendering). Therefore, Button 1's dependency is UI Rendering.
[0067] Then, the AST is updated, that is, the nodes of the corresponding component and its corresponding dependencies are located in the AST structure and updated.
[0068] Finally, after updating the AST, locate the corresponding component in the code editor and rewrite the corresponding class name and function to obtain the updated code. For example, if the visual operation involves modifying the properties of Button 1, after updating the AST, locate Button 1 in the code editor. For example, if Button 1 is named "btnSubmit," search for the class name and corresponding function containing "btnSubmit" in the code editor. Then, rewrite only the corresponding class name and function to obtain the updated code.
[0069] When the user does not actively update the global template or switch to the code editor to build, each visualization operation is locally forward parsed in the above manner.
[0070] The above method locates the AST update nodes during the forward parsing and reverse parsing processes, thereby partially updating the AST, thereby effectively reducing the overhead during the dynamic parsing process.
[0071] Conversely, when the user proactively updates the global template, the system automatically updates the AST and code globally, making it easier for the user to continue with subsequent operations. When the user switches to the code editor build, it means that the user is dissatisfied with the drag-and-drop interface build results or the drag-and-drop page does not have the operations they need. In this case, to ensure that the user's operation results are accurately and promptly displayed after the code editor operation, the system automatically updates the AST and code globally when the user switches to the code editor build.
[0072] The code update process described above uses the Babel tool to perform a lightweight transformation on the updated AST, generating executable code. The generated code is then fed into a pre-trained code enhancement model for optimization, resulting in the optimized code. This code optimization helps align the overall project code style with the user style as closely as possible, avoiding multiple code modifications by the user. This effectively reduces the overall cost of visual programming and forward parsing, making it easier for users to review code and reducing the cost of subsequent code maintenance. Since the process of acquiring the pre-trained code enhancement model will be detailed in the subsequent user code style learning process, it will not be repeated here.
[0073] (2.2) Code Editor Construction: When the user modifies the generated code directly in the code editor, the IDE plug-in or file monitoring service captures the scope of the code improvement. Specifically, the improved class name and corresponding function are obtained, and then the following operations are performed:
[0074] First, the lexical analyzer breaks down the user-modified code string into a series of tokens. This process is conventional. For example, if the code string is "net a = 1," the lexical analyzer will break it down into the following tokens: { type: 'keyword', value: 'net'}, { type: 'identifier', value: 'a'}, { type: 'punctuator', value: '='}, { type: 'numeric', value: '1'}, { type: 'punctuator', value: ';'}.
[0075] Then, the compiler organizes the token sequence (subsequently recorded as token sequence 1) into an AST structure based on the analysis results of the lexical analyzer, recorded as AST structure 1, and at the same time obtains the token sequence before improvement (subsequently recorded as token sequence 2) and the AST structure corresponding to the code in the improvement scope, and records the AST structure as AST structure 2.
[0076] Finally, use an AST difference tool (such as GumTree) to compare the differences between AST structure 1 and AST structure 2, locate the changed nodes, and update the corresponding logical branches and UI components in the visualization canvas.
[0077] It should be understood that in special cases, when the modified code cannot be mapped to the existing AST node (such as when the user introduces an undefined variable when editing the code), the user can choose to "overwrite" or "keep the conflicting part".
[0078] 3. User code style learning: During the reverse parsing process, the code input by the user usually has a distinct personal style. Therefore, during forward parsing, when the system automatically generates executable code that does not meet the user's requirements, the user will make changes on their own, thereby increasing the cost of the entire visual programming and the overhead of forward parsing. To this end, a user code optimization module is set up in the low-code visual programming system. The user code optimization module is used to learn the user's code style features, obtain a pre-trained code enhancement model, and use the code enhancement model to optimize the code automatically generated by the system, so as to obtain optimized code that meets the user's requirements, avoiding multiple modifications to the code by the user himself, which is conducive to reducing the cost of the entire visual programming and the overhead of forward parsing.
[0079] Among them, such as Figure 2 As shown, the user code optimization module is specifically composed of six functional modules that can realize corresponding functions, and these six functional modules are respectively a data acquisition module 100, a pre- and post-modification indicator acquisition module 200, a modification feature acquisition module 300, a weight acquisition module 400, a model acquisition module 500 and a code optimization processing module 600. In combination with the implementation functions of these six functional modules, the user code optimization module learns the user code style features, obtains a pre-trained code enhancement model, and then uses the code enhancement model to optimize the code automatically generated by the system. The specific implementation process is introduced in detail below.
[0080] The data acquisition module 100 is used to acquire the tag sequence of the code before and after each modification and the AST structure formed by the tag sequence when the user modifies the system-generated code in the code editor.
[0081] Specifically, during the code editor construction process in the visual design stage, the tag sequence of the code before and after the modification and the AST structure composed of the tag sequence are obtained each time the user directly modified the generated code in the code editor in the past, that is, the tag sequence 1 of the modified code obtained by the above-mentioned code editor construction part and the AST structure 1 composed of the tag sequence 1, and the tag sequence 2 of the code before the modification and the AST structure 2 composed of the tag sequence 2.
[0082] The pre- and post-modification index acquisition module 200 is used to determine the similarity between the AST structures before and after each modification, and the complexity change index of the tag sequence before and after each modification.
[0083] Specifically, the similarity between the AST structures before and after each modification is quantified, and the similarity is used to reflect the degree of difference between the AST structures before and after each modification. For example, the smaller the value of the similarity, the greater the difference between the AST structure corresponding to the newly input code after the user's modification and the original AST structure, and the greater the user's dissatisfaction with the original code result or visual layout. At the same time, the complexity change index of the tag sequence before and after each modification is quantified, and the complexity change index is used to reflect the degree of complexity of the newly input code after the user's modification compared to the code generated by the original system. For example, the larger the value of the complexity change index, the higher the degree of complexity of the newly input code compared to the code generated by the original system.
[0084] The modification feature acquisition module 300 is used to determine the code modification feature corresponding to each modification according to the similarity and the complexity change index.
[0085] Specifically, based on the similarity between the AST structures before and after each modification, as well as the complexity change index of the tag sequence before and after each modification, the code modification feature corresponding to each modification is determined. This code modification feature reflects the personal style contained in the newly input code after the user's modification. For example, the less similar the AST structure of the newly input code after the user's modification is to the original system-generated code, and the higher the complexity of the newly input code after the modification is compared to the original system-generated code, the higher the possibility that the newly input code after the user's modification contains personal style, and the larger the value of the corresponding code modification feature.
[0086] The weight acquisition module 400 is used to determine the code modification feature learning weight corresponding to each modification according to the code modification feature.
[0087] Specifically, each time a user builds code in a code editor, that is, each time a code modification is made, the code modification features corresponding to the modification can be obtained, and then based on these code modification features, the code modification feature learning weight corresponding to each modification can be determined.
[0088] The model acquisition module 500 is used to train the constructed code enhancement model based on the code before and after several modifications and the code modification feature learning weights to obtain a trained code enhancement model.
[0089] Specifically, a training data set is constructed based on the code before and after multiple modifications and the code modification feature learning weights, and the constructed code enhancement model is trained to enable the code enhancement model to learn the personal style features of the user's code modification, thereby obtaining a trained code enhancement model, that is, a pre-trained code enhancement model.
[0090] The code optimization processing module 600 is used to optimize the code automatically generated for each user visual operating system during the drag-and-drop interface construction process using the trained code enhancement model.
[0091] Specifically, the code automatically generated for each user's visual operating system during the drag-and-drop interface construction process is input into the pre-trained code enhancement model, and the code enhancement model can output optimized code that conforms to the user's personal style.
[0092] 4. Execute user visual operations: After the user completes the code editor, the overall AST structure is updated to adapt to the integrity and completeness of the code. The low-code visual programming system based on bidirectional AST dynamic parsing then performs multiple automated tests on the AST, including logic verification and integration testing. All updates are deployed to the canvas and cloud server, completing the low-code visual programming based on bidirectional AST dynamic parsing.
[0093] In a low-code visual programming system based on bidirectional AST dynamic parsing provided in this embodiment, a user code optimization module is set up and used to learn the features of the user when directly modifying the generated code in the code editor, and the code modification feature learning weight corresponding to each code modification is determined, so that the code before and after multiple modifications and the code modification feature learning weights are used to train the code enhancement model, so that the code enhancement model learns the personal style features of the user's code modification, and uses the trained code enhancement model to optimize the code automatically generated by the system during the drag-and-drop interface construction process, so as to obtain the optimized code that is adapted to the user's code style and meets the user's requirements, thereby avoiding the user's own multiple modifications to the code, effectively reducing the cost of the entire visual programming and the overhead of forward parsing.
[0094] In a possible implementation, the above-mentioned before-and-after modification indicator acquisition module 200 includes:
[0095] The similarity obtaining unit is used to determine the similarity between the AST structures before and after each modification based on the difference in the number of nodes and the difference in the number of layers between the AST structures before and after each modification.
[0096] Specifically, an AST structure typically involves multiple layers and includes multiple nodes. The more layers and nodes there are, the more complex the AST structure is, potentially including more nested relationships. Therefore, we analyze the differences in the number of nodes and the number of layers between the AST structures formed by the token sequences of the code before and after each modification to determine the similarity between the AST structures before and after each modification. The smaller the differences in the number of nodes and the number of layers, the higher the similarity between the AST structures before and after the modification.
[0097] In one example, the similarity acquisition unit includes: a first processing value acquisition sub-unit, used to: determine the first absolute value of the difference in the number of nodes between the AST structures before and after each modification, perform negative correlation mapping processing on the first absolute value of the difference, and obtain a first negative correlation mapping processing value; a second processing value acquisition sub-unit, used to: determine the second absolute value of the difference in the number of layers between the AST structures before and after each modification, perform negative correlation mapping processing on the second absolute value of the difference, and obtain a second negative correlation mapping processing value; a similarity acquisition sub-unit, used to: determine the product of the first negative correlation mapping processing value and the second negative correlation mapping processing value as the similarity between the AST structures before and after each modification.
[0098] In this embodiment, the similarity between the AST structures before and after each modification is determined by the following formula:
[0099] ;
[0100] Where: Indicates the similarity between the AST structures before and after each modification, that is, the similarity between AST structure 1 and AST structure 2; Indicates the number of layers of the AST structure composed of the tag sequence of the code after each modification, that is, the number of layers of AST structure 1; Indicates the number of layers of the AST structure composed of the tag sequence of the code before each modification, that is, the number of layers of AST structure 2; The number of nodes in the AST structure consisting of the tag sequence of the code after each modification, that is, the number of nodes in AST structure 1; Indicates the number of nodes in the AST structure composed of the tag sequence of the code before each modification, that is, the number of nodes in AST structure 2.
[0101] The complexity change index acquisition unit is used to: determine the number of code complexity skeletons and the code complexity of the marker sequence, and determine the complexity change index of the marker sequence before and after each modification based on the difference in the number of code complexity skeletons and the difference in code complexity between the marker sequences before and after each modification.
[0102] Specifically, since the AST structure cannot accurately indicate the degree of difference in the lexical types of the new code constructed by the user during the code editing process, the type field in the token sequence corresponding to the user code indicates the grammatical type corresponding to each token. For example, keyword indicates that the token is a keyword, and identifier indicates that the token is an identifier. Among them, keywords and separators related to control flow, scope, and nested logic are complexity markers and are the skeleton of code complexity. Control flow keywords are keywords such as "if, else, while, for". By analyzing the distribution of keywords and separators in the token sequence of the code before each modification, the number of code complexity skeletons and code complexity of each token sequence are determined, and then based on the difference in the number of code complexity skeletons and the difference in code complexity between the token sequences before and after each modification, the complexity change index of the token sequence before and after each modification is determined.
[0103] In one example, the complexity change index acquisition unit includes: a code complexity skeleton quantity acquisition subunit, used to: determine a first total quantity of keywords and separators contained in the tag sequence as the code complexity skeleton quantity of the tag sequence; a code complexity acquisition subunit, used to: match the values in the value field corresponding to the keywords and separators contained in the tag sequence with the values in the value field corresponding to the keywords in the preset keyword set and the separators in the separator set, and determine a second total quantity of matching keywords and separators; and determine a ratio of the second total quantity to the code complexity skeleton quantity as the code complexity of the tag sequence.
[0104] Specifically, first, the preset control flow keyword set is , the default delimiter set is , where the corresponding value field in the tag represents the specific tag value.
[0105] Then, for each code modification, count the number of keywords in the token sequence corresponding to AST structure 1, that is, the token sequence of the modified code. , and the number of delimiters marked , then a total of A skeleton representing the complexity of the code, The number of code complexity skeletons represented as the token sequence corresponding to the AST structure 1 is recorded as .
[0106] Next, The value and keyword set in the value field corresponding to the tag The set of keywords and delimiters in The value in the value field corresponding to the delimiter in the string is matched. If there is a matching value, the corresponding second total number is increased by 1 to obtain the final second total number, which is the total matching number. .
[0107] Finally, determine the second total quantity Number of skeletons and code complexity The code complexity of the token sequence corresponding to AST structure 1, that is, the token sequence of the modified code, is the ratio of , at this time there is .
[0108] Similarly, we can count the number of keywords in the token sequence corresponding to AST structure 2, that is, the token sequence of the code before modification. and the number of markers as delimiters , thus obtaining the code complexity skeleton number of the token sequence corresponding to AST structure 2 , and keywords and delimiters in the token sequence and keyword sets and Final second total quantity , and finally get the code complexity of the token sequence corresponding to AST structure 2, that is, the token sequence of the code before modification , at this time there is .
[0109] Due to code complexity, the number of skeletons is second to the total number and The smaller the difference, the less important the change in the user's input code is, and the smaller the complexity of the corresponding code modification. compared to The smaller the number, the smaller the proportion of the skeleton mark representing the code complexity in the user's input code, and the smaller the complexity of the corresponding code modification. Therefore, according to the code complexity skeleton number and the total number and Differences in code complexity and The difference between the two can be used to determine the complexity change index of the tag sequence before and after the modification.
[0110] In one example, the above-mentioned complexity change index acquisition unit also includes: a skeleton number difference acquisition sub-unit, used to: determine the third absolute value of the difference in the number of code complexity skeletons between the tag sequence before and after each modification, and obtain the code complexity skeleton number difference; a mapping value acquisition sub-unit, used to: determine the positive correlation mapping value of the difference between the code complexity of the tag sequence before each modification and the code complexity of the tag sequence after modification; a complexity change index acquisition sub-unit, used to: normalize the product of the code complexity skeleton number difference and the positive correlation mapping value, and obtain the complexity change index of the tag sequence before and after each modification.
[0111] In this embodiment, the complexity change index of the tag sequence before and after each modification is determined by the following formula:
[0112] ;
[0113] Where: Indicates the complexity change index of the tag sequence before and after each modification; Represents the normalization function, which is used for normalization processing; It represents an exponential function with the natural constant e as the base, which is used to perform positive correlation mapping processing to obtain a positive correlation mapping value.
[0114] Furthermore, in a possible implementation, the modification feature acquisition module 300 is configured to determine a ratio of the similarity before and after each modification to the complexity change index as a code modification feature corresponding to each modification.
[0115] Specifically, the less similar the AST structure of the user-modified input code is to the original code, and the more complex it is compared to the original code, the more likely it is that the user-modified input code contains personal style features, and the larger the value of the corresponding code modification feature. Therefore, the ratio of the similarity and complexity change index before and after each modification is determined as the code modification feature corresponding to each modification. At this time, there is a code modification feature corresponding to each modification. .
[0116] Furthermore, in a possible implementation, the weight acquisition module 400 includes: an accumulated value acquisition unit, used to determine the accumulated value of all the code modification features; and a learning weight acquisition unit, used to determine the ratio of each code modification feature to the accumulated value as the code modification feature learning weight corresponding to each modification.
[0117] Specifically, each time a user modifies the code in the code editor, the code modification feature corresponding to the user's code modification is calculated, and all code modification features are accumulated to obtain a cumulative value. The ratio of each code modification feature to the cumulative value is determined to obtain the code modification feature learning weight corresponding to each modification:
[0118] ;
[0119] Where: Indicates that during the code editor construction process, when the user modifies the system-generated code in the code editor, The code modification feature learning weight corresponding to the first modification is the first modification constructed by the user in the code editor. The weight of the sub-code (referring to the modified code) in the subsequent learning of the user's code style; Indicates the number of times the user modified the system-generated code in the code editor, that is, the number of times the user built code during this code editor build process; and Respectively represent The first revision and The code modification characteristics corresponding to the modification.
[0120] Furthermore, in a possible implementation, the above-mentioned model acquisition module 500 includes: a loss function determination unit, used to: determine the loss function of the code enhancement model during the training process; a model training unit, used to: use the code before each modification as the input of the code enhancement model, use the code after each modification as the output of the code enhancement model, and set the weight value of the code before each modification to the product of the code modification feature learning weight and the preset overall weight, and train the code enhancement model to obtain a trained code enhancement model.
[0121] Specifically, a code enhancement model is constructed. In one example, the code enhancement model is a neural network model, more specifically, a CodeT5 model. A loss function of the code enhancement model during training is determined. The loss function may be a cross-entropy loss function.
[0122] A training data set is constructed using all the codes before and after modification and the code modification feature learning weights. 80% of the data in the training data set is used as the training set, and 20% of the data is used as the test set. The code enhancement model is trained using the training set and the test set. The model training type is code generation, thereby obtaining a trained code enhancement model. During the training process, the input of the model is the original code fragment, i.e., the code before modification. During the input process, the weight value of the input code before modification is set to the product of the code modification feature learning weight and the preset overall weight. The value of the preset overall weight can be set to 0.7. The output of the model is the optimized code after structured enhancement processing, i.e., the modified code. By setting the weight value of the input code before modification, the model can better learn the user's own code input style. Since the pre-training process of the neural network model based on the weight value is an existing technology, it will not be described in detail here. Using this trained code enhancement model, the code automatically generated for each user's visual operating system during the drag-and-drop interface construction process is optimized, thereby obtaining optimized code that conforms to the user's personal style. Figure 3 and Figure 4 Schematic diagrams before and after code optimization are shown respectively.
[0123] Based on the same inventive concept, Figure 5 As shown, an embodiment of the present invention further provides a user code optimization method applied to a low-code visual programming system based on bidirectional AST dynamic parsing, the method comprising:
[0124] Step S10: obtaining the tag sequence of the code before and after each modification and the AST structure formed by the tag sequence when the user modifies the system-generated code in the code editor;
[0125] Step S20: determining the similarity between the AST structures before and after each modification, and the complexity change index of the tag sequence before and after each modification;
[0126] Step S30: determining the code modification feature corresponding to each modification based on the similarity and the complexity change index;
[0127] Step S40: determining a code modification feature learning weight corresponding to each modification based on the code modification feature;
[0128] Step S50: Based on the code before and after several modifications and the code modification feature learning weights, the constructed code enhancement model is trained to obtain a trained code enhancement model;
[0129] Step S60: Utilizing the trained code enhancement model, the code automatically generated for each user visual operating system operation during the drag-and-drop interface construction process is optimized.
[0130] Since steps S10 to S60 in the user code optimization method correspond one-to-one to the implementation functions of the six modules included in the above-mentioned user code optimization module, and the implementation functions of the six modules included in the user code optimization module have been introduced in detail above, the user code optimization method will not be repeated here.
[0131] It should be noted that the above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. 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 make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the various embodiments of the present invention, and should all be included in the protection scope of the present invention.< / uibutton>
Claims
1. A low-code visual programming system based on bidirectional AST dynamic parsing, characterized by: The system includes a user code optimization module, and the user code optimization module includes: The data acquisition module is used to obtain the tag sequence of the code before and after each modification and the AST structure formed by the tag sequence when the user modifies the system-generated code in the code editor; The module for obtaining indicators before and after modification is used to determine the similarity between the AST structures before and after each modification, as well as the complexity change indicators of the tag sequences before and after each modification; A modification feature acquisition module, configured to: determine a code modification feature corresponding to each modification based on the similarity and the complexity change index; A weight acquisition module is used to determine a code modification feature learning weight corresponding to each modification based on the code modification feature; The model acquisition module is used to: train the constructed code enhancement model based on the code before and after several modifications and the code modification feature learning weights to obtain a trained code enhancement model; A code optimization processing module is used to optimize the code automatically generated for each user visual operating system during the drag-and-drop interface construction process using the trained code enhancement model; The module for obtaining indicators before and after modification includes: A similarity acquisition unit is used to determine the similarity between the AST structures before and after each modification based on the difference in the number of nodes and the difference in the number of layers between the AST structures before and after each modification; The complexity change index acquisition unit is used to: determine the number of code complexity skeletons and the code complexity of the marker sequence, and determine the complexity change index of the marker sequence before and after each modification based on the difference in the number of code complexity skeletons and the difference in code complexity between the marker sequences before and after each modification.
2. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 1 is characterized in that The similarity acquisition unit includes: A first processing value acquisition subunit is configured to determine a first absolute value of a difference in the number of nodes between the AST structures before and after each modification, and perform negative correlation mapping processing on the first absolute value of the difference to obtain a first negative correlation mapping processing value; A second processing value acquisition subunit is configured to determine a second absolute value of a difference in the number of layers between the AST structures before and after each modification, and perform negative correlation mapping processing on the second absolute value of the difference to obtain a second negative correlation mapping processing value; The similarity acquisition subunit is used to determine the product of the first negative correlation mapping processing value and the second negative correlation mapping processing value as the similarity between the AST structures before and after each modification.
3. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 1 is characterized in that: The complexity change index obtaining unit includes: The code complexity skeleton quantity obtaining subunit is configured to: determine a first total quantity of keywords and separators contained in the tag sequence as the code complexity skeleton quantity of the tag sequence; A code complexity acquisition subunit is used to: match the values in the value field corresponding to the keywords and delimiters contained in the tag sequence with the values in the value field corresponding to the keywords in the preset keyword set and the delimiters in the delimiter set, to determine a second total number of matching keywords and delimiters; and determine the ratio of the second total number to the code complexity skeleton number as the code complexity of the tag sequence.
4. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 3 is characterized in that: The complexity change index acquisition unit further includes: The skeleton quantity difference obtaining subunit is used to: determine the absolute value of the third difference in the number of code complexity skeletons between the tag sequence before and after each modification, and obtain the code complexity skeleton quantity difference; The mapping value acquisition subunit is used to: determine a positive correlation mapping value of the difference between the code complexity of the tag sequence before each modification and the code complexity of the tag sequence after the modification; The complexity change index acquisition subunit is used to: normalize the product of the difference in the number of code complexity skeletons and the positive correlation mapping value to obtain the complexity change index of the tag sequence before and after each modification.
5. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 1 is characterized in that The modification feature acquisition module is used to determine the ratio of the similarity before and after each modification to the complexity change index as the code modification feature corresponding to each modification.
6. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 1 is characterized in that: The weight acquisition module includes: an accumulated value obtaining unit, configured to: determine an accumulated value of all the code modification features; The learning weight obtaining unit is used to determine the ratio of each code modification feature to the accumulated value as the code modification feature learning weight corresponding to each modification.
7. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 1 is characterized in that: The model acquisition module includes: A loss function determination unit, used to: determine the loss function of the code enhancement model during the training process; The model training unit is used to: use the code before each modification as the input of the code enhancement model, use the code after each modification as the output of the code enhancement model, and set the weight value of the code before each modification to the product of the code modification feature learning weight and the preset overall weight, and train the code enhancement model to obtain a trained code enhancement model.
8. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 1 is characterized in that: The code enhancement model is a neural network model.
9. The low-code visual programming system based on bidirectional AST dynamic parsing according to claim 8 is characterized in that: The neural network model is the CodeT5 model.
Citation Information
Patent Citations
Code generation method and system, electronic equipment and storage medium
CN119621543A