A method and device for generating code based on program flow chart

By extracting graphic data from the program flow chart and generating corresponding code, the problems of low efficiency and high error rate when writing complex programs manually are solved, and more efficient and accurate code generation is achieved.

CN119201084BActive Publication Date: 2025-05-16BEIJING GLOBAL CROWN JINYANG TECH DEV CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

When writing computer programs manually, especially when dealing with complex logical processes, it is easy to lead to low code writing efficiency and high error rates.

Method used

By obtaining the program flowchart of the tree structure, extracting graphic data, and traversing the search process path based on this data, codes representing the intent of the program flowchart are generated.

Benefits of technology

It reduces the error rate of code writing, improves the efficiency of code writing, and simplifies the implementation of complex logic by generating code consistent with the semantic logic of the program flow chart.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201084B_ABST
    Figure CN119201084B_ABST
Patent Text Reader

Abstract

The present invention provides a method and device for generating code based on a program flow chart, the method comprising: obtaining a program flow chart of a tree structure, the program flow chart being composed of a plurality of nodes and transfer lines between nodes, each transfer line being provided with an expression; extracting graphic data corresponding to the program flow chart; and based on the graphic data, traversing and searching the flow path of the program flow chart to generate code representing the intent of the program flow chart. In this solution, graphic data is extracted from the program flow chart of a tree structure, and the flow path of the program flow chart is traversed and searched based on the graphic data, thereby generating code representing the intent of the program flow chart, the program flow chart can intuitively reflect complex logical processes, and the created program flow chart is used to automatically generate code consistent with the graphic semantic logic of the program flow chart, which can reduce the error rate of code writing and improve the efficiency of code writing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for generating codes based on a program flow chart. Background Art

[0002] When writing computer programs, programmers are still required to write codes manually. The process of writing codes tests the programmers’ logic and understanding of programming languages. When encountering complex logical processes, programmers face a more difficult code writing task, and it is easy to make mistakes during the code writing process, resulting in low code writing efficiency. Summary of the invention

[0003] In view of this, an embodiment of the present invention provides a method and device for generating codes based on a program flow chart, so as to solve the problem of low code writing efficiency existing in manual code writing.

[0004] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0005] A first aspect of an embodiment of the present invention discloses a method for generating code based on a program flow chart, the method comprising:

[0006] Obtaining a program flow chart of a tree structure, wherein the program flow chart is composed of a plurality of nodes and transfer lines between the nodes, and an expression is set on each transfer line;

[0007] Extracting graphic data corresponding to the program flow chart;

[0008] Based on the graphic data, a flow path of the program flow chart is traversed and searched to generate a code representing the intent of the program flow chart.

[0009] Preferably, extracting the graphic data corresponding to the program flow chart includes:

[0010] Starting from the root node with the entry line added in the program flow chart, the transfer relationship is recorded according to the transfer sequence of each node to extract the graphic data corresponding to the program flow chart.

[0011] Preferably, based on the graphic data, traversing and searching the flow path of the program flow chart to generate a code representing the intent of the program flow chart includes:

[0012] Based on the graphic data, the flow path of the program flow chart is traversed and searched according to the transfer order of each node and the value of the expression on the transfer line to generate code representing the intent of the program flow chart, wherein the expression includes a transfer condition expression and / or an action expression.

[0013] Preferably, it also includes:

[0014] In the process of traversing and searching the flow path of the program flow chart, for the first target node in the program flow chart having multiple transfer lines, if the value of the expression on the first target transfer line of the first target node is true, then stop traversing and searching the flow path corresponding to the transfer line whose sequence number is after the first target transfer line of the first target node, and the first target transfer line is any one of the transfer lines of the first target node.

[0015] Preferably, it also includes:

[0016] In the process of traversing and searching the flow path of the program flow chart, for the second target node currently traversed, if the node to which the second target node is transferred downward along the second target transfer line is not a leaf node, a flag variable with an initial value of false is generated for the second target transfer line, the second target transfer line is any transfer line of the second target node, and the flag variable is used to avoid generating duplicate code;

