A program code generation method and system

By pre-constructing program code processing units and automatically concatenating subroutine code based on input and output data types, the problems of low code writing efficiency and high error rate in existing technologies are solved, achieving efficient and low-error code generation.

CN114416095BActive Publication Date: 2026-06-19BEIJING ZHANXINZHANLI INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING ZHANXINZHANLI INFORMATION TECH CO LTD
Filing Date
2021-12-29
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Existing technologies suffer from repetitive work, low efficiency, and high error rates when writing programs with multiple semantic correspondences. This is especially true in new internet and consumer systems, where developers need to start from scratch to sort out each process, leading to increased development time and costs.

Method used

By pre-constructing multiple program code processing units, subroutine code is automatically concatenated according to the input and output data types of the program to be developed, generating target program code. The program code processing units are constructed using sample semantic information and random algorithms to achieve automated code generation.

🎯Benefits of technology

It improves code writing efficiency, reduces the chance of errors during the code writing process, and reduces project costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416095B_ABST
    Figure CN114416095B_ABST
Patent Text Reader

Abstract

This invention provides a method and system for generating program code. The method includes: acquiring a preset number of program code processing units, wherein each program code processing unit is provided with subroutine code corresponding to a specific function; and concatenating the subroutine code based on data type to obtain target program code. This invention, through the pre-construction of multiple program code processing units, automatically concatenates the subroutine code in the program code processing units according to the type of input and output data of the program to be developed, thereby completing the construction of the target program code, improving the efficiency of code writing, and reducing the probability of errors in the code writing process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and system for generating program code. Background Technology

[0002] In software development, a variable is often randomly manipulated according to its semantics to achieve specific purposes. Generally, to achieve such random manipulation, developers need to first construct a processing flow with corresponding semantics, understand the semantics, and then write the corresponding code based on those semantics. After writing the code, the program is then checked and tested.

[0003] When writing programs with multiple semantic meanings, developers need to understand the meaning of each semantic and write different code. Existing solutions are suitable for situations where the overall random processing requirement is small, projects vary greatly, and development time is ample. For new internet and consumer systems, for each independent random processing program, developers have to completely analyze every process and write code from scratch. A complete development process involves complex steps such as understanding semantics, writing code, and testing code. Although this approach can accurately consider every detail of the semantics, it involves a lot of repetitive work, severely reducing coding efficiency, and the error rate is also high due to the manual coding process.

[0004] Therefore, there is an urgent need for a program code generation method and system to solve the above problems. Summary of the Invention

[0005] To address the problems existing in the prior art, the present invention provides a method and system for generating program code.

[0006] This invention provides a method for generating program code, comprising:

[0007] Obtain a preset number of program code processing units, wherein each program code processing unit is equipped with subroutine code with a corresponding function;

[0008] Based on the data type, the subroutine code is concatenated to obtain the target program code.

[0009] According to a program code generation method provided by the present invention, before obtaining a preset number of program code processing units, the method further includes:

[0010] The global semantics of multiple samples are parsed to determine the data input and output processes in the global semantics of each sample. Based on each data input and output process, corresponding sample semantic information is generated, wherein the sample semantic information includes data input type information and output type information.

[0011] Based on the semantic information of the sample, match the corresponding subroutine code;

[0012] Random parameters are generated based on a random algorithm.

[0013] A program code processing unit is constructed based on the subroutine code, the sample semantic information, and the random parameters.

[0014] According to a program code generation method provided by the present invention, the step of concatenating the subroutine code based on data type to obtain target program code includes:

[0015] Step S1: Based on the output type information of the current program code processing unit, determine the next program code processing unit from multiple corresponding pre-assembled program code processing units;

[0016] Step S2: Concatenate the semantic information of the current program code processing unit and the semantic information of the next program code processing unit; concatenate the subroutine code of the current program code processing unit and the subroutine code of the next program code processing unit.

[0017] Step S3: Take the next program code processing unit as the current program code processing unit, and repeat steps S1 to S3 until the preset number of program code processing units are assembled to obtain the target program code and the corresponding target semantic information.

[0018] According to a program code generation method provided by the present invention, determining the next program code processing unit from multiple corresponding pre-assembled program code processing units based on the output type information of the current program code processing unit includes:

