Programming language conversion method and device, equipment and storage medium
By generating structured representations and using large language models for deep semantic understanding, the problem of low efficiency of existing programming language conversion methods is solved, and high-quality automatic conversion and accuracy improvement is achieved.
Patent Information
- Application Number
- CN202410925024.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-10
- Publication Date
- 2024-11-12
AI Technical Summary
The existing programming language conversion methods are time-consuming, error-prone and inefficient, making it difficult to achieve high-quality code conversion.
By obtaining the language code to be converted, generating structured representations, and using a large language model to perform internal subdivided node representations and target code generation, realizing deep semantic understanding and automatic conversion.
It improves the accuracy and efficiency of code language conversion, shortens the conversion time, and achieves high-quality target language code generation.
Smart Images

Figure CN118940720A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a programming language conversion method, device, equipment and storage medium. Background Art
[0002] In the field of software development, programming language conversion is an important research direction, which allows developers to convert code from one programming language to another programming language so that it can run on different platforms or environments. Existing programming language conversion methods mainly include manual conversion, template-driven conversion, and source code to intermediate representation and then translation.
[0003] Manual conversion methods specifically include: developers read the source code line by line and then translate it into the target language. Template-driven conversion methods specifically include: using predefined template rules to achieve conversion between programming languages through pattern matching and replacement. Source code to intermediate representation and then translation method specifically includes: converting the source code to intermediate representation, and then converting the intermediate representation into code of the target language.
[0004] However, the above methods have the problems of being time-consuming, error-prone and inefficient. Summary of the invention
[0005] The present invention provides a programming language conversion method, device, equipment and storage medium to solve the problem of poor programming language conversion effect.
[0006] In a first aspect, the present invention provides a programming language conversion method, comprising:
[0007] Acquire a language code to be converted, and generate a structured representation of a code node to be converted according to a logical feature in the language code to be converted, wherein the structured representation of the code node to be converted includes a plurality of code nodes to be converted;
[0008] For each language code to be converted in the code node to be converted, a structured representation of an internal subdivision node of the current code node to be converted is generated using a large language model, and a target code node is generated using the large language model according to the structured representation of the internal subdivision node, wherein the internal subdivision node includes a preset code element in the language code to be converted, and the target code node includes a target language code corresponding to the code node to be converted;
[0009] The large language model is used to generate target language codes according to the target code nodes.
[0010] In a second aspect, the present invention provides a programming language conversion device, comprising:
[0011] A code node structuring module, used to obtain a language code to be converted, and generate a code node structured representation to be converted according to logical features in the language code to be converted, wherein the code node structured representation to be converted includes a plurality of code nodes to be converted;
[0012] a target code node generation module, for generating an internal subdivision node structured representation of the current code node to be converted using a large language model for the language code to be converted in each code node to be converted, and generating a target code node based on the internal subdivision node structured representation using the large language model, wherein the internal subdivision node includes a preset code element in the language code to be converted, and the target code node includes a target language code corresponding to the code node to be converted;
[0013] The target language code generation module is used to generate target language code according to the target code node by using the large language model.
[0014] In a third aspect, the present invention provides an electronic device, the electronic device comprising:
[0015] at least one processor;
[0016] and a memory communicatively coupled to the at least one processor;
[0017] The memory stores a computer program executable by at least one processor, and the computer program is executed by at least one processor so that the at least one processor can execute the programming language conversion method of the first aspect.
[0018] In a fourth aspect, the present invention provides a computer-readable storage medium storing computer instructions, which are used to enable a processor to implement the programming language conversion method of the first aspect when executed.
[0019] The programming language conversion solution provided by the present invention fully understands the deep semantics of the language code to be converted, improves the accuracy of code language conversion, and uses the large language model to generate code nodes of the target language and their corresponding target language codes, thus completing the automatic conversion of the target language code with high quality, shortening the conversion time and improving the conversion efficiency.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. 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 creative work.
[0022] Figure 1 is a flowchart of a programming language conversion method provided according to Embodiment 1 of the present invention;
[0023] Figure 2 is a flowchart of a programming language conversion method provided according to Embodiment 2 of the present invention;
[0024] Figure 3 is a schematic diagram of the structure of a programming language conversion device provided according to Embodiment 3 of the present invention;
[0025] Figure 4 It is a schematic diagram of the structure of an electronic device provided according to Embodiment 4 of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings 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 should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In the description of the present invention, unless otherwise specified, "multiple" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after are an "or" relationship. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] Embodiment 1
[0029] Figure 1 A flowchart of a programming language conversion method is provided for the first embodiment of the present invention. This embodiment is applicable to the case of converting a programming language. The method can be executed by a programming language conversion device. The programming language conversion device can be implemented in the form of hardware and / or software. The programming language conversion device can be configured in an electronic device. The electronic device can be composed of two or more physical entities or one physical entity.
[0030] like Figure 1 As shown, the programming language conversion method provided in the first embodiment of the present invention specifically includes the following steps:
[0031] S101: Acquire a language code to be converted, and generate a structured representation of a code node to be converted according to a logical feature in the language code to be converted, wherein the structured representation of the code node to be converted includes a plurality of code nodes to be converted.
[0032] In this embodiment, the language code to be converted (i.e., source code) can be first subjected to source code parsing and lexical analysis, specifically including: preprocessing the source code, including removing non-essential contents such as comments and blank characters, and then using a lexical analyzer (Lexer) to scan the source code and divide it into a series of symbols (Tokens), such as keywords, identifiers, operators, string constants, and numerical constants. Next, the source code is subjected to grammatical analysis, specifically including: using a grammatical analyzer (Parser) to combine lexical units into a more complex structure according to the grammatical rules of the language of the source code, forming a hierarchical and abstract syntax tree (Abstract Syntax Tree, AST) representing the grammatical structure of the source code. Each node in the AST corresponds to a grammatical building block in the source code (such as function definition, class declaration, expression, and control structure, etc.), and retains the corresponding attribute information in the source code. Then, semantic analysis and type checking are performed, specifically including: further semantic analysis is performed on the basis of establishing the AST to determine the variable type, function signature, and type compatibility, etc., to provide accurate semantic information for the subsequent conversion process. Type inference and other necessary static analysis are completed to ensure that the AST not only reflects the grammatical structure, but also contains sufficient semantic context. Next, generate data sources, including: creating multiple data sources based on the results of AST and semantic analysis, including but not limited to the following five data sources:
[0033] 1) Node relationship diagram: shows the dependencies and calling relationships between different code elements.
[0034] 2) Metadata collection: stores information such as variable name, type, scope, and function signature.
[0035] 3) Test data set: Extract or generate input / output sample data to verify the functionality of the converted code.
[0036] 4) Control Flow Graph (CFG) or Data Flow Graph (DFG): Visualizes the control structure and data flow paths of a program.
[0037] 5) Pseudocode: shows the core logic and structure of the source code, while ignoring the specific programming syntax details.
[0038] Finally, the data obtained above can be persistently stored in a suitable data format (such as JSON or XML, etc.) for subsequent reading and processing, and an interface is created to facilitate the target language code generation module in the large language model to access and understand these data. Among them, the structured representation of the code node to be converted can be an abstract syntax tree, a control flow graph, and a data flow graph, etc. The structured representation of the code node to be converted can include multiple code nodes to be converted, and each code node to be converted can contain multiple sentences of language code to be converted. Among them, the logical feature can be understood as how the code expresses and processes the characteristics of logic, data, and control flow. Logical features are very important for understanding the structure and function of programming languages.
[0039] S102: for each language code to be converted in the code node to be converted, generate an internal subdivision node structured representation of the current code node to be converted by using a large language model, and generate a target code node according to the internal subdivision node structured representation by using the large language model, wherein the internal subdivision node includes a preset code element in the language code to be converted, and the target code node includes a target language code corresponding to the code node to be converted.
[0040] In this embodiment, the target code node can be generated using a large language model. The specific process includes: for the source code in each conversion code node, the large language model is used to deeply explore more detailed information, and the current node is structured again to generate the internal subdivision node structured representation of the current code node to be converted, including but not limited to the data type of the variable, the specific implementation of the function, the branching of the control flow, and the nested structure. Based on the built target language framework, the large language model is used to gradually fill in the specific implementation details according to the internal subdivision node structured representation to generate the target code node. For example, the loop structure in the source code is converted into the corresponding loop statement of the target language, and the content of the function body is converted into the function implementation of the target language. Through the above process, the logic and function of the source code can be accurately and effectively migrated to the target programming language, realizing cross-language transplantation and reconstruction. The preset code element can be the logical framework of the language code to be converted. Each code node to be converted corresponds to a target code node.
[0041] S103: Generate target language code according to the target code node by using the large language model.
[0042] In this embodiment, the target code nodes can be integrated according to the order of the source code by using the large language model, so as to generate the target language code.
[0043] The programming language conversion method provided by the embodiment of the present invention fully understands the deep semantics of the language code to be converted, improves the accuracy of code language conversion, and uses the large language model to generate code nodes of the target language and their corresponding target language codes, thereby completing the automatic conversion of the target language code with high quality, shortening the conversion time and improving the conversion efficiency.
[0044] Optionally, generating a structured representation of code nodes to be converted based on logical features in the language code to be converted includes: generating an abstract syntax tree containing code nodes to be converted based on logical features and grammatical features in the language code to be converted, wherein the abstract syntax tree belongs to the structured representation of code nodes to be converted, and the code nodes to be converted include grammatical building blocks in the language code to be converted.
[0045] Specifically, the abstract syntax tree of the language code to be converted can be a multi-branch tree, and the edges between the code nodes to be converted in the abstract syntax tree are abstract representations of syntax and logical relationships. Syntactic features can include lexical structure, statements and expressions, grammar rules, naming rules, file and module structure, error handling, etc.
[0046] Optionally, the using the large language model to generate a target code node according to the internal subdivision node structured representation includes: using the large language model to generate a target code node framework according to the pseudocode of the language code to be converted, and generating a target code node according to the internal subdivision node structured representation and the target code node framework, wherein the target code node framework contains logical information required to convert the language code to be converted into the target language code.
[0047] Specifically, the target code node is generated using the large language model. The specific process includes:
[0048] Step 1: Build the target language code framework
[0049] (1) Target language framework design
[0050] Based on the pseudocode representation of the source code, a framework for generating target language code using a large language is used, specifically including determining the main structure of the target language code (such as class definition, module division, function interface, and global variable declaration, etc.), while taking into account the specific programming paradigm and architectural requirements of the target language.
[0051] (2) Framework code generation:
[0052] Generate basic framework code based on the abstract representation of source code in pseudocode, ensuring that it complies with the programming specifications of the target language and the use of standard libraries. At the same time, the framework can accommodate all logic converted from the source code.
[0053] Step 2: Fill and complete the code content
[0054] (1) Detailed information extraction:
[0055] For the source code in each conversion code node, the large language model is used to deeply mine more detailed information to generate a structured representation of the internal subdivision nodes of the current code node to be converted, including but not limited to the data type of the variable, the specific implementation of the function, the branching of the control flow, and the nested structure.
[0056] (2) Fill in node details:
[0057] Based on the established target language framework, the large language model is used to gradually fill in specific implementation details according to the internal segmented node structured representation to generate target code nodes. For example, the loop structure in the source code is converted into the corresponding loop statement in the target language, and the content of the function body is converted into the function implementation in the target language.
[0058] (3) Type conversion and adaptation:
[0059] According to the type system differences between the source code and the target language, necessary type conversion operations are performed to ensure the type safety of the converted code. At the same time, for some advanced features such as generics and templates, suitable target language alternatives are found.
[0060] (4) Code optimization and adjustment:
[0061] In the process of filling in the code, appropriate code optimization is performed based on the characteristics of the target language, such as replacing more efficient built-in functions or methods, improving memory management, and adapting to the performance requirements of the target platform.
[0062] Optionally, the using the large language model to generate the target language code according to the target code nodes includes: using the large language model to integrate the target code nodes according to the structured representation of the code nodes to be converted to generate the target language code.
[0063] Specifically, the large language model can integrate the target code nodes according to the hierarchical structure of the source code based on the logical and grammatical relationships contained in the structuring of the code nodes to be converted, and construct a complete target language code, forming high-quality code that retains the original logic and conforms to the characteristics of the target programming language.
[0064] Embodiment 2
[0065] Figure 2 This is a flowchart of a programming language conversion method provided in the second embodiment of the present invention. The technical solution of the embodiment of the present invention is further optimized on the basis of the above-mentioned optional technical solutions, and a specific method for converting the programming language is given.
[0066] Optionally, before using the large language model to generate the target language code according to the target code node, it also includes: performing a verification operation on the target language code in each of the target code nodes to obtain a verification result, wherein the verification operation includes compilation, execution and functional testing; wherein using the large language model to generate the target language code according to the target code node includes: if the verification results of the target code nodes are all passed, then using the large language model to generate the target language code according to the target code node. The advantage of this setting is that through compilation, execution and functional testing, a comprehensive and rigorous target language code generation post-processing system is formed, which ensures the accurate reproduction and efficient execution of the source code logic in the cross-language conversion process.
[0067] Optionally, before the language code to be converted in each of the code nodes to be converted is used to generate the internal subdivision node structured representation of the current code node to be converted using the large language model, it also includes: for each of the language code to be converted in the code node to be converted, determining the node in the current code node to be converted that does not contain the third-party dependency library code; wherein, for each of the language code to be converted in the code node to be converted, using the large language model to generate the internal subdivision node structured representation of the current code node to be converted includes: using the large language model to generate the internal subdivision node structured representation of the node that does not contain the third-party dependency library code. The advantage of such a setting is that in the process of traversing each code node to be converted, the code nodes to be converted at the current level that do not contain the third-party dependency library code are accurately converted using the large language model, and the corresponding target code fragments are accurately generated.
[0068] Optionally, before the language code to be converted in each of the code nodes to be converted is generated by the large language model as the internal subdivision node structured representation of the current code node to be converted, it also includes: for the language code to be converted in each of the code nodes to be converted, determining the current code node to be converted whose code is a third-party dependency library code, and using the preset third-party dependency library mapping large language model to convert the third-party dependency library code into a first target language code to be integrated; wherein, using the large language model to generate the target language code according to the target code node includes: using the large language model to generate a second target language code to be integrated according to the target code node, and according to the structured representation of the code node to be converted, integrating the first target language code to be integrated and the second target language code to be integrated to obtain the target language code. The advantage of this setting is that the preset third-party dependency library mapping large language model is used to achieve efficient and accurate conversion of the third-party dependency library code to the target language code, which greatly improves the conversion efficiency and accuracy.
[0069] like Figure 2 As shown, a programming language conversion method provided by Embodiment 2 of the present invention specifically includes the following steps:
[0070] S201: Obtain a language code to be converted, and generate an abstract syntax tree containing code nodes to be converted according to logical features and grammatical features in the language code to be converted.
[0071] Specifically, when facing source code with a complex nested structure, a multi-tree hierarchical traversal strategy can be used to convert each code node to be converted starting from the top layer and gradually going down. The top-down approach ensures that the parent node is processed first and then the child node, ensuring that the contextual dependencies in the source code are correctly processed.
[0072] S202: for each language code to be converted in the code node to be converted, determine whether the current code node to be converted is a node containing a third-party dependent library code; if not, execute step 203; if yes, execute step 205.
[0073] Specifically, a large-scale third-party dependency library mapping model from the language to be converted to the target language can be pre-trained through deep learning technology, and the model is used for third-party dependency library code conversion. This process involves collecting a large number of corresponding third-party dependency library code snippets in the language to be converted and the target language as training data to ensure that the model can understand and learn the grammatical differences and semantic correspondence rules of third-party dependency library calls between different languages. The intelligent recognition engine can be used to determine the nodes that do not contain third-party dependency library code in the current code nodes to be converted, and determine the current code nodes to be converted whose code is third-party dependency library code. The core responsibility of the engine is to accurately identify which parts of the code belong to the calls of the third-party dependency library. It uses natural language processing technology and pattern matching algorithms to perform deep scanning and analysis of the source code, which can effectively distinguish between custom code and third-party dependency library code, and provide accurate target positioning for subsequent conversion steps. Once the engine confirms that a certain section of code belongs to the third-party dependency library code, it can immediately activate the preset third-party dependency library mapping large language model, and use its built-in node mapping function to convert the third-party dependency library code in a targeted manner.
[0074] S203: Generate an internal subdivision node structured representation of the node that does not contain the third-party dependency library code by using a large language model.
[0075] S204 , using the large language model, generating a target code node framework according to the pseudo code of the language code to be converted, and generating a target code node according to the internal subdivided node structured representation and the target code node framework, and executing step 206 .
[0076] S205: Mapping a large language model using a preset third-party dependency library to convert the third-party dependency library code into a first target language code to be integrated.
[0077] Specifically, for each current code node to be converted that contains third-party dependency library code, the large language model will find and apply the most appropriate conversion rules to convert the third-party dependency library code into an equivalent expression in the target language, accurately map the third-party dependencies, ensure that these complex nodes are not distorted during the conversion, and ensure the efficiency and accuracy of the conversion process. After obtaining the first target language code to be integrated, the functional test and integration test of the target language can be deployed through the automated testing framework, and test cases for the first target language code to be integrated can be reused or generated to verify the functional correctness and compatibility of the converted code in the actual application scenario, thereby providing comprehensive quality assurance.
[0078] S206: Verify the target language code and / or the first target language code to be integrated in each target code node to obtain a verification result.
[0079] The verification operation includes compilation, execution and functional testing.
[0080] Specifically, the target language code in the target code node and / or the first target language code to be integrated is verified, which specifically includes the following three steps:
[0081] Step 1: Code review and logical correctness assessment
[0082] (1) Deep code understanding:
[0083] The target language code and / or the first target language code to be integrated are deeply analyzed and reviewed using the large language model. The large language model compares the abstract syntax tree of the source code with the internal logic of the target language code and / or the first target language code to be integrated, and determines whether the generated target language code and / or the first target language code to be integrated are semantically consistent with the source code, ensuring that the critical path and control flow have not deviated, and that function and method calls are correct.
[0084] (2) Code quality assessment:
[0085] Evaluate code style, readability, and maintainability, identify common programming errors such as redundant code, uninitialized variables, and null pointer references, and output improvement suggestions and optimization recommendations.
[0086] Step 2: Compile and execute verification and its loop iteration
[0087] (1) Automatic compilation process:
[0088] Input the target language code and / or the first target language code to be integrated into the corresponding compiler for compilation, and observe and record any errors or warnings that occur during the compilation process. In the case of compilation failure, analyze the cause of the error, locate the relevant code segment, and send it back to the large language model for targeted correction.
[0089] (2) Runtime environment configuration and execution:
[0090] Set up a suitable operating environment, deploy the successfully compiled target language code and / or the first target language code to be integrated, and execute the program to detect the actual operating effect. By capturing and analyzing runtime exceptions, performance indicators, and resource consumption, you can fully understand the actual performance of the target language code and / or the first target language code to be integrated.
[0091] (3) Closed-loop feedback and iterative optimization:
[0092] Establish a continuous feedback and optimization loop testing mechanism. When compilation errors or execution exceptions are found, the problems are immediately fed back to the large language model, prompting the model to learn and update the conversion strategy, and then regenerate the optimized target language code and / or the first target language code to be integrated, and enter the compilation, execution and diagnosis stages again until the expected correctness and performance standards are achieved.
[0093] Step 3: Unit test acceptance and accuracy verification
[0094] (1) Automatically generate unit test cases:
[0095] Based on the intelligent generation capability of the large language model, corresponding unit test cases are created for each key function or module in the source code to ensure that these cases cover various boundary conditions, normal logical paths, and exception handling situations of the source code.
[0096] (2) Cross-validation test results:
[0097] Execute unit test cases of the target language code and / or the first target language code to be integrated, collect and compare the execution results with the output data generated by the source code under the same test conditions. This process is designed to verify that the logic of a single code node (such as a function, class or module) remains highly consistent during the conversion process.
[0098] S207: If the verification results of the target code node and the first target language code to be integrated are both passed, using the large language model to generate a second target language code to be integrated according to the target code node, and integrating the first target language code to be integrated and the second target language code to be integrated according to the abstract syntax tree of the code node to be converted to obtain a target language code.
[0099] Specifically, after the current target code node and the first target language code to be integrated have been verified, the above conversion, analysis and testing process can be repeated for the next target code node. This recursive process ensures that all components of the source code receive full attention and accurate conversion. After layer-by-layer and node-by-node refinement, all internal nodes will be converted into the target programming language and independently verified. The large language model can gradually splice the first target language code to be integrated and the second target language code to be integrated according to the abstract syntax tree of the code node to be converted to form a complete target language architecture, thereby constructing a complete target code for the language code to be converted. At the same time, in response to problems such as interface calls and dependencies that may exist between nodes, the large language model will also conduct overall coordination and optimization based on actual conditions to ensure the overall coherence of the code.
[0100] The programming language conversion method provided by the embodiment of the present invention takes into account the limitations and possible uncertainties of the large language model, based on the idea of hierarchical and recursive refinement, and fully utilizes the advantages of the large language model. In the process of traversing each code node to be converted, the code nodes to be converted at the current level that do not contain the third-party dependency library code are accurately converted, and the corresponding target code fragments are accurately generated. This method also uses a preset third-party dependency library to map a large language model to achieve efficient and accurate conversion of the third-party dependency library code to the target language code, greatly improving the conversion efficiency and accuracy. When facing complex third-party library conversion scenarios, it shows excellent adaptability, improves the efficiency and accuracy of processing third-party dependencies in code translation scenarios, and especially shows significant advantages in cross-language migration scenarios. Finally, this method constitutes a comprehensive and rigorous target language code generation post-processing system through compilation, execution and functional testing, ensuring the accurate reproduction and efficient execution of the source code logic in the cross-language conversion process. This method realizes the understanding and reconstruction of the logical structure of source code, which not only simplifies the complexity of cross-language development and saves valuable time for developers, but also opens up a high-efficiency and high-precision conversion path by mapping large language models through preset third-party dependency libraries, promotes the connection between different programming languages, and accelerates open cooperation and integration between software ecosystems.
[0101] Embodiment 3
[0102] Figure 3 This is a schematic diagram of the structure of a programming language conversion device provided by Embodiment 3 of the present invention. Figure 3 As shown, the device includes: a code node structuring module 301, a target code node generating module 302 and a target language code generating module 303, wherein:
[0103] A code node structuring module, used to obtain a language code to be converted, and generate a code node structured representation to be converted according to logical features in the language code to be converted, wherein the code node structured representation to be converted includes a plurality of code nodes to be converted;
[0104] a target code node generation module, for generating an internal subdivision node structured representation of the current code node to be converted using a large language model for the language code to be converted in each code node to be converted, and generating a target code node based on the internal subdivision node structured representation using the large language model, wherein the internal subdivision node includes a preset code element in the language code to be converted, and the target code node includes a target language code corresponding to the code node to be converted;
[0105] The target language code generation module is used to generate target language code according to the target code node by using the large language model.
[0106] The programming language conversion device provided by the embodiment of the present invention fully understands the deep semantics of the language code to be converted, improves the accuracy of code language conversion, and uses the large language model to generate code nodes of the target language and their corresponding target language codes, thereby completing the automatic conversion of the target language code with high quality, shortening the conversion time and improving the conversion efficiency.
[0107] Optionally, the code node structured modules include:
[0108] An abstract syntax tree determination unit is used to generate an abstract syntax tree including code nodes to be converted according to the logical features and grammatical features in the language code to be converted, wherein the abstract syntax tree belongs to the structured representation of the code nodes to be converted, and the code nodes to be converted include grammatical building blocks in the language code to be converted.
[0109] Optionally, the target code node generation module includes:
[0110] The target code node generation unit is used to generate a target code node framework based on the pseudo code of the language code to be converted by using the large language model, and generate a target code node based on the internal subdivision node structured representation and the target code node framework, wherein the target code node framework contains the logic information required for converting the language code to be converted into the target language code.
[0111] Optionally, the device further comprises:
[0112] A verification result determination module is used to perform a verification operation on the target language code in each target code node before generating the target language code according to the target code node using the large language model to obtain a verification result, wherein the verification operation includes compilation, execution and functional testing.
[0113] The target language code generation module is specifically used to generate target language codes according to the target code nodes using the large language model if the verification results of the target code nodes are all passed.
[0114] Optionally, the target language code generation module is specifically configured to utilize the large language model and integrate the target code nodes according to the structured representation of the code nodes to be converted to generate the target language code.
[0115] Optionally, the device further comprises:
[0116] The dependency library node determination module is used to determine the nodes in the current code node to be converted that do not contain the third-party dependency library code, before using the large language model to generate the internal subdivision node structured representation of the current code node to be converted for the language code to be converted in each code node to be converted.
[0117] Optionally, the target code node generation module includes:
[0118] The subdivision node structuring unit is used to generate an internal subdivision node structured representation of the node that does not contain the third-party dependent library code by using a large language model.
[0119] Optionally, the device further comprises:
[0120] The module for determining the target code to be integrated is used to determine the current code node to be converted whose code is a third-party dependent library code, before using the large language model to generate the internal subdivided node structured representation of the current code node to be converted for the language code to be converted in each code node to be converted, and use the preset third-party dependent library mapping large language model to convert the third-party dependent library code into the first target language code to be integrated.
[0121] Optionally, the target language code generation module is specifically used to generate a second target language code to be integrated according to the target code node using the large language model, and integrate the first target language code to be integrated and the second target language code to be integrated according to the structured representation of the code node to be converted to obtain the target language code.
[0122] The programming language conversion device provided in the embodiment of the present invention can execute the programming language conversion method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0123] Embodiment 4
[0124] Figure 4 A schematic diagram of the structure of an electronic device 40 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0125] like Figure 4 As shown, the electronic device 40 includes at least one processor 41, and a memory connected to the at least one processor 41, such as a read-only memory (ROM) 42, a random access memory (RAM) 43, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 41 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 42 or the computer program loaded from the storage unit 48 to the random access memory (RAM) 43. In the RAM 43, various programs and data required for the operation of the electronic device 40 can also be stored. The processor 41, the ROM 42, and the RAM 43 are connected to each other through a bus 44. An input / output (I / O) interface 45 is also connected to the bus 44.
[0126] A number of components in the electronic device 40 are connected to the I / O interface 45, including: an input unit 46, such as a keyboard, a mouse, etc.; an output unit 47, such as various types of displays, speakers, etc.; a storage unit 48, such as a disk, an optical disk, etc.; and a communication unit 49, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 49 allows the electronic device 40 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0127] The processor 41 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 41 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 41 executes the various methods and processes described above, such as a programming language conversion method.
[0128] In some embodiments, the programming language conversion method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 48. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 40 via the ROM 42 and / or the communication unit 49. When the computer program is loaded into the RAM 43 and executed by the processor 41, one or more steps of the programming language conversion method described above may be performed. Alternatively, in other embodiments, the processor 41 may be configured to perform the programming language conversion method in any other appropriate manner (e.g., by means of firmware).
[0129] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0130] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0131] The computer device provided above can be used to execute the programming language conversion method provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0132] Embodiment 5
[0133] In the context of the present invention, a computer-readable storage medium may be a tangible medium, wherein the computer-executable instructions, when executed by a computer processor, are used to perform a programming language conversion method, the method comprising:
[0134] Acquire a language code to be converted, and generate a structured representation of a code node to be converted according to a logical feature in the language code to be converted, wherein the structured representation of the code node to be converted includes a plurality of code nodes to be converted;
[0135] For each language code to be converted in the code node to be converted, a structured representation of an internal subdivision node of the current code node to be converted is generated using a large language model, and a target code node is generated using the large language model according to the structured representation of the internal subdivision node, wherein the internal subdivision node includes a preset code element in the language code to be converted, and the target code node includes a target language code corresponding to the code node to be converted;
[0136] The large language model is used to generate target language codes according to the target code nodes.
[0137] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by an instruction execution system, device or equipment or used with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0138] The computer device provided above can be used to execute the programming language conversion method provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0139] It is worth noting that in the embodiment of the above-mentioned programming language conversion device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0140] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A programming language conversion method, characterized in that: include: Acquire a language code to be converted, and generate a structured representation of a code node to be converted according to a logical feature in the language code to be converted, wherein the structured representation of the code node to be converted includes a plurality of code nodes to be converted; For each language code to be converted in the code node to be converted, a structured representation of an internal subdivision node of the current code node to be converted is generated using a large language model, and a target code node is generated using the large language model according to the structured representation of the internal subdivision node, wherein the internal subdivision node includes a preset code element in the language code to be converted, and the target code node includes a target language code corresponding to the code node to be converted; The large language model is used to generate target language codes according to the target code nodes.
2. The method according to claim 1, characterized in that The step of generating a structured representation of a code node to be converted according to the logical features in the language code to be converted comprises: An abstract syntax tree including code nodes to be converted is generated according to the logical features and grammatical features in the language code to be converted, wherein the abstract syntax tree belongs to the structured representation of the code nodes to be converted, and the code nodes to be converted include grammatical building blocks in the language code to be converted.
3. The method according to claim 1, characterized in that: The step of using the large language model to generate target code nodes according to the internal subdivision node structured representation includes: The large language model is used to generate a target code node framework according to the pseudocode of the language code to be converted, and a target code node is generated according to the internal subdivision node structured representation and the target code node framework, wherein the target code node framework contains the logic information required to convert the language code to be converted into the target language code.
4. The method according to claim 1, characterized in that: Before using the large language model to generate the target language code according to the target code node, the method further includes: Performing a verification operation on the target language code in each target code node to obtain a verification result, wherein the verification operation includes compilation, execution, and functional testing; Wherein, the using the large language model to generate the target language code according to the target code node includes: If the verification results of the target code nodes are all passed, the target language code is generated according to the target code nodes using the large language model.
5. The method according to any one of claims 1 to 4, characterized in that The step of using the large language model to generate target language code according to the target code node includes: The target code nodes are integrated by using the large language model according to the structured representation of the code nodes to be converted, so as to generate target language codes.
6. The method according to claim 1, characterized in that Before generating the internal subdivision node structured representation of the current code node to be converted by using the large language model for the language code to be converted in each code node to be converted, the method further includes: For each of the to-be-converted language codes in the to-be-converted code nodes, determining a node in the current to-be-converted code node that does not contain a third-party dependent library code; The step of generating a structured representation of the internal subdivision nodes of the current code node to be converted by using a large language model for the language code to be converted in each code node to be converted includes: The internal subdivision node structured representation of the node that does not contain the third-party dependent library code is generated by using a large language model.
7. The method according to claim 6, characterized in that Before generating the internal subdivision node structured representation of the current code node to be converted by using the large language model for the language code to be converted in each code node to be converted, the method further includes: For each of the code nodes to be converted, the code node to be converted is determined to be a third-party dependent library code, and the third-party dependent library code is converted into a first target language code to be integrated by using a preset third-party dependent library mapping large language model; Wherein, the using the large language model to generate the target language code according to the target code node includes: The large language model is used to generate a second target language code to be integrated according to the target code node, and the first target language code to be integrated and the second target language code to be integrated are integrated according to the structured representation of the code node to be converted to obtain a target language code.
8. A programming language conversion device, characterized in that: include: A code node structuring module, used to obtain a language code to be converted, and generate a code node structured representation to be converted according to logical features in the language code to be converted, wherein the code node structured representation to be converted includes a plurality of code nodes to be converted; a target code node generation module, for generating an internal subdivision node structured representation of the current code node to be converted using a large language model for the language code to be converted in each code node to be converted, and generating a target code node based on the internal subdivision node structured representation using the large language model, wherein the internal subdivision node includes a preset code element in the language code to be converted, and the target code node includes a target language code corresponding to the code node to be converted; A target language code generation module is used to generate target language code according to the target code node using the large language model.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the programming language conversion method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the programming language conversion method according to any one of claims 1 to 7 when executed.
Citation Information
Cited By
Code language conversion method and device, electronic equipment, storage medium and computer program product
CN120803467A
Code conversion method and device, electronic equipment and storage medium
CN120872325A