[0017] Determining whether to assign the flag variable to true based on an expression on the transfer line involved in the process of traversing the search process path along the second target transfer line;

[0018] When the flag variable is true, the process path corresponding to the transfer line whose sequence number of the second target node is arranged after the second target transfer line is traversed and searched.

[0019] A second aspect of an embodiment of the present invention discloses a device for generating code based on a program flow chart, the device comprising:

[0020] An acquisition unit, used for acquiring a program flow chart of a tree structure, wherein the program flow chart is composed of a plurality of nodes and transfer lines between the nodes, and an expression is set on each transfer line;

[0021] An extraction unit, used for extracting graphic data corresponding to the program flow chart;

[0022] The search unit is used to traverse and search the flow path of the program flow chart based on the graphic data to generate a code representing the intention of the program flow chart.

[0023] Preferably, the extraction unit is specifically used for: starting from the root node with the entry line added in the program flow chart, recording the transfer relationship according to the transfer sequence of each node, so as to extract the graphic data corresponding to the program flow chart.

[0024] Preferably, the search unit is specifically used to: based on the graphic data, traverse and search the flow path of the program flow chart according to the transfer order of each node and the value of the expression on the transfer line to generate code representing the intent of the program flow chart, wherein the expression includes a transfer condition expression and / or an action expression.

[0025] Preferably, it also includes:

[0026] A stopping unit is used for stopping traversing and searching the process path of the program flow chart. For a first target node in the program flow chart having multiple transfer lines, if the value of an expression on a first target transfer line of the first target node is true, then stopping traversing and searching the process path corresponding to the transfer line whose sequence number is after the first target transfer line of the first target node, wherein the first target transfer line is any one of the transfer lines of the first target node.

[0027] Preferably, it also includes:

[0028] A generating unit, configured to generate a flag variable with an initial value of false for a second target transfer line during a process of traversing and searching the process path of the program flow chart, for a second target node currently traversed, if the node to which the second target node is transferred downward along a second target transfer line is not a leaf node, wherein the second target transfer line is any transfer line of the second target node, and the flag variable is used to avoid generating duplicate code;

[0029] a determination unit, configured to determine whether to assign the flag variable to true based on an expression on the transfer line involved in the process of traversing the search process path along the second target transfer line;

[0030] Accordingly, the search unit is also used for:

[0031] When the flag variable is true, the process path corresponding to the transfer line whose sequence number of the second target node is arranged after the second target transfer line is traversed and searched.

[0032] Based on the above-mentioned embodiment of the present invention, a method and device for generating code based on a program flowchart is provided. The method is: obtaining a program flowchart with a tree structure, the program flowchart is composed of multiple nodes, and transfer lines between nodes, and each transfer line is provided with an expression; extracting the graphic data corresponding to the program flowchart; based on the graphic data, traversing and searching the flow path of the program flowchart to generate code representing the intent of the program flowchart. In this scheme, graphic data is extracted from the program flowchart with a tree structure, and the flow path of the program flowchart is traversed and searched based on the graphic data, so as to generate code representing the intent of the program flowchart. The program flowchart can intuitively reflect complex logical processes, and the created program flowchart can automatically generate code consistent with the graphic semantic logic of the program flowchart, which can reduce the error rate of code writing and improve the efficiency of code writing. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0034] Figure 1 A flowchart of a method for generating codes based on a program flowchart provided by an embodiment of the present invention;

[0035] Figure 2 An example diagram of a program flow chart with a tree structure provided by an embodiment of the present invention;

[0036] Figure 3 An example diagram of the generated C code provided by an embodiment of the present invention;

[0037] Figure 4 A structural block diagram of a device for generating codes based on a program flow chart provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0038] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0039] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0040] As can be seen from the background technology, the code writing process tests the programmer's logic and understanding of the programming language. When encountering complex logical processes, programmers face a more difficult code writing task, and it is easy to make mistakes in the manual code writing process, resulting in low code writing efficiency.