[0019] Based on the output type information, multiple corresponding pre-assembled program code processing units are determined;

[0020] Obtain the output range data of the current program code processing unit, and determine the data processing result range of each pre-assembled program code processing unit based on the output range data;

[0021] The pre-assembled program code processing unit whose data processing result range is less than the preset data range threshold is used as the next program code processing unit.

[0022] According to a program code generation method provided by the present invention, the step of matching corresponding subroutine code based on the sample semantic information includes:

[0023] Based on the sample semantic information and the preset code syntax, the corresponding subroutine code is matched.

[0024] The present invention also provides a program code generation system, comprising:

[0025] The program code acquisition module is used to acquire a preset number of program code processing units, wherein each program code processing unit is equipped with subroutine code with corresponding functions;

[0026] The program code concatenation module is used to concatenate the subroutine code based on data type to obtain the target program code.

[0027] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the above-described program code generation methods.

[0028] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the program code generation method described above.

[0029] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the above-described program code generation methods.

[0030] The present invention provides a program code generation method and system that, through a variety of pre-built program code processing units, automatically concatenates the subroutine code in the program code processing units according to the type of input and output data of the program to be developed, thereby completing the construction of the target program code, improving the efficiency of code writing and reducing the probability of errors in the code writing process. Attached Figure Description

[0031] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0032] Figure 1 A flowchart illustrating the program code generation method provided by the present invention;

[0033] Figure 2 A schematic diagram illustrating the target program code splicing process provided by the present invention;

[0034] Figure 3 A schematic diagram illustrating the process of concatenating program code and semantics based on a program code processing unit provided by the present invention;

[0035] Figure 4A schematic diagram of the structure of the program code generation system provided by the present invention;

[0036] Figure 5 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation

[0037] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0038] Figure 1 A flowchart illustrating the program code generation method provided by this invention is shown below. Figure 1 As shown, the present invention provides a program code generation method, including:

[0039] Step 101: Obtain a preset number of program code processing units, wherein each program code processing unit is provided with subroutine code for a corresponding function;

[0040] Step 102: Based on the data type, the subroutine code is concatenated to obtain the target program code.

[0041] In this invention, a program code processing unit can be understood as a processing unit that receives specific type of input data and generates specific type of output data. Each program code processing unit is constructed through the following steps: First, the pre-obtained global semantics of the samples are decomposed; then, the corresponding subroutine code is matched with the decomposed individual semantics (each individual semantics corresponds to one input and output process of data processing in the code), so that the attributes of a program code processing unit contain the subroutine code, and a program code processing unit database is constructed based on these. In the subsequent subroutine code splicing process, the corresponding subroutine code is selected from the data based on the data input and output types between each program code processing unit and spliced ​​together. At the same time, the semantics between each program code processing unit are also spliced ​​together to form a complete semantic description of the target program code.

[0042] Figure 2 This is a schematic diagram illustrating the target program code splicing process provided by the present invention, which can be referred to. Figure 2As shown, in this invention, a complete program input processing process is broken down into multiple parts, each corresponding to a program code processing unit. This program code processing unit has a "Lego"-like assembly function. Through preliminary semantic decomposition, after determining a certain number of such "Lego"-like program code processing units, the subroutine codes within these units are assembled (assembly between subroutine codes is based on a preset calling method). Correspondingly, the corresponding semantics are assembled (assembly between semantics is based on preset transition statements). Furthermore, for ease of understanding, this invention defines the assembled semantics as pipeline semantics, meaning that the semantics between pairs resemble a pipeline structure, describing the various processes from data input to output. Similarly, the assembled code is defined as pipeline code, meaning that the code between pairs resembles a pipeline structure, completing the data input and output processing process. This invention uses program code processing units to automatically generate target program code and corresponding target semantic information, thereby improving the efficiency of program code generation, saving engineering costs, and reducing the probability of errors in the code writing process.

[0043] The program code generation method provided by this invention automatically concatenates the subroutine code in the program code processing units according to the type of input and output data of the program to be developed and implemented through a variety of pre-built program code processing units, thereby completing the construction of the target program code, improving the efficiency of code writing and reducing the probability of errors in the code writing process.

[0044] Based on the above embodiments, before obtaining the preset number of program code processing units, the method further includes:

[0045] The global semantics of multiple samples are parsed to determine the data input and output processes in the global semantics of each sample, and corresponding sample semantic information is generated based on each data input and output process. The sample semantic information includes data input type information and output type information.

[0046] Based on the semantic information of the sample, match the corresponding subroutine code;

[0047] Random parameters are generated based on a random algorithm.

[0048] A program code processing unit is constructed based on the subroutine code, the semantic information, and the random parameters.

[0049] In this invention, during the construction process, program code processing units can be constructed into various different types based on different attribute definitions. The semantics and corresponding program generation processes of these different types of program code processing units are also clearly defined. Among them, program code processing units of the same type share the following characteristics:

[0050] 1. Acceptable input data types, such as numeric, string, list, and dictionary types.

[0051] 2. The data type of the output data obtained after processing by the corresponding program code in the program code processing unit. The data type of the output data can refer to the data type of the input data.

[0052] 3. Random parameter generation method: Each program code processing unit corresponds to a random parameter. This random parameter determines the difference between this program code processing unit and other program code processing units of the same type. For different random parameters, the same type of program code processing unit can become multiple program code processing units with different functions, producing different results for the same input. Specifically, the processing logic of a certain type of program code processing unit is an arithmetic operator (such as "+", "*", and " / ", corresponding to addition, multiplication, and division, respectively). According to a predetermined random algorithm, a parameter is randomly selected (this parameter is not specifically limited and is randomly generated, such as 2, which is an addition operation that increments the input variable by 2), thus determining the random parameter in the program code processing unit.

[0053] 4. The subroutine code that processes the input and obtains the output is a function of the program code processing unit parameter. That is, each subroutine code will change as the program code processing unit parameter changes. For each program code processing unit parameter, there is a unique subroutine code.

[0054] 5. The textual description of the input processing process (i.e., individual semantics) is also a function of the program code processing unit parameters. Each semantic will change with the change of the program code processing unit parameters, and each program code processing unit parameter will also correspond to unique semantic information. These are all set in advance. During the splicing process, the corresponding semantic information is spliced ​​directly without the need for manual additional semantic construction.

[0055] This invention decomposes the global semantics of a complete input / output processing procedure into a combination of multiple steps. Each step is described and processed according to its parameters, and different steps are closely linked through their own input / output types. The randomness of the parameters and the order of the steps ensures a high degree of diversity in the concatenated result, while the control of input / output types ensures that multiple concatenated steps can still form a complete target program code without coding errors. It should be noted that the global semantics of the samples can be obtained from a semantic sample library, which already stores various global semantics that completely describe the entire program. This invention selects global semantics from this semantic sample library for decomposition and analysis, thereby constructing various program code processing units.

[0056] Based on the above embodiments, the step of concatenating the subroutine code based on data type to obtain the target program code includes:

[0057] Step S1: Based on the output type information of the current program code processing unit, determine the next program code processing unit from multiple corresponding pre-assembled program code processing units;

[0058] Step S2: Concatenate the semantic information of the current program code processing unit and the semantic information of the next program code processing unit; concatenate the subroutine code of the current program code processing unit and the subroutine code of the next program code processing unit.

[0059] Step S3: Take the next program code processing unit as the current program code processing unit, and repeat steps S1 to S3 until the preset number of program code processing units are assembled to obtain the target program code and the corresponding target semantic information.

[0060] In this invention, after the previous program code processing unit (i.e., the current program code processing unit) processes the input data (based on the subroutine code within the program code processing unit), the input data type of the next program code processing unit is determined according to the data type of the output data of the current program code processing unit. In this invention, it is necessary to control the range of data transferred between program code processing units. Therefore, after determining the output type information of the current program code processing unit, multiple program code processing units to be concatenated are first obtained based on this output type information. The input type information of these units matches the output type information. Further, based on the data processing results generated between the current program code processing unit and each unit to be concatenated, the corresponding pre-concatenated program code processing unit is selected as the next program code processing unit. After determining the next program code processing unit, the subroutine codes corresponding to the two program code processing units are concatenated, and their corresponding semantics are also concatenated. Since the total number of required program code processing units has been predetermined, after the subroutine codes and semantics between all program code processing units are concatenated, the target program code and target semantic information are obtained.

