Code information generation method and device, storage medium and electronic equipment
By performing code processing and denoising operations on script files and using pre-trained target network models for conversion, the problem of low script conversion efficiency in the existing technology is solved, and efficient and accurate code conversion and quality improvement is achieved.
Patent Information
- Application Number
- CN202411706961.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-04-11
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The conversion efficiency of scripts in the prior art is low, resulting in insufficient in complex logic processing and performance optimization of converted code, and developers need additional time to manually adjust and correct.
By obtaining the script file to be converted, performing code processing operations to add programming environment and functional logic information, and performing denoising operations on the script file. Then, the processed script file is converted using the pre-trained target network model to generate a new script file with a functional equivalent.
It significantly improves the efficiency and quality of code conversion, reduces the error and time cost of manual conversion, and increases the productivity of developers.
Smart Images

Figure CN119806482A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computers, and specifically, to a method and device for generating code information, a storage medium, and an electronic device. Background Art
[0002] Currently, script conversions mostly rely on simple syntax replacement and structural matching, without a deep understanding of the script's context and functional intent. This results in deficiencies in the converted code's complex logic processing and performance optimization. After using these tools, developers need to spend additional time manually adjusting and correcting the generated code, which not only reduces work efficiency but also increases project costs. Summary of the Invention
[0003] The embodiments of the present application provide a method and device for generating code information, a storage medium, and an electronic device to at least solve the problem of low script conversion efficiency in related technologies.
[0004] According to one embodiment of the present application, a method for generating code information is provided, comprising: obtaining a script file to be converted; performing a code processing operation on the script file to obtain a first script file, wherein the code processing operation comprises adding the programming environment and functional logic information of the script file to the first script file, and performing a denoising operation on the script file; performing a conversion operation on the first script file using a pre-trained target network model to obtain a second script file, wherein the target network model is a model obtained by iteratively training an initial network model using multiple groups of sample script files, and the conversion operation comprises: parsing the first script file to parse out a first logic box of the first script file from the programming environment and the functional logic; A framework and first code information, wherein the first logic framework includes the program structure of the first script file and the program logic of the first script file, and the first code information is information in a first code format; determining conversion logic information for converting the first script file into a second script file, wherein the code included in the second script file is in a second code format; using the first logic framework and the conversion logic information, generating a second logic framework, wherein the second logic framework includes the program structure of the second script file and the program logic of the second script file; generating second code information of the second script file based on the second logic framework and the first code information, wherein the second code information has the same function as the first code information.
[0005] In an exemplary embodiment, the target network model includes a syntax parser that parses the first script file to parse out the first logical framework and first code information of the first script file from the programming environment and the functional logic, including: parsing the programming environment of the first script file by the syntax parser to extract the program structure of the first script file; parsing the functional logic and syntax structure in the first script file by the syntax parser to obtain the program logic of the first script file; parsing the code in the first script file by the syntax parser to obtain the first code information.
[0006] In an exemplary embodiment, the target network model includes a mapping subnetwork, and determining conversion logic information for converting the first script file into the second script file includes: inputting the first logical framework into the mapping subnetwork and inputting the script type of the second script file into the mapping subnetwork; searching for a preset logical framework that matches the second script file according to the script type of the second script file through the mapping subnetwork; and parsing the preset logical framework and the first logical framework through the mapping subnetwork to establish a mapping relationship between the preset logical framework and the first logical framework to obtain the conversion logic information.
[0007] In an exemplary embodiment, the target network model includes a logic parser and a logic converter. The generating of the second logic framework using the first logic framework and the conversion logic information includes: parsing the program structure and program logic of the first script file by the logic parser, wherein the program structure of the first script file includes at least one of the following: function calls, variable declarations, data types, and object operations, and the program logic of the first script file includes at least one of the following: logic control structures and event processing logic; inputting the conversion logic information and the first logic framework parsed by the logic parser into the logic converter; the logic converter converts the logic control structure of the first script file into an equivalent structure of the second script, converts the function calls of the first script file into function calls of the second script file, converts the object operations of the first script file into application programming interface (API) calls of the second script file, and processes data type differences between the first and second script files; constructing a syntax tree of the second script file by the logic converter, and generating the second logic framework using the syntax tree, the equivalent structure of the second script, the function calls of the second script file, the API calls of the second script file, and the processed data type differences. The syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file.
[0008] In an exemplary embodiment, the target network model includes a code generator, and generating second code information of the second script file based on the second logical framework and the first code information includes: inputting the second logical framework and the first code information into the code generator, and mapping the first code information to the syntax and functions in the second logical framework according to syntax elements, function calls, and object operations by the code generator to obtain the code structure of the second script file; adjusting the code structure of the second script file through a syntax tree of the second script file to obtain an adjusted code structure, wherein the syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file; generating code information based on the adjusted code structure to obtain the second code information.
[0009] In an exemplary embodiment, the target network model includes a code debugger, and code information is generated based on the adjusted code structure. After obtaining the second code information, the method further includes: inputting the second code information into the code debugger, and performing a code debugging operation on the second code information through the code debugger, wherein the code debugging operation includes at least one of the following: code refactoring, eliminating redundancy, handling loops and recursion, and repairing exceptions.
[0010] In an exemplary embodiment, the second code information is input into the code debugger. After the code debugging operation is performed on the second code information through the code debugger, the method further includes: saving the debugged second code information and displaying the debugged second code information on a preset interface, wherein the preset interface includes a download service, and the download service is used to respond to the download operation triggered by the debugged second code information and convert the debugged second code information into a preset format.
[0011] According to another embodiment of the present application, a device for generating code information is also provided, comprising: a first acquisition module for acquiring a script file to be converted; a first processing module for performing a code processing operation on the script file to obtain a first script file, wherein the code processing operation includes adding the programming environment and functional logic information of the script file to the first script file, and performing a denoising operation on the script file; a first conversion module for performing a conversion operation on the first script file using a pre-trained target network model to obtain a second script file, wherein the target network model is a model obtained by iteratively training an initial network model using multiple groups of sample script files, and the conversion operation includes: parsing the first script file to parse the programming environment and the functional logic information from the first script file. Determine a first logical framework and first code information of the first script file, wherein the first logical framework includes the program structure of the first script file and the program logic of the first script file, and the first code information is information in a first code format; determine conversion logic information for converting the first script file into a second script file, wherein the code included in the second script file is in a second code format; generate a second logical framework using the first logical framework and the conversion logic information, wherein the second logical framework includes the program structure of the second script file and the program logic of the second script file; generate second code information of the second script file based on the second logical framework and the first code information, wherein the second code information has the same function as the first code information.
[0012] According to another embodiment of the present application, a computer program product is provided, including a computer program, which implements the steps of any of the above method embodiments when executed by a processor.
[0013] According to another embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when run.
[0014] According to another embodiment of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0015] Through the present application, a conversion operation is performed on the processed first script file using a pre-trained target network model. This model is obtained by iteratively training a large number of sample script files and is capable of understanding and converting complex code logic. The conversion operation includes parsing the first script file, extracting a first logical framework (program structure and program logic) and a first code information therefrom, then determining the conversion logic information, and based on the first logical framework and the conversion logic information, the model generates a second logical framework. Finally, using the second logical framework and the first code information, the model generates the second code information of the second script file. The first script file can be efficiently and accurately converted to the second script file, significantly improving the efficiency and quality of code conversion, reducing the errors and time costs of manual conversion, and improving the productivity of developers. Therefore, the problem of low conversion efficiency of scripts in the related art can be solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 This is a hardware structure block diagram of a server device for a method for generating code information according to an embodiment of the present application;
[0017] Figure 2 is a flowchart of a method for generating code information according to an embodiment of the present application;
[0018] Figure 3 This is a flowchart of the JavaScript code generated according to the specific embodiment of this application;
[0019] Figure 4 It is a structural block diagram of a device for generating code information according to an embodiment of the present application. DETAILED DESCRIPTION
[0020] The embodiments of the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0021] It should be noted that the terms "first", "second", etc. in the description and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0022] The method embodiments provided in the embodiments of the present application can be executed in a server device or a similar computing device. Taking running on a server device as an example, Figure 1 This is a hardware structure diagram of a server device for a method of generating code information according to an embodiment of the present application. Figure 1 As shown, the server device may include one or more ( Figure 1Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the above-mentioned server device may also include a transmission device 106 for communication functions and an input and output device 108. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above server device. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.
[0023] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for generating code information in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to a server device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0024] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by a communication provider of the server device. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0025] In this embodiment, a method for generating code information is provided. Figure 2 is a flow chart of a method for generating code information according to an embodiment of the present application. Figure 2 As shown, the process includes the following steps:
[0026] Step S202, obtaining the script file to be converted;
[0027] Optionally, this embodiment is primarily used for migrating and updating enterprise-level office automation systems, particularly in scenarios where traditional Microsoft Office environments are transitioning to localized or web-based office systems. For example, a software development team or IT department may have a large library of VBA macro scripts for various customized office automation tasks. As the technology stack is updated, the team needs to convert these scripts into web-based JavaScript scripts to improve cross-platform compatibility and leverage the advantages of modern web technologies.
[0028] Optionally, in this embodiment, the script file to be converted can be obtained in the following manner:
[0029] The file upload interface obtains the script file to be converted. A user-friendly interface is developed to allow users to upload VBA macro script files by dragging and dropping, clicking, or clicking an upload button. After uploading, the system needs to verify that the file is in the correct format, that is, whether it contains VBA macros. This can be achieved by reading the file header information or using a specialized library (such as the jsdocx or docx libraries in Node.js) to ensure that the uploaded file is suitable as input for conversion.
[0030] The system reads and parses VBA macro scripts, extracting the macro code. This parsing process may require calling a specific VBA parsing library or using regular expressions to identify and extract macro code segments. For Office documents, a specialized document parsing library, such as docx-js, may be used to convert the document to a text format and then filter out the macro code.
[0031] Before formal conversion, the VBA macro script is preprocessed, which may include removing comments, formatting the code, adding necessary contextual information (such as programming environment, functional logic description, etc.), and performing denoising operations to ensure that the input received by the model is clear, unambiguous, and free of irrelevant information.
[0032] Before processing files, perform security checks to prevent malicious code or viruses from entering the system through uploaded script files. This may include using security scanning tools to check uploaded files and setting restrictions such as file size limits and file types to prevent resource exhaustion or potential threats.
[0033] Before the conversion begins, create a backup of the uploaded file to ensure that the original file is not affected by the conversion process. At the same time, implement a version control mechanism to record the detailed information of each conversion, including the versions before and after the conversion, the conversion date, user information, etc., for easy tracking and recovery.
[0034] Through the above steps, the VBA macro script file to be converted can be accurately and safely obtained and prepared, providing high-quality input for subsequent model conversion.
[0035] Step S204: performing a code processing operation on the script file to obtain a first script file, wherein the code processing operation includes adding the programming environment and functional logic information of the script file to the first script file, and performing a denoising operation on the script file;
[0036] Optionally, performing code processing on the script file is a key step in the conversion process, aiming to provide optimized input for subsequent model conversion while ensuring the accuracy and efficiency of the conversion process. Specific operations include:
[0037] Add programming environment and functional logic information: When processing VBA macro scripts, the system needs to understand the context in which the script is running, which includes but is not limited to the version of Microsoft Office used, the specific document type (such as Excel workbooks, Word documents, etc.), and the specific functions of the macro script in the document (such as data processing, format adjustment, automated tasks, etc.). This information can be embedded in the first script file in the form of comments or metadata to help the model consider these factors during conversion, thereby generating more accurate and functionally equivalent JavaScript macro scripts. For example, for a VBA macro that processes Excel data, the system will automatically recognize that its running environment is Excel and extract the functional description of the macro, such as "batch update data in specified worksheets." This information will be appended to the header of the first script file or other predefined locations for the model to reference during conversion.
[0038] Perform denoising: VBA macro scripts may contain a large number of comments, redundant code, or irrelevant modules, which are not necessary when converted to JavaScript macro scripts. The denoising operation aims to remove these non-functional elements and retain the core code logic to improve the efficiency and accuracy of the model conversion. The denoising operation may include: removing all comments, including single-line comments and multi-line comments. Deleting unused variables and function definitions to avoid introducing unnecessary complexity during the conversion process. Eliminating code fragments that are incompatible with the target environment for conversion, such as certain object model calls that are only valid in the VBA environment. Identifying and removing duplicate code segments to ensure that the converted script is concise and logically clear. The denoising operation can be achieved through static code analysis tools, such as VBA parsers, code beautifiers, and code analysis libraries. These tools can identify and remove unnecessary parts when processing VBA macro scripts, while keeping the core functionality and logical structure of the script unchanged.
[0039] Through the above code processing operations, the system is able to generate an optimized first script file. This file retains the original logic while removing interfering elements and adding necessary contextual information, providing clearer and more focused input for subsequent model conversion, ensuring the accuracy and quality of the conversion results.
[0040] Step S206: Use a pre-trained target network model to perform a conversion operation on the first script file to obtain a second script file, wherein the target network model is a model obtained by iteratively training the initial network model using multiple groups of sample script files, and the conversion operation includes: parsing the first script file to parse out a first logical framework and first code information of the first script file from the programming environment and the functional logic, wherein the first logical framework includes the program structure of the first script file and the program logic of the first script file, and the first code information is information in a first code format; determining conversion logic information for converting the first script file into a second script file, wherein the code included in the second script file is in a second code format; using the first logical framework and the conversion logic information, generating a second logical framework, wherein the second logical framework includes the program structure of the second script file and the program logic of the second script file; generating second code information of the second script file based on the second logical framework and the first code information, wherein the second code information has the same function as the first code information.
[0041] Optionally, at the beginning of the conversion process, the system needs to load a pre-trained target network model (e.g., a generative large language model), which has undergone multiple rounds of iterative training and can understand the syntax, structure, and functional logic of VBA macro scripts, while also having the ability to generate JavaScript macro scripts.
[0042] The initial network model learned common natural language and programming language patterns through training on a large amount of text and code data. It was then iteratively trained with targeted sample script files (i.e., pairs of VBA macro scripts and equivalent JavaScript macro scripts), gradually optimizing the conversion capabilities from VBA to JavaScript.
[0043] The specific training process includes the following steps:
[0044] S1. Dataset Construction and Preparation: Building a training dataset is crucial for model success. Data sources include, but are not limited to, open source code libraries, internal enterprise code, tutorials, and programming books. This includes both VBA macro scripts and JavaScript code. However, to achieve VBA-to-JavaScript conversion, we need to focus on collecting functionally or logically corresponding VBA macro script and JavaScript code pairs. This is achieved by identifying and matching scripts with similar functionality, for example, a VBA macro for Excel data processing and a JavaScript macro that implements the same functionality.
[0045] S2, code preprocessing: After data collection, the preprocessing step is very important to ensure that the model can effectively learn the pattern of code conversion. Preprocessing includes: Syntax analysis and abstract syntax tree generation: Convert VBA and JavaScript code into abstract syntax tree (AST) format, so that the model can not only understand the linear text of the code, but also capture its structure and syntax hierarchy, which is convenient for cross-language logical mapping. Adding contextual information: Add contextual information related to the programming environment (such as Excel, Web), variable scope, and function purpose to the code snippet. This information is embedded in the code in the form of metadata or comments to help the model understand the running environment and expected functions of the code. For example, the VBA Range object has specific functions in Excel, while different APIs are required to achieve similar functions in JavaScript.
[0046] S3, Model Architecture Selection and Training: Choose a generative large language model architecture that has been trained on extensive text and code data, such as GPT or Wenxinyiyan. These model architectures provide the foundation for the model's training and conversion capabilities, and they can understand multiple programming languages.
[0047] The model training process includes the following steps:
[0048] S1, input-output pair learning, takes VBA macro scripts and corresponding JavaScript macro scripts as paired input and output. The model understands the grammatical and logical conversion rules between the two languages by learning these pairs.
[0049] S2, iterative optimization. During the learning process, the model gradually optimizes its conversion capabilities through multiple rounds of iterative training to ensure that the generated JavaScript code is not only syntactically correct but also retains the functional logic of the original VBA macro script.
[0050] S3, Model Tuning and Validation. After training, the model undergoes validation to ensure the accuracy of its conversion capabilities. This includes: Test dataset validation: Using VBA macro scripts and JavaScript macro scripts that were not used in training to test the model's conversion effectiveness and evaluate its performance on unseen data. Error type analysis and correction: Based on the test results, analyze the types of errors generated by the model, such as syntax errors and functional logic errors, adjust model parameters, optimize conversion rules, and improve the model's conversion success rate and code quality.
[0051] S4, continuous optimization and updating. As the model is used, user feedback and actual conversion effects are collected, the training dataset is continuously updated, and the model is iteratively trained to adapt to new code scenarios and improve the accuracy and efficiency of conversion.
[0052] Through the above training process, the target network model can deeply understand the differences between VBA macro scripts and JavaScript macro scripts, not only converting them at the syntax level, but also maintaining equivalence in high-level logic and detailed syntax, thereby achieving high-quality code conversion tasks.
[0053] Optionally, in this embodiment, parsing the first script file includes: taking the optimized first script file (i.e., a denoised VBA macro script with environment and logic information) as input, and the model begins parsing the script's structure and semantics, including program structure (such as function definitions, class structures, loop statements, etc.) and program logic (such as data processing flow, conditional branches, etc.). The parsing process involves an in-depth understanding and grammatical analysis of the script, and the model is able to identify VBA-specific object model operations, function calls, and event handling mechanisms.
[0054] Optionally, in this embodiment, determining the conversion logic information includes: based on the first logical framework and first code information of the first script file, the model determines conversion strategies and rules, including how specific syntax and functions in the VBA macro script are mapped to the JavaScript macro script. The conversion logic information is determined based on the conversion pattern between VBA and JavaScript learned by the model during training, ensuring that the converted script can run normally in the new environment while maintaining the same functionality as the original script.
[0055] Optionally, in this embodiment, generating the second logical framework includes: using the parsed first logical framework and conversion logic information, the model generates a second logical framework of a second script file (i.e., a JavaScript macro script), which includes JavaScript versions of the program structure (e.g., function definitions, loop statements, etc.) and program logic (e.g., data processing flow, conditional branches, etc.). Generating the second logical framework is key to the conversion process, ensuring the structural and logical equivalence of the converted script, laying a solid foundation for subsequent code generation.
[0056] Optionally, in this embodiment, the second code information generation includes: based on the second logical framework and the first code information, the model generates the second code information of the second script file, that is, specific JavaScript code, which is functionally equivalent to the first code information (i.e., VBA macro script code) and can reproduce the same operations and processing. The generated second code information follows JavaScript syntax specifications and best practices, improves the readability and maintainability of the code, and ensures that the converted script can operate normally in the target environment (e.g., Web applications, localized systems, etc.).
[0057] In this embodiment, the execution subject of the above steps can be a terminal, a server, a specific processor set in the terminal or server, or a processor or processing device set relatively independently from the terminal or server, but is not limited thereto.
[0058] Through the above steps, the conversion operation is performed on the processed first script file using the pre-trained target network model. This model is obtained by iteratively training a large number of sample script files and is capable of understanding and converting complex code logic. The conversion operation includes parsing the first script file, extracting the first logical framework (program structure and program logic) and the first code information therefrom, then determining the conversion logic information, and based on the first logical framework and the conversion logic information, the model generates the second logical framework. Finally, using the second logical framework and the first code information, the model generates the second code information of the second script file. The first script file can be converted into the second script file efficiently and accurately, which significantly improves the efficiency and quality of code conversion, reduces the errors and time cost of manual conversion, and improves the productivity of developers. Therefore, the problem of low script conversion efficiency in the related art can be solved.
[0059] In an exemplary embodiment, the target network model includes a syntax parser that parses the first script file to parse out the first logical framework and first code information of the first script file from the programming environment and the functional logic, including: parsing the programming environment of the first script file by the syntax parser to extract the program structure of the first script file; parsing the functional logic and syntax structure in the first script file by the syntax parser to obtain the program logic of the first script file; parsing the code in the first script file by the syntax parser to obtain the first code information.
[0060] Optionally, in this embodiment, the syntax parser is a component in the target network model that analyzes the structure of programming language code and decomposes it into smaller grammatical units, such as keywords, identifiers, operators, etc. The syntax parser can generate a syntax tree (e.g., an abstract syntax tree (AST)), which is a tree structure that can clearly represent the grammatical structure of the code, making it easier to understand and process the code.
[0061] Optionally, the first logical framework refers to the code logic structure and flow extracted from the first script file (e.g., a VBA macro script). It includes an in-depth analysis of the original script's program structure and program logic, covering the script's function definitions, variable declarations, conditional statements, loop structures, etc., and serves as an important reference during the conversion process.
[0062] Optionally, the first code information refers to a code segment that implements a specific function in a first script file (e.g., a VBA macro script). This information is presented in VBA syntax and structure, including details such as function calls, object operations, and variable assignments, and is the basis for conversion into a JavaScript macro script.
[0063] For example, consider a VBA macro script named SumData, which summarizes data on a specific worksheet in an Excel workbook. The script processing program converts SumData.vba into SumData_cleaned.vba. This processing removes comments, redundant code, and non-functional elements, while also adding programming environment information and functional logic descriptions. For example, a comment such as " / / Used in Excel 2016 for data summation" is added to the beginning of the script to help the parser understand the macro's operating environment and intended functionality.
[0064] The first logical framework and first code information are parsed from SumData_cleaned.vba. The program structure is extracted, and the parser identifies the function definitions, parameter lists, loop structures, and conditional statements within the macro. The program logic is then derived, and the main logic flow of the macro, such as data reading, summary calculations, and result output, is analyzed. The target network model generates the corresponding JavaScript macro script code based on the parsed first logical framework and first code information. The model understands the intent of the VBA code and converts it into WPS Office-compatible JavaScript code.
[0065] Through the above embodiments, we can see the role of the syntax parser in parsing scripts and extracting key information, as well as how the target network model uses this information to generate functionally equivalent JavaScript macro scripts, thereby achieving automatic conversion from VBA to JavaScript.
[0066] In an exemplary embodiment, the target network model includes a mapping subnetwork, and determining conversion logic information for converting the first script file into the second script file includes: inputting the first logical framework into the mapping subnetwork and inputting the script type of the second script file into the mapping subnetwork; and searching, through the mapping subnetwork, for a preset logical framework that matches the second script file according to the script type of the second script file;
[0067] Optionally, the mapping subnetwork in this embodiment is a component in the target network model that performs logical conversion and syntax mapping from a source scripting language (e.g., a VBA macro script) to a target scripting language (e.g., a JavaScript macro script). By learning the conversion rules and corresponding logic between different scripting languages, the mapping subnetwork can map the logical framework of the source language to the logical framework of the target language, ensuring that the converted script remains consistent with the original script in terms of functionality and logic.
[0068] Optionally, a preset logical framework refers to a predefined code structure and process template in the target scripting language that is related to specific functionality or logic. These frameworks typically include the basic grammatical structure of the target language and common code patterns for implementing similar functions, such as loop structures for data processing and API calls for file reading and writing. The preset logical framework serves as a key reference for the mapping subnetwork to construct the target script during the conversion process.
[0069] Optionally, the conversion logic information includes mapping rules and conversion strategies from the first logical framework (i.e., the logical framework of the source language) to a preset logical framework corresponding to the script type of the second script file. This includes details such as data type conversion, function library call replacement, and control structure conversion, ensuring that the functionality of the source script is preserved in the target script.
[0070] The preset logical framework and the first logical framework are parsed by the mapping sub-network to establish a mapping relationship between the preset logical framework and the first logical framework, thereby obtaining the conversion logic information.
[0071] For example, converting a VBA macro script for automatic formatting of Microsoft Word documents into a JavaScript macro script in WPS Office involves the following steps:
[0072] S1 constructs a first logical framework and first code information, and uses a syntax parser to parse the VBA macro script AutoFormatDoc.vba to extract its program structure, logic flow, and code information. For example, the macro script may contain logic for adjusting paragraph styles, changing font colors, and setting page margins for a Word document.
[0073] S2, the mapping sub-network determines the conversion logic information, inputs the first logic framework into the mapping sub-network, and inputs the target script type (JavaScript) into the mapping sub-network. The mapping sub-network searches for a preset logic framework compatible with the WPS Office environment based on the input script type. These frameworks contain JavaScript code structures and API calls that implement similar Word document formatting functions in WPS Office. The mapping sub-network parses the preset logic framework and the first logic framework, establishes a mapping relationship between the two, and determines the conversion logic information. The conversion logic information includes how specific operations in VBA are converted to corresponding API calls in JavaScript, such as how paragraph style adjustments in VBA are mapped to WPS Office paragraph style settings in JavaScript.
[0074] S3 generates a second logical framework and second code information for the second script file. Based on the converted logical information, the mapping subnetwork generates the second logical framework of the second script file (i.e., JavaScript macro script), including structures such as function definitions, variable declarations, and API calls. Based on the second logical framework and the first code information, the mapping subnetwork generates specific JavaScript code, i.e., the second code information. For example, the paragraph style setting in VBA is converted into an API call such as paragraph.style = 'Heading1' in JavaScript.
[0075] Through the above steps, we can see how the mapping subnetwork searches for the corresponding preset logical framework in the target scripting language, parses and establishes the mapping relationship, and generates a functionally equivalent JavaScript macro script, thus achieving automatic conversion from VBA to JavaScript. The mapping subnetwork ensures that the conversion process is not only a syntactic conversion, but also a precise mapping at the logical and functional levels, ensuring the correctness and practicality of the converted script.
[0076] In an exemplary embodiment, the target network model includes a logic parser and a logic converter. The generating of the second logic framework using the first logic framework and the conversion logic information includes: parsing the program structure and program logic of the first script file by the logic parser, wherein the program structure of the first script file includes at least one of the following: function calls, variable declarations, data types, and object operations, and the program logic of the first script file includes at least one of the following: logic control structures and event processing logic; inputting the conversion logic information and the first logic framework parsed by the logic parser into the logic converter; the logic converter converts the logic control structure of the first script file into an equivalent structure of the second script, converts the function calls of the first script file into function calls of the second script file, converts the object operations of the first script file into application programming interface (API) calls of the second script file, and processes data type differences between the first and second script files; constructing a syntax tree of the second script file by the logic converter, and generating the second logic framework using the syntax tree, the equivalent structure of the second script, the function calls of the second script file, the API calls of the second script file, and the processed data type differences. The syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file.
[0077] Optionally, the logic parser in this embodiment is a component in the target network model that is used to deeply understand the logical structure and functional execution process of the source script (e.g., VBA macro script). It can accurately identify and split programming elements such as function calls, variable declarations, data types, object operations, as well as advanced functions such as logical control structures (e.g., loops, conditional judgments) and event processing logic. The logic parser represents the logical framework of the source script by generating an abstract syntax tree (AST), which facilitates further logic conversion and code generation.
[0078] Optionally, the logic converter in this embodiment is another key component in the target network model. It is used to receive the first logic framework (the logical structure of the source script) and conversion logic information (the conversion rules from the source script to the target script) obtained from the logic parser, and is responsible for converting the logical control structure of the source script into an equivalent structure of the target script (for example, a JavaScript macro script), converting function calls and object operations in the source script into function calls and API calls in the target script, and processing data type differences between the source and target scripts. The logic converter ensures that the converted script can run accurately in the target environment, retaining the original logical flow and functional implementation.
[0079] Optionally, the syntax tree in this embodiment is a tree-like data structure used to represent the grammatical structure of the source code. During the script conversion process, the syntax tree can clearly represent the logical structure and grammatical characteristics of the code, including the relationships between programming elements such as functions, variables, keywords, and operators. The syntax tree is the basis for the logic parser and logic converter to process script logic, helping the model understand the code structure and generate equivalent code for the target script.
[0080] Logical Parser Parsing Process: The logical parser first deeply parses the above VBA macro script, generating an abstract syntax tree (AST). It identifies the following: Function call: GenerateReport() function. Variable declarations: ws (worksheet object), report (report string). Data types: string (report), worksheet object (ws). Object operations: ws.Range, row.Cells, etc. Logical control structures: For Each...Next loop, If...End If conditional statements. Event handling logic: None (VBA macro scripts typically do not include event monitoring logic).
[0081] Logic converter conversion process: The parsed logic framework and conversion logic information are input into the logic converter, which performs the following conversions:
[0082] Converts a For Each...Next loop to a for...of loop or .forEach() method in JavaScript.
[0083] Convert the If...End If conditional to a JavaScript if statement.
[0084] Convert MsgBox function calls in VBA to alert function calls or logging in JavaScript.
[0085] Convert ws.Range and row.Cells object operations to API calls in WPS Office JavaScript macro scripts, such as context.workbook.worksheets.getItem("Data").getRange("A1:Z100").values.
[0086] Handle data type differences between VBA and JavaScript, such as string array representation.
[0087] A syntax tree of the JavaScript macro script code is constructed through a logic converter to ensure that the logical structure of the converted code is consistent with the original VBA macro script and generate a second logic framework.
[0088] Through the above-described embodiment, the logic parser and logic converter work together to analyze the source script's logical framework, apply the conversion logic information, and generate a second logical framework for the target script, ultimately achieving functionally equivalent code conversion. This process ensures that the converted script is not only syntactically correct but also logically consistent with the original script, capable of running in the new environment and performing the same functions.
[0089] In an exemplary embodiment, the target network model includes a code generator, and generating second code information of the second script file based on the second logical framework and the first code information includes: inputting the second logical framework and the first code information into the code generator, and mapping the first code information to the syntax and functions in the second logical framework according to syntax elements, function calls, and object operations by the code generator to obtain the code structure of the second script file; adjusting the code structure of the second script file through a syntax tree of the second script file to obtain an adjusted code structure, wherein the syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file; generating code information based on the adjusted code structure to obtain the second code information.
[0090] Optionally, the code generator in this embodiment is another component in the target network model, primarily used to generate second code information of a functionally equivalent target script (e.g., a JavaScript macro script) based on the converted logical framework (second logical framework) and the first code information of the source script. It can map the grammatical elements, function calls, and object operations in the first code information to the target script based on the grammatical rules and functional correspondence of the target script, ensuring that the generated code is not only syntactically correct but also logically consistent with the source script.
[0091] Optionally, syntax tree adjustment in this embodiment refers to performing necessary structural and syntactic optimization on the syntax tree of the second script file during the code generation process to ensure that the generated code can run efficiently and correctly in the target environment. This includes adjusting the code structure to conform to best programming practices, such as avoiding redundant code, optimizing loop and conditional statement structures, adjusting variable scope, etc., as well as fine-tuning based on the syntactic characteristics of the target script to ensure that the generated code is syntactically correct and easy to understand and maintain.
[0092] Code generator generation process: The code generator receives the second logical framework (i.e. the logical framework of the converted JavaScript macro script) and the first code information (i.e. the specific code information of the VBA macro script), and starts to generate the second code information (JavaScript macro script code).
[0093] Map the syntax elements, function calls, and object operations in the first code information to the syntax and functionality in the second logical framework. For example, convert the For Each...Next loop in VBA to the .forEach() method in JavaScript, convert the IsNumeric function call to the JavaScript typeof check or Number.isFinite method, and convert the ws.Range and cell.Value object operations to API calls in the WPS Office JavaScript macro script.
[0094] Based on the second logical framework and the mapping result, a code structure of the second script file is constructed, and a JavaScript macro script code structure is generated.
[0095] Syntax tree adjustment process: The code generator adjusts the generated code structure based on the syntax tree of the JavaScript macro script to ensure correct syntax, clear logic, and efficient performance. For example, static code analysis tools (such as ESLint) may be used to perform syntax checking and optimization, adjust the structure of loops and conditional statements, and optimize variable declarations and scopes to ensure that the generated code follows best programming practices.
[0096] Based on the adjusted code structure, the second code information, namely the final JavaScript macro script code, is generated to ensure that the code is not only functionally equivalent to the original VBA macro script, but is also optimized in syntax and logic, and can be seamlessly integrated into the WPS Office environment for operation.
[0097] This embodiment ensures that the converted script is not only functionally equivalent but also can be executed efficiently and correctly in the target environment through the process of code generator and syntax tree adjustment, which reflects the advancement and practicality of the technical solution of the present invention.
[0098] In an exemplary embodiment, the target network model includes a code debugger, and code information is generated based on the adjusted code structure. After obtaining the second code information, the method further includes: inputting the second code information into the code debugger, and performing a code debugging operation on the second code information through the code debugger, wherein the code debugging operation includes at least one of the following: code refactoring, eliminating redundancy, handling loops and recursion, and repairing exceptions.
[0099] Optionally, the code debugger in this embodiment is a component in the target network model, which is used to perform code debugging operations in the generated second code information (for example, the converted JavaScript macro script), including code refactoring, eliminating redundancy, processing loops and recursion, repairing exceptions, etc., to optimize the code structure, improve code execution efficiency, and ensure the correctness and stability of the code.
[0100] For example, after a VBA macro script is converted to a JavaScript macro script, the initially generated code may have performance issues and code redundancy, requiring further optimization through a code debugger.
[0101] The code debugger first identifies that traditional loops can be replaced with more modern and concise JavaScript syntax, such as using the Array.prototype.filter method to replace two nested loops, improving code readability and execution efficiency. It checks for unnecessary lines of code, such as context.load(dataRange), which is redundant here. Data can be loaded by directly calling context.sync(), simplifying the code structure. By observing the efficiency of the loop, the code debugger converts the conditional judgments and push operations in the inner loop into more efficient forms. Static code analysis tools (such as ESLint) are used to detect and correct potential syntax errors and logic problems to ensure the correctness of API calls.
[0102] This embodiment optimizes the second code information through the operation of the code debugger, so that the generated JavaScript macro script not only follows the best programming practices, but also has significant improvements in performance and stability. Code reconstruction and redundancy elimination simplify the code structure, processing loops and recursion optimizes loop efficiency, and fixing exceptions ensures the correctness and reliability of the code. These operations together provide a guarantee for the generation of high-quality JavaScript macro scripts, enabling them to run efficiently and stably in environments such as WPS Office.
[0103] In an exemplary embodiment, the second code information is input into the code debugger. After the code debugging operation is performed on the second code information through the code debugger, the method further includes: saving the debugged second code information and displaying the debugged second code information on a preset interface, wherein the preset interface includes a download service, and the download service is used to respond to the download operation triggered by the debugged second code information and convert the debugged second code information into a preset format.
[0104] Optionally, in this embodiment, after the code debugger completes the debugging operation, the system saves the final optimized second code information to the server or local storage, providing the user with a stable code version for subsequent use or further development.
[0105] Optionally, the preset interface in this embodiment refers to a portion of the user interface specifically used to display the debugged second code information. This interface typically includes a code editing area and one or more operation buttons, such as download, save, run test, etc., to provide users with an intuitive and user-friendly code viewing and management experience.
[0106] Optionally, the download service in this embodiment is one of the functions provided by the preset interface. It responds to the download operation triggered by the user, converts the debugged second code information into a preset format (such as a .js file), and provides it to the user for download, so that the user can save the debugged code file locally, which is convenient for further testing and deployment in the local environment.
[0107] For example, after the user uses the solution of the present invention to convert a VBA macro script into a JavaScript macro script, the system automatically inputs the preliminarily generated second code information (i.e., JavaScript macro script code) into the code debugger. The code debugger performs in-depth optimization on the second code information, including code reconstruction to improve readability, eliminating redundant code to improve execution efficiency, optimizing loops and recursive structures to reduce performance bottlenecks, and repairing exceptions to ensure the stability of the code. After debugging is completed, the code debugger saves the debugged second code information to a designated folder on the server, and displays the code information in a preset user interaction interface. The interface includes a code editing area where users can view and edit the debugged code, and a download button for downloading the debugged second code information to the local computer.
[0108] The user interface includes a code editing area: This area displays the debugged JavaScript macro script code, allowing users to review and fine-tune it. A download button triggers the download service, converting the debugged secondary code information into a .js file format for download. A save button saves any user-defined changes made to the preset interface. A run test button runs tests directly on the preset interface to verify the code's correctness and performance.
[0109] When the user clicks the download button, the pre-set interface download service is triggered, downloading the debugged second code information from the server to the user's device. The user can select a save location and save the code in .js file format. This allows users to further test and deploy the code in a local environment and make additional customizations based on actual needs, increasing the flexibility and practicality of the code.
[0110] This example demonstrates the smooth and efficient code conversion, debugging, and downloading process. From the automated conversion of VBA macro scripts to the in-depth optimization of JavaScript macro scripts, and finally to the display and download of debugged code information in the user interface, each step is designed to improve code quality, simplify user operations, and ensure that the generated code can be executed accurately in the target environment, while providing users with convenient code management and download services.
[0111] The present application is described in detail below with reference to specific embodiments:
[0112] This specific embodiment is described by taking the generated JavaScript code as an example. Figure 3 As shown, the following steps are included:
[0113] S301, read in VBA script: At this stage, users can upload VBA macro script files (such as .xlsm or .docm files) to be converted through the graphical user interface (GUI) or command line interface (CLI). The system will receive these files and read the VBA macro script code contained therein.
[0114] S302: Send the VBA script to the model, which parses the VBA script. This embodiment utilizes a generative large language model to parse and understand the logic and structure of the VBA script. The model receives the VBA script code through an API interface and performs semantic analysis and syntactic parsing. This includes identifying key syntactic elements (such as variables, functions, conditional statements, etc.), understanding the logical intent and functionality of the code, and converting it into a representation within the model.
[0115] S303: Derivation of mapping rules from VBA scripts to JavaScript: Based on analysis of the VBA scripts, the model uses learned mapping rules (e.g., data type conversion, function library substitution, control structure conversion, etc.) to derive a set of specific rules for converting VBA scripts to JavaScript. These rules take into account the syntactical differences and functional correspondence between the two languages, ensuring that the converted code remains as consistent as possible in structure and logic.
[0116] S304, generate a JavaScript code framework and template, whose structure, function and logical framework are consistent with those before conversion; based on the parsed VBA logic and mapping rules, the model generates a framework and template for JavaScript code. This framework is structurally consistent with the original VBA script, and an abstract syntax tree (AST) is constructed to retain its original function and logical framework. At the same time, the model will make preliminary adjustments to the template according to the JavaScript syntax specifications to ensure its basic operability in the JavaScript environment. For example, assuming a VBA macro script uses a For Each...Next loop structure, the model will generate a corresponding JavaScript loop structure, such as a for loop or a .forEach() method, while retaining the specific functional operations in the loop.
[0117] S305, optimize and adjust the code, adapt to the environment, and introduce manual review when necessary; after the generated JavaScript code undergoes preliminary structural and functional conversion, the system further optimizes the code, including syntax checking, logic clarification, code refactoring, performance optimization, etc. At the same time, the system adapts the code according to the target environment (such as the WPS Office JavaScript macro environment) to ensure that the converted code can run stably in that environment. If a code segment with possible missing functions, high logical complexity, or potential errors is detected during the automatic optimization process, the system will automatically introduce a manual review process. The reviewer can further check and correct the code based on the prompts provided by the system to ensure the accuracy of the conversion.
[0118] S306: Output JavaScript script, provide feedback mechanism and version control; finally, the system outputs the optimized JavaScript script to the GUI for display, allowing users to view, edit, and save it as a .js file. The system also provides a feedback mechanism, allowing users to submit feedback after use to improve model training and conversion strategies.
[0119] In addition, the system uses a version control mechanism, using services such as GitLab, to track every code transformation and optimization. This allows for tracing back and rolling back to previous code versions if necessary. The model status can also be synchronized and managed through version control.
[0120] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0121] In this embodiment, a device for generating code information is also provided, which is used to implement the above-mentioned embodiments and preferred embodiments. The details already described will not be repeated here. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0122] Figure 4 is a structural block diagram of a device for generating code information according to an embodiment of the present application, such as Figure 4 As shown, the device includes:
[0123] A first acquisition module 42 is used to acquire a script file to be converted;
[0124] a first processing module 44 configured to perform a code processing operation on the script file to obtain a first script file, wherein the code processing operation includes adding the programming environment and functional logic information of the script file to the first script file, and performing a denoising operation on the script file;
[0125] The first conversion module 46 is used to perform a conversion operation on the first script file using a pre-trained target network model to obtain a second script file, wherein the target network model is a model obtained by iteratively training an initial network model using multiple groups of sample script files, and the conversion operation includes: parsing the first script file to parse out a first logical framework and first code information of the first script file from the programming environment and the functional logic, wherein the first logical framework includes the program structure of the first script file and the program logic of the first script file, and the first code information is information in a first code format; determining conversion logic information for converting the first script file into a second script file, wherein the code included in the second script file is in a second code format; using the first logical framework and the conversion logic information, generating a second logical framework, wherein the second logical framework includes the program structure of the second script file and the program logic of the second script file; generating second code information of the second script file based on the second logical framework and the first code information, wherein the second code information has the same function as the first code information.
[0126] In an exemplary embodiment, the target network model includes a syntax parser, and the above-mentioned first conversion module 46 is also used to parse the first script file in the following manner to parse out the first logical framework and first code information of the first script file from the programming environment and the functional logic: parsing the programming environment of the first script file by the syntax parser to extract the program structure of the first script file; parsing the functional logic and syntax structure in the first script file by the syntax parser to obtain the program logic of the first script file; parsing the code in the first script file by the syntax parser to obtain the first code information.
[0127] In an exemplary embodiment, the target network model includes a mapping subnetwork, and the above-mentioned first conversion module 46 is further used to determine the conversion logic information for converting the first script file into the second script file in the following manner: inputting the first logical framework into the mapping subnetwork, and inputting the script type of the second script file into the mapping subnetwork; searching for a preset logical framework that matches the second script file according to the script type of the second script file through the mapping subnetwork; parsing the preset logical framework and the first logical framework through the mapping subnetwork to establish a mapping relationship between the preset logical framework and the first logical framework to obtain the conversion logic information.
[0128] In an exemplary embodiment, the target network model includes a logic parser and a logic converter, and the first conversion module 46 is further used to generate a second logic framework by using the first logic framework and the conversion logic information in the following manner: parsing the program structure of the first script file and the program logic of the first script file by the logic parser, wherein the program structure of the first script file includes at least one of the following: function call, variable declaration, data type, object operation, and the program logic of the first script file includes at least one of the following: logic control structure, event processing logic; inputting the conversion logic information and the first logic framework parsed by the logic parser into the logic converter, and converting the first logic framework into the second logic framework through the logic converter. The method includes converting the logical control structure of the script file into an equivalent structure of the second script, converting the function calls of the first script file into function calls of the second script file, converting the object operations of the first script file into application programming interface (API) calls of the second script file, and processing the data type differences between the first and second script files; constructing a syntax tree of the second script file through the logical converter, and generating a second logical framework using the syntax tree, the equivalent structure of the second script, the function calls of the second script file, the API calls of the second script file, and the processed data type differences, wherein the syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file.
[0129] In an exemplary embodiment, the target network model includes a code generator, and the above-mentioned first conversion module 46 is further used to generate second code information of the second script file based on the second logical framework and the first code information in the following manner: input the second logical framework and the first code information into the code generator, and the code generator maps the first code information to the syntax and functions in the second logical framework according to syntax elements, function calls and object operations, so as to obtain the code structure of the second script file; adjust the code structure of the second script file through the syntax tree of the second script file to obtain the adjusted code structure, wherein the syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file; generate code information based on the adjusted code structure to obtain the second code information.
[0130] In an exemplary embodiment, the target network model includes a code debugger, and the above-mentioned first conversion module 46 is further used to generate code information based on the adjusted code structure. After obtaining the second code information, the second code information is input into the code debugger, and a code debugging operation is performed on the second code information through the code debugger, wherein the code debugging operation includes at least one of the following: code reconstructing, eliminating redundancy, processing loops and recursions, and repairing exceptions.
[0131] In an exemplary embodiment, the above-mentioned first conversion module 46 is also used to input the second code information into the code debugger, and after performing a code debugging operation on the second code information through the code debugger, save the debugged second code information and display the debugged second code information on a preset interface, wherein the preset interface includes a download service, and the download service is used to respond to the download operation triggered by the debugged second code information and convert the debugged second code information into a preset format.
[0132] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0133] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any of the above method embodiments when run.
[0134] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0135] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0136] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0137] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.
[0138] An embodiment of the present application further provides another computer program product, comprising a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the above method embodiments are implemented.
[0139] An embodiment of the present application also provides a computer program, which includes computer instructions, which are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps of any of the above method embodiments.
[0140] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail here.
[0141] Obviously, those skilled in the art should understand that the modules or steps of the present application described above can be implemented using a general-purpose computing device, they can be concentrated on a single computing device, or distributed across a network composed of multiple computing devices, they can be implemented using program code executable by the computing device, and thus, they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be performed in a different order than herein, or they can be fabricated into separate integrated circuit modules, or multiple modules or steps can be fabricated into a single integrated circuit module for implementation. Thus, the present application is not limited to any specific combination of hardware and software.
[0142] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present application shall be included within the scope of protection of the present application.
Claims
1. A method for generating code information, characterized in that: include: Get the script file to be converted; Performing a code processing operation on the script file to obtain a first script file, wherein the code processing operation includes adding a programming environment and functional logic information of the script file to the first script file, and performing a denoising operation on the script file; The first script file is converted using a pre-trained target network model to obtain a second script file, wherein the target network model is a model obtained by iteratively training an initial network model using multiple groups of sample script files, and the conversion operation includes: Parsing the first script file to parse out a first logic framework and first code information of the first script file from the programming environment and the functional logic, wherein the first logic framework includes a program structure of the first script file and a program logic of the first script file, and the first code information is information in a first code format; Determining conversion logic information for converting the first script file into a second script file, wherein the code included in the second script file is in a second code format; Generate a second logical framework using the first logical framework and the conversion logic information, wherein the second logical framework includes the program structure of the second script file and the program logic of the second script file; Second code information of the second script file is generated based on the second logical framework and the first code information, wherein the second code information has the same function as the first code information.
2. The method according to claim 1, characterized in that: The target network model includes a syntax parser, which parses the first script file to parse out a first logic framework and first code information of the first script file from the programming environment and the functional logic, including: Parsing the programming environment of the first script file by the syntax parser to extract the program structure of the first script file; Parsing the functional logic and grammatical structure in the first script file by the grammar parser to obtain the program logic of the first script file; The first code information is obtained by parsing the code in the first script file through the syntax parser.
3. The method according to claim 1, characterized in that The target network model includes a mapping sub-network, and determining conversion logic information for converting the first script file into the second script file includes: Inputting the first logical framework into the mapping subnetwork, and inputting the script type of the second script file into the mapping subnetwork; Searching, through the mapping subnetwork, for a preset logical framework matching the second script file according to the script type of the second script file; The preset logic framework and the first logic framework are parsed through the mapping sub-network to establish a mapping relationship between the preset logic framework and the first logic framework, thereby obtaining the conversion logic information.
4. The method according to claim 1, characterized in that The target network model includes a logic parser and a logic converter, and the generating of the second logic framework by using the first logic framework and the conversion logic information includes: Parsing the program structure of the first script file and the program logic of the first script file by the logic parser, wherein the program structure of the first script file includes at least one of the following: function call, variable declaration, data type, object operation, and the program logic of the first script file includes at least one of the following: logic control structure, event processing logic; Input the conversion logic information and the first logic framework parsed by the logic parser into the logic converter, and convert the logic control structure of the first script file into an equivalent structure of the second script file, convert the function call of the first script file into the function call of the second script file, convert the object operation of the first script file into the application programming interface API call of the second script file, and process the data type difference between the first script file and the second script file through the logic converter; A syntax tree of the second script file is constructed through the logic converter, and the second logical framework is generated by using the syntax tree, the equivalent structure of the second script, the function call of the second script file, the API call of the second script file, and the processed data type difference, wherein the syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file.
5. The method according to claim 1, characterized in that The target network model includes a code generator, which generates second code information of the second script file based on the second logical framework and the first code information, including: Inputting the second logical framework and the first code information into the code generator, and mapping the first code information to the syntax and functions in the second logical framework according to syntax elements, function calls and object operations by the code generator, to obtain the code structure of the second script file; Adjusting the code structure of the second script file by using a syntax tree of the second script file to obtain an adjusted code structure, wherein the syntax tree is used to represent the logical structure and syntax characteristics of the code of the second script file; Generate code information based on the adjusted code structure to obtain the second code information.
6. The method according to claim 5, characterized in that The target network model includes a code debugger, and code information is generated based on the adjusted code structure. After obtaining the second code information, the method further includes: The second code information is input into the code debugger, and a code debugging operation is performed on the second code information through the code debugger, wherein the code debugging operation includes at least one of the following: code refactoring, eliminating redundancy, processing loops and recursion, and repairing exceptions.
7. The method according to claim 6, characterized in that After inputting the second code information into the code debugger and performing a code debugging operation on the second code information through the code debugger, the method further includes: The debugged second code information is saved and displayed on a preset interface, wherein the preset interface includes a download service, and the download service is used to respond to a download operation triggered by the debugged second code information and convert the debugged second code information into a preset format.
8. A device for generating code information, characterized in that: include: A first acquisition module, used to acquire a script file to be converted; A first processing module, configured to perform a code processing operation on the script file to obtain a first script file, wherein the code processing operation includes adding a programming environment and functional logic information of the script file to the first script file, and performing a denoising operation on the script file; The first conversion module is used to perform a conversion operation on the first script file using a pre-trained target network model to obtain a second script file, wherein the target network model is a model obtained by iteratively training an initial network model using multiple groups of sample script files, and the conversion operation includes: parsing the first script file to parse out a first logic framework and first code information of the first script file from the programming environment and the functional logic, wherein the first logic framework includes a program structure of the first script file and a program logic of the first script file, and the first code information is information in a first code format; determining conversion logic information for converting the first script file into a second script file, wherein the code included in the second script file is in a second code format; using the first logic framework and the conversion logic information, generating a second logic framework, wherein the second logic framework includes a program structure of the second script file and a program logic of the second script file; generating second code information of the second script file based on the second logic framework and the first code information, wherein the second code information has the same function as the first code information.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 7 when executed by a processor.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method described in any one of claims 1 to 7 are implemented.