[0041] To solve the above problems, this solution proposes a method and device for generating code based on a program flowchart, which extracts graphic data from a tree-structured program flowchart, and traverses and searches the flow path of the program flowchart based on the graphic data, thereby generating code that represents the intention of the program flowchart. The program flowchart can intuitively reflect complex logical processes, and the created program flowchart can automatically generate code that is consistent with the graphic semantic logic of the program flowchart, which can reduce the error rate of code writing and improve code writing efficiency.

[0042] It should be noted that the method and device for generating code based on a program flow chart proposed in the present invention can be used to generate C code and can also be used to generate other types of code. The type of the generated code is not specifically limited here.

[0043] See also Figure 1 , shows a flowchart of a method for generating code based on a program flow chart provided by an embodiment of the present invention, the method comprising:

[0044] Step S101: Obtain a program flow chart with a tree structure.

[0045] In the specific implementation of step S101, a pre-created program flow chart is obtained, and the program flow chart is presented in a tree structure; wherein, when creating the node primitives of the program flow chart, a unique identification ID is generated for each node in the program flow chart.

[0046] It should be noted that the program flow chart is composed of multiple nodes and transfer lines between nodes. An expression is set on each transfer line, and the expression set on each transfer line includes a transfer condition expression and / or an action expression.

[0047] Each node in the program flow chart has 0, 1 or more transfer lines. A leaf node in the program flow chart refers to a node with 0 transfer lines. The transfer line of each node carries a serial number representing the transfer order, wherein the transfer line of the node represents: the node transfers to another node through the transfer line.

[0048] For example: Assume that node 1 is transferred to node 2 through transfer line 1, then transfer line 1 is the transfer line that node 1 has.

[0049] For another example: Assume that node 1 is transferred to node 2 through transfer line 1, node 2 is transferred to node 3 through transfer line 2, and node 3 is not transferred to any other node, then transfer line 1 is the transfer line of node 1, transfer line 2 is the transfer line of node 2, and node 3 is a leaf node.

[0050] To further understand the program flow chart involved in this scheme, Figure 2 The program flow chart shown is explained;

[0051] exist Figure 2 In the program flow chart presented in a tree structure, the node A with the entry line added is the root node (tree root node), and the node A has three transfer lines (numbered 1, 2 and 3 respectively). The numbers of the three transfer lines of the node A represent the transfer order; starting from the node A, there are three transfer lines that can reach the three nodes of the node B, the node C and the node D respectively;

[0052] Node B has two transfer lines (numbered 1 and 2 respectively). According to these two transfer lines, nodes B can be transferred to nodes E and F respectively.

[0053] Node C has two transfer lines (numbered 1 and 2 respectively). According to these two transfer lines, nodes C can be transferred to nodes G and H respectively.

[0054] Node D, node E, node F, node G and node H do not have transfer lines, so node D, node E, node F, node G and node H are leaf nodes.

[0055] Figure 2 Each transfer line shown is provided with a transfer condition expression and / or an action expression, wherein c1-c7 are transfer condition expressions (eg, transfer condition expressions in the form of "state!=0"), and p1 and p2 are action expressions.

[0056] It is worth explaining again that the serial numbers of the transfer lines of the node represent the transfer order, and the serial numbers of the transfer lines of the node can be set and modified according to the actual situation. If the serial numbers of the transfer lines of the node are not set and modified, then the serial numbers of the transfer lines of the node are set by default according to the order in which the transfer lines are created.

[0057] Step S102: extracting the graphic data corresponding to the program flow chart.

[0058] To generate the code (such as C code) corresponding to the program flow chart, it is necessary to first abstract the program flow chart into a tree structure in the memory data. In the process of specifically implementing step S102, the graphic data of the tree structure corresponding to the program flow chart is extracted.

[0059] In some embodiments, the specific implementation method of extracting graphic data is: starting from the root node with an entry line added in the program flow chart, the transfer relationship is recorded according to the transfer order of each node to extract the graphic data corresponding to the program flow chart, and the graphic data includes the recorded transfer relationship, which at least includes the node ID, the expression of the transfer line, the serial number of the transfer line, etc.