[0061] Based on the above embodiments, determining the next program code processing unit from multiple corresponding pre-assembled program code processing units according to the output type information of the current program code processing unit includes:

[0062] Based on the output type information, multiple corresponding pre-assembled program code processing units are determined;

[0063] Obtain the output range data of the current program code processing unit, and determine the data processing result range of each pre-assembled program code processing unit based on the output range data;

[0064] The pre-assembled program code processing unit whose data processing result range is less than the preset data range threshold is used as the next program code processing unit.

[0065] Given that the data type is satisfied, the output of the previous program code processing unit may cause an error in the next program code processing unit. That is, because the data output by the previous unit exceeds a certain range, the subsequent program code processing unit cannot process it normally. Therefore, it is necessary to control the range of data passed between different program code processing units. At the same time, starting from the initial randomized input, the processing of multiple program code processing units with random parameters must be ensured to proceed smoothly without any errors.

[0066] Based on the above, this invention, by controlling the initial random input (e.g., limiting the assignment of input variables) and the range of random parameters of the program code processing unit, adds a modifying processing part to the specific processing of the program code processing unit. This ensures that for each different data type, after being processed by any program code processing unit, the result always converges to a predetermined range. For example, if the output data value of the previous program code processing unit is 1000, to ensure that the output data value in the subsequent program code processing unit does not exceed 10000 (a predefined range value), the value of the previous program code processing unit is calculated accordingly with the random parameters of each pre-assembled program code processing unit. For example, if the random parameter of one pre-assembled program code processing unit is multiplied by 5, and the random parameter of another pre-assembled program code processing unit is added by 5, then the latter pre-assembled program code processing unit can be used as the next program code processing unit. It should be noted that when the data processing results between multiple pre-assembled program code processing units and the output data of the current program code processing unit are all less than a preset data range threshold, the pre-assembled program code processing unit corresponding to the smallest data processing result can be selected.

[0067] Based on the above embodiments, the step of matching the corresponding subroutine code according to the sample semantic information includes:

[0068] Based on the sample semantic information and the preset code syntax, the corresponding subroutine code is matched.

[0069] In this invention, the program code processing unit can be constructed based on different preset code syntaxes, so that the target program code generated subsequently can be a code structure with multiple different syntaxes.

[0070] Figure 3 The schematic diagram of the program code and semantic concatenation process based on the program code processing unit provided by the present invention can be referred to. Figure 3As shown, firstly, the number of program code processing units required for a complete program flow is determined. Then, corresponding program code processing units are selected from a pre-built program code processing unit library. Based on the selected program code processing units, corresponding random parameters are generated, turning them into specific program code processing units to be used. The textual description of the process of processing input to obtain output is extracted as part of the semantics, and the program code that processes the input is extracted as part of the overall code. Further, based on the output data type of the previous program code processing unit, a set of program code processing units that can accept that type of input is selected from the program code processing unit library, and program code processing units are randomly selected from this set to complete the semantic concatenation and program code concatenation of the previous program code processing unit and the current program code processing unit. This process continues until a sufficient number of program code processing units are processed, finally obtaining the target program code and the corresponding target semantics.

[0071] This invention can automatically generate a large number of target code programs composed of program code processing units that handle input and output by pre-writing a small amount of subroutine code; each target code program can be unique, and under normal circumstances, there is little possibility of duplication (multiple combination methods can be generated based on different combinations between program code processing units).

[0072] The program code generation system provided by the present invention is described below. The program code generation system described below and the program code generation method described above can be referred to in correspondence.

[0073] Figure 4 A schematic diagram of the structure of the program code generation system provided by the present invention, such as... Figure 4 As shown, the present invention provides a program code generation system, including a program code acquisition module 401 and a program code splicing module 402. The program code acquisition module 401 is used to acquire a preset number of program code processing units, wherein each program code processing unit is provided with subroutine code with a corresponding function. The program code splicing module 402 is used to splice the subroutine code based on the data type to obtain the target program code.

[0074] The program code generation system provided by this invention automatically splices the subroutine code in the program code processing units according to the type of input and output data of the program to be developed and implemented through a variety of pre-built program code processing units, thereby completing the construction of the target program code, improving the efficiency of code writing and reducing the probability of errors in the code writing process.