[0060] More specifically, starting from the root node with the entry line added, the transfer relationship is recorded in the transfer order of each node. The transfer relationship is recorded in the form of a list, and one of the contents of the record is: recording the ID of the node transferred from the root node, and then performing the same recording operation as above on the node transferred from the root node, and so on. In this way, the recording of the transfer relationship can be completed to obtain graphic data, and the graphic data is saved in the memory structure.

[0061] For example: the root node is transferred to node 1, and the ID of node 1 is recorded; node 1 is transferred to node 2, and the ID of node 2 is recorded; other nodes perform recording operations in the same manner as described above, so that the transfer relationship can be recorded to obtain graphic data, and the graphic data is saved in the memory structure.

[0062] Step S103: Based on the graphic data, traverse and search the process path of the program flowchart to generate a code representing the intent of the program flowchart.

[0063] In the process of implementing step S103, after extracting the tree-structured graphic data corresponding to the program flowchart, a code (such as C code) representing the intent of the program flowchart is generated based on the graphic data. The specific implementation method is: based on the graphic data, the process path of the program flowchart is traversed and searched according to the transfer order of each node and the value of the expression on the transfer line to generate a code representing the intent of the program flowchart.

[0064] In the process of traversing and searching the flow path of the program flow chart (equivalent to traversing and searching the tree structure), a code corresponding to the flow path of the program flow chart traversed and searched can be generated.

[0065] More specifically, based on the graphic data, starting from the root node of the program flowchart, the process path of the program flowchart is traversed and searched according to the transfer order of the nodes and the values ​​of the expressions on the transfer lines. Each traversal search tries to find leaf nodes as much as possible, thereby generating code that is consistent with the graphic semantic logic of the program flowchart.

[0066] In some embodiments, after the code is generated that is consistent with the graphical semantic logic of the program flow chart, a computer device is called to run the code to obtain a corresponding running result.

[0067] It should be noted that an expression is set on the transfer line. For a node with multiple transfer lines, if the value of the expression on a transfer line of the node is true by default, then the traversal and search for the process path corresponding to the subsequent transfer line of the node (the transfer line after the transfer line with a value of true) will be stopped, which is equivalent to not generating the code corresponding to the subsequent transfer line (or the code of the subsequent transfer line is covered); conversely, if the value of the expression on all transfer lines of the node is not true, then it is necessary to traverse and search the process path corresponding to all transfer lines of the node, that is, generate the code corresponding to all transfer lines of the node.

[0068] In some embodiments, during the process of traversing and searching the flow path of a program flow chart, for a first target node in the program flow chart having multiple transfer lines, if the value of an expression on the first target transfer line of the first target node is true, then the traversal and search for the flow path corresponding to the transfer line whose sequence number is after the first target transfer line of the first target node is stopped, and the first target transfer line is any transfer line of the first target node.

[0069] On the contrary, if the values ​​of the expressions on all the transfer lines of the first target node are not true, the process path is traversed and searched along all the transfer lines of the first target node, so as to generate the codes corresponding to all the transfer lines of the first target node.

[0070] For example: Assume that the first target node has three transfer lines. According to the transfer order, these three transfer lines are transfer line 1, transfer line 2 and transfer line 3. If the value of the expression on transfer line 1 is true, the process path is only traversed and searched along transfer line 1 to generate the code corresponding to transfer line 1. The traversal and search of the process paths corresponding to transfer lines 2 and 3 are stopped, that is, the codes corresponding to transfer lines 2 and 3 are not generated.

[0071] It can be understood that in the process of traversing the flow path of the search program flowchart to generate code, in order to avoid generating duplicate code and avoid generating goto jump code, this solution avoids generating duplicate code by creating a flag variable (denoted as flag).

[0072] In some embodiments, during the process of traversing the flow path of the search program flow chart, for the second target node currently traversed, if the node to which the second target node is transferred downward along the second target transfer line is not a leaf node, a flag variable with an initial value of false is generated for the second target transfer line, the second target transfer line is any transfer line of the second target node, and the flag variable is used to avoid generating duplicate code;

[0073] Determine whether to assign the flag variable to true based on an expression on the transfer line involved in the process of traversing the search process path along the second target transfer line;

[0074] When the flag variable is true, the process path corresponding to the transfer line whose sequence number of the second target node is arranged after the second target transfer line is traversed and searched.

[0075] Specifically, when processing the expression on the transfer line of the second target node currently traversed, if the node to which the second target node is transferred downward along the second target transfer line is not a leaf node (equivalent to the subsequent node transfer), a flag variable (flag) with an initial value of false is generated for the second target transfer line;

[0076] In the process of traversing the search process path along the second target transfer line, if a preset situation exists (such as situation one and situation two in the subsequent examples), the flag variable of the second target transfer line is assigned to true; the processing (traversing the search process path) of the transfer lines whose serial numbers are after the second target transfer line (the transfer lines subsequent to the second target node) are all performed when the flag variable is true.

[0077] It should be noted that when the flag variable is true, flag variables corresponding to other transfer lines may be generated during the traversal and search of the flow path corresponding to the subsequent transfer line. Therefore, a queue is used to record all flag variables in code generation. Each time, the flag variable is taken from the first position of the queue for processing, and the newly generated flag variable is added to the end of the queue until all flag variables are processed, thereby completing the code generation work.

[0078] Combination Figure 2As can be seen from the example diagram of the tree-structured program flow chart, the code generated when the transfer condition expression c1 is true, c2 is not true, and c3 is not true is the same as the code generated when c1 is not true; in order to avoid generating duplicate code and avoid generating goto jump code, a flag variable (denoted as flag) is created to avoid generating duplicate code.

[0079] For example: static expressions cannot be judged as true or false when generating code. Figure 2 In the program flow chart shown, the three transfer lines starting from the root node (node ​​A) all have transfer condition expressions. It is impossible to statically determine whether the condition expression is true or false, so the code that needs to be written is "if(c1!=0){...}else{...}". Inside the above if branch, the following code "if(c2!=0) and if(c3!=0)" needs to be written; record case 1 as: "if(c2!=0)" and "if(c3!=0)" are not true; record case 2 as: "if(c1!=0)" is not true;

[0080] The code of case 1 is the same as the code of the else part of "if (c1! = 0)" in case 2. In order to avoid generating duplicate code and avoid generating goto jump code, when processing the transfer condition expression on the transfer line of the second target node currently traversed, if the node to which the second target transfer line transfers downward is not a leaf node, a flag with an initial value of false is generated for the second target transfer line, and it is recorded that the flag is generated for the second target transfer line of the second target node, so as to then generate the code of the subsequent transfer line;

[0081] For the above cases 1 and 2, the flag of the second target transfer line is uniformly assigned a value of true, and the processing of the subsequent transfer lines of the second target node is performed when the flag is true; because new flags may be generated during the subsequent processing, a queue is used to record all flags in code generation, and each time the flag is taken from the first position of the queue for processing, and the newly generated flag is added to the end of the queue until all flags are processed, thus completing the code generation work.

[0082] To better understand how to use flags to avoid generating duplicate code, the following examples are used to further illustrate:

[0083] Get Figure 2 The tree-structured program flow chart shown in FIG. 1 is used to extract graphic data from the program flow chart. Based on the graphic data, the flow path of the program flow chart is traversed and searched to generate C code representing the intent of the program flow chart. The generated C code is as follows: Figure 3 shown.

[0084] Figure 3 In the c code shown, flag1 is the flag variable corresponding to the transfer line 1 of the root node (node ​​A), and flag2 is the flag variable corresponding to the transfer line 2 of the root node (node ​​A);

[0085] from Figure 3 As can be seen from the C code shown, flag can be used to mark the operation of the previous transfer line, thereby avoiding the generation of duplicate code and making the structure of the generated code clearer.

[0086] In practical applications, you can use a compiler to compile the generated code to run the program and compare the output results to verify the correctness of the generated code.

[0087] In summary, this solution uses a program flow chart to split complex logic into multiple steps, and forms the program execution process through graphical nodes, transfer lines between nodes, and expressions on transfer lines; taking the root node of the program flow chart as the entry, the transfer process represented by the transfer line is described with code, thereby unifying the program flow chart with the computer language. Users can describe complex logic through concise graphical language, and then automatically generate code based on the program flow chart to run on the computer, and quickly obtain the running results, which can reduce the error rate of code writing and improve code writing efficiency.