[0075] The system provided by this invention is used to execute the above-described method embodiments. For specific processes and details, please refer to the above embodiments, which will not be repeated here.

[0076] Figure 5 This is a schematic diagram of the structure of the electronic device provided by the present invention, such as... Figure 5 As shown, the electronic device may include a processor 501, a communications interface 502, a memory 503, and a communication bus 504. The processor 501, communications interface 502, and memory 503 communicate with each other via the communication bus 504. The processor 501 can call logical instructions in the memory 503 to execute a program code generation method. This method includes: acquiring a preset number of program code processing units, wherein each program code processing unit is provided with subroutine code corresponding to a specific function; and concatenating the subroutine codes based on data type to obtain target program code.

[0077] Furthermore, the logical instructions in the aforementioned memory 503 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0078] On the other hand, the present invention also provides a computer program product, the computer program product including a computer program stored on a non-transitory computer-readable storage medium, the computer program including program instructions, and when the program instructions are executed by a computer, the computer is able to execute the program code generation method provided by the above methods, the method including: obtaining a preset number of program code processing units, wherein each program code processing unit is provided with subroutine code with a corresponding function; and concatenating the subroutine code based on data type to obtain target program code.

[0079] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the program code generation method provided in the above embodiments. The method includes: obtaining a preset number of program code processing units, wherein each program code processing unit is provided with subroutine code corresponding to a function; and concatenating the subroutine code based on data type to obtain target program code.

[0080] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0081] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0082] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A program code generation method characterized by, include: Obtain a preset number of program code processing units, wherein each program code processing unit is equipped with subroutine code with a corresponding function; Based on the data type, the subroutine code is concatenated to obtain the target program code; Before obtaining the preset number of program code processing units, the method further includes: The global semantics of multiple samples are parsed to determine the data input and output processes in the global semantics of each sample, and corresponding sample semantic information is generated based on each data input and output process. The sample semantic information includes data input type information and output type information. Based on the semantic information of the sample, match the corresponding subroutine code; Random parameters are generated based on a random algorithm. A program code processing unit is constructed based on the subroutine code, the sample semantic information, and the random parameters.

2. The program code generation method according to claim 1, characterized by, The step of concatenating the subroutine code based on data type to obtain the target program code includes: Step S1: Based on the output type information of the current program code processing unit, determine the next program code processing unit from multiple corresponding pre-assembled program code processing units; Step S2: Concatenate the semantic information of the current program code processing unit and the semantic information of the next program code processing unit; concatenate the subroutine code of the current program code processing unit and the subroutine code of the next program code processing unit. Step S3: Take the next program code processing unit as the current program code processing unit, and repeat steps S1 to S3 until the preset number of program code processing units are assembled to obtain the target program code and the corresponding target semantic information.

3. The program code generation method according to claim 2, characterized in that, The step of determining the next program code processing unit from multiple corresponding pre-assembled program code processing units based on the output type information of the current program code processing unit includes: Based on the output type information, multiple corresponding pre-assembled program code processing units are determined; Obtain the output range data of the current program code processing unit, and determine the data processing result range of each pre-assembled program code processing unit based on the output range data; The pre-assembled program code processing unit whose data processing result range is less than the preset data range threshold is used as the next program code processing unit.

4. The program code generation method according to claim 1, characterized in that, The step of matching the corresponding subroutine code based on the sample semantic information includes: Based on the sample semantic information and the preset code syntax, the corresponding subroutine code is matched.

5. A program code generation system, characterized in that, include: The program code acquisition module is used to acquire a preset number of program code processing units, wherein each program code processing unit is equipped with subroutine code with corresponding functions; The program code concatenation module is used to concatenate the subroutine code based on data type to obtain the target program code; The system is also used for: The global semantics of multiple samples are parsed to determine the data input and output processes in the global semantics of each sample, and corresponding sample semantic information is generated based on each data input and output process. The sample semantic information includes data input type information and output type information. Based on the semantic information of the sample, match the corresponding subroutine code; Random parameters are generated based on a random algorithm. A program code processing unit is constructed based on the subroutine code, the sample semantic information, and the random parameters.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the program code generation method as described in any one of claims 1 to 4.

7. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the program code generation method as described in any one of claims 1 to 4.

8. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the program code generation method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Code generation method and device

    CN111124378A