[0088] In other words, the graphic elements in the program flowchart are abstracted into a reasonable data structure, and then a traversal algorithm is used to splice the code based on the graphic data extracted from the program flowchart, and finally the code is generated that is consistent with the graphic semantic logic of the program flowchart. The generated code conforms to the rules of structured programming and is concise and easy to read.

[0089] Corresponding to the method for generating code based on a program flow chart provided in the above embodiment of the present invention, see Figure 4 , the embodiment of the present invention also provides a structural block diagram of a device for generating codes based on a program flow chart, the device comprising: an acquisition unit 100, an extraction unit 200 and a search unit 300;

[0090] The acquisition unit 100 is used to acquire a program flow chart of a tree structure. The program flow chart is composed of a plurality of nodes and transfer lines between the nodes. An expression is set on each transfer line.

[0091] The extraction unit 200 is used to extract the graphic data corresponding to the program flow chart.

[0092] In a specific implementation, the extraction unit 200 is specifically used to: start from the root node with the entry line added in the program flow chart, record the transfer relationship according to the transfer sequence of each node, so as to extract the graphic data corresponding to the program flow chart.

[0093] The search unit 300 is used to traverse and search the flow path of the program flow chart based on the graphic data to generate a code representing the intention of the program flow chart.

[0094] In a specific implementation, the search unit 300 is specifically used to: based on the graphic data, traverse and search the process path of the program flowchart according to the transfer order of each node and the value of the expression on the transfer line to generate code representing the intent of the program flowchart, and the expression includes a transfer condition expression and / or an action expression.

[0095] In an embodiment of the present invention, graphic data is extracted from a tree-structured program flowchart, and the process path of the program flowchart is traversed and searched based on the graphic data, so as to generate code representing the intent of the program flowchart. The program flowchart can intuitively reflect complex logical processes. By automatically generating code that is consistent with the graphic semantic logic of the program flowchart through the created program flowchart, the error rate of code writing can be reduced and the efficiency of code writing can be improved.

[0096] Preferably, combined Figure 4 The device also includes:

[0097] A stop unit is used to stop traversing and searching the process path of a program flow chart. For a first target node in the program flow chart having multiple transfer lines, if the value of an expression on the first target transfer line of the first target node is true, then stop traversing and searching the process path corresponding to the transfer line whose sequence number is after the first target transfer line of the first target node. The first target transfer line is any one of the transfer lines of the first target node.

[0098] Preferably, combined Figure 4 The device also includes:

[0099] A generation unit is used for traversing the process path of the search program flow chart. For the second target node currently traversed, if the node to which the second target node is transferred downward along the second target transfer line is not a leaf node, a flag variable with an initial value of false is generated for the second target transfer line. The second target transfer line is any transfer line of the second target node. The flag variable is used to avoid generating duplicate code.

[0100] The determination unit is used to determine whether to assign a flag variable to true based on an expression on a transfer line involved in the process of traversing the search process path along the second target transfer line.

[0101] Accordingly, the search unit 300 is further configured to:

[0102] When the flag variable is true, the process path corresponding to the transfer line whose sequence number of the second target node is arranged after the second target transfer line is traversed and searched.

[0103] In summary, the embodiments of the present invention provide a method and device for generating code based on a program flowchart, extracting graphic data from a tree-structured program flowchart, traversing and searching the flow path of the program flowchart based on the graphic data, and thereby generating code representing the intent of the program flowchart. The program flowchart can intuitively reflect complex logical flows, and the created program flowchart can automatically generate code that is consistent with the graphic semantic logic of the program flowchart, thereby reducing the error rate of code writing and improving code writing efficiency.

[0104] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0105] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0106] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for generating code based on a program flow chart, characterized in that: The method comprises: Obtaining a program flow chart of a tree structure, wherein the program flow chart is composed of a plurality of nodes and transfer lines between the nodes, and an expression is set on each transfer line; Extracting graphic data corresponding to the program flow chart; Based on the graphic data, traverse and search the flow path of the program flow chart to generate a code representing the intention of the program flow chart; In the process of traversing and searching the flow path of the program flow chart, for the first target node in the program flow chart having multiple transfer lines, if the value of the expression on the first target transfer line of the first target node is true, then stop traversing and searching the flow path corresponding to the transfer line whose sequence number is after the first target transfer line of the first target node, and the first target transfer line is any one of the transfer lines of the first target node.

2. The method according to claim 1, characterized in that Extracting graphic data corresponding to the program flow chart, including: Starting from the root node with the entry line added in the program flow chart, the transfer relationship is recorded according to the transfer sequence of each node to extract the graphic data corresponding to the program flow chart.

3. The method according to claim 1, characterized in that: Based on the graphic data, traversing and searching the flow path of the program flow chart to generate a code representing the intent of the program flow chart, including: Based on the graphic data, the flow path of the program flow chart is traversed and searched according to the transfer order of each node and the value of the expression on the transfer line to generate code representing the intent of the program flow chart, wherein the expression includes a transfer condition expression and / or an action expression.

4. The method according to any one of claims 1 to 3, characterized in that: Also includes: In the process of traversing and searching the flow path of the program flow chart, for the second target node currently traversed, if the node to which the second target node is transferred downward along the second target transfer line is not a leaf node, a flag variable with an initial value of false is generated for the second target transfer line, the second target transfer line is any transfer line of the second target node, and the flag variable is used to avoid generating duplicate code; Determining whether to assign the flag variable to true based on an expression on the transfer line involved in the process of traversing the search process path along the second target transfer line; When the flag variable is true, the process path corresponding to the transfer line whose sequence number of the second target node is arranged after the second target transfer line is traversed and searched.

5. A device for generating code based on a program flow chart, characterized in that: The device comprises: An acquisition unit, used for acquiring a program flow chart of a tree structure, wherein the program flow chart is composed of a plurality of nodes and transfer lines between the nodes, and an expression is set on each transfer line; An extraction unit, used for extracting graphic data corresponding to the program flow chart; A search unit, configured to traverse and search a flow path of the program flow chart based on the graphic data to generate a code representing the intent of the program flow chart; A stopping unit is used for stopping traversing and searching the process path of the program flow chart. For a first target node in the program flow chart having multiple transfer lines, if the value of an expression on a first target transfer line of the first target node is true, then stopping traversing and searching the process path corresponding to the transfer line whose sequence number is after the first target transfer line of the first target node, wherein the first target transfer line is any one of the transfer lines of the first target node.

6. The device according to claim 5, characterized in that The extraction unit is specifically used to: start from the root node with the entry line added in the program flow chart, record the transfer relationship according to the transfer sequence of each node, so as to extract the graphic data corresponding to the program flow chart.

7. The device according to claim 5, characterized in that The search unit is specifically used to: based on the graphic data, traverse and search the flow path of the program flow chart according to the transfer order of each node and the value of the expression on the transfer line to generate code representing the intention of the program flow chart, wherein the expression includes a transfer condition expression and / or an action expression.

8. The device according to any one of claims 5 to 7, characterized in that: Also includes: A generating unit, configured to generate a flag variable with an initial value of false for a second target transfer line during a process of traversing and searching the process path of the program flow chart, for a second target node currently traversed, if the node to which the second target node is transferred downward along a second target transfer line is not a leaf node, wherein the second target transfer line is any transfer line of the second target node, and the flag variable is used to avoid generating duplicate code; a determination unit, configured to determine whether to assign the flag variable to true based on an expression on the transfer line involved in the process of traversing the search process path along the second target transfer line; Accordingly, the search unit is also used for: When the flag variable is true, the process path corresponding to the transfer line whose sequence number of the second target node is arranged after the second target transfer line is traversed and searched.

Citation Information

Patent Citations

  • Test path generation method and related equipment

    CN112559343A

  • Flow processing method and device, and computer system

    CN113918138A