Code converter and conversion method

Through the code conversion method, old language code is processed and parsed, and converted into new code that adapts to the new technical framework, solving the problems of old language code maintenance and upgrading, and achieving low-cost secondary development and quality improvement.

CN119512566APending Publication Date: 2025-02-25SUZHOU INDAL PARK LINKAGE SOFTWARE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411544731.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-31
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

Due to the lack of understanding and maintenance of the code developed by old language R&D systems, the code is poorly used and difficult to upgrade and secondary development.

Method used

Through a code conversion method, the original code is processed to comply with the parsing specifications, the original code is parsed to obtain information, the original code is converted using the code conversion tool, and the new code is output to adapt to the new technical framework.

Benefits of technology

It realizes the continued use of the running logic and code content of the original program, and realizes the upgrade and secondary development of the original program at a low cost, saves resources and improves the quality of use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119512566A_ABST
    Figure CN119512566A_ABST
Patent Text Reader

Abstract

The invention discloses a code conversion method, which comprises the following steps of: processing an original code so that the original code conforms to a subsequent analysis specification; analyzing the original code to obtain information of the original code; and code conversion: according to the obtained original code information, converting an original code through a code conversion tool, and outputting a new code. A code converter comprises a preprocessing module, an analysis module and a conversion module. According to the code converter and the conversion method provided by the invention, the original program language is analyzed and converted to adapt to the new program language, so that the running logic and code content of the original program can be continuously used, the upgrading and secondary development of the original program are realized at low cost, resources are saved, and the use quality is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a code converter and a conversion method. Background Art

[0002] With the continuous changes in technology in the industry, the codes developed by old language development systems such as Cobol, Ruby and VB.NET are often facing the situation of being eliminated. Specifically, there are no corresponding engineers who can understand them, and the original codes cannot be updated and maintained in time, which leads to poor use effects. Therefore, one way to solve the problem is to improve the system of old language codes to a system of new technology framework to reduce the dependence on old languages. At the same time, secondary development and system upgrades are carried out based on the new technology framework to improve productivity and system upgrade effects and use quality. Summary of the invention

[0003] In view of the above-mentioned shortcomings in the prior art, the present invention provides a code conversion method, comprising:

[0004] Process the original code to make it conform to the subsequent parsing specifications;

[0005] Analyze the original code to obtain the information intelligence of the original code;

[0006] Convert the code, convert the original code through a code conversion tool according to the obtained original code information, and output a new code.

[0007] Furthermore, it also includes:

[0008] The new code is shaped and outputted.

[0009] Furthermore, the processing source code also includes:

[0010] Replace the referenced asset content in the original code with the actual asset content;

[0011] Replace the non-standard characters in the original code with standard characters;

[0012] Format the code according to the preset code format.

[0013] Furthermore, the parsing of the original code includes: parsing the original code by means of artificial intelligence, or parsing the original code by means of a syntax tree.

[0014] Further, including:

[0015] Parse the original code through the parser and convert it into an abstract syntax tree;

[0016] Decomposing the abstract syntax tree hierarchically;

[0017] The information of each layer of the abstract syntax tree is structured and stored in a syntax container pool.

[0018] Furthermore, it is characterized in that the conversion code includes:

[0019] Obtaining an abstract syntax tree formed after being processed by the parser;

[0020] Traversing the abstract syntax tree to obtain the level information of the syntax tree;

[0021] Obtaining grammatical rules and node information in the hierarchical information and performing matching;

[0022] Edit the obtained language information and grammar information and convert them into Eclipsejdt abstract syntax tree;

[0023] The Eclipsejdt code generation method is called, and the converted java source code is generated according to the Eclipsejdt abstract syntax tree.

[0024] The present invention also provides a code converter, comprising:

[0025] The preprocessing module is used to preprocess the original code so that the original code meets the subsequent parsing specifications;

[0026] The parsing module is used to parse the original code to obtain information intelligence of the original code;

[0027] The conversion module converts the original code through a code conversion tool according to the acquired original code information and outputs a new code.

[0028] Furthermore, it also includes:

[0029] The code shaping module is used to shape the obtained new code and convert it into a code that meets the standards of the new technology framework.

[0030] Beneficial effect: The present invention provides a code converter and conversion method, which parses and converts the original program language to adapt it to a new programming language, so that the operating logic and code content of the original program can continue to be used, and the original program can be upgraded and redeveloped at a low cost, saving resources and improving the quality of use. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] Figure 1 It is a schematic diagram of the main steps of the method of the present invention.

[0032] Figure 2 It is a schematic diagram of a sub-step of the method of the present invention.

[0033] Figure 3 It is another schematic diagram of sub-steps of the method of the present invention.

[0034] Figure 4 It is another schematic diagram of sub-steps of the method of the present invention.

[0035] Figure 5 It is a schematic diagram of the structure of the code converter in the present invention. DETAILED DESCRIPTION

[0036] The present invention will be further described below in conjunction with the accompanying drawings and embodiments:

[0037] like Figure 5 As shown, a code converter is used to convert one software language into another software language. The code converter includes a preprocessing module 10, a parsing module 20 and a conversion module 30. The preprocessing module 10 is used to preprocess the original code to be converted so that the original code meets the subsequent code parsing specifications after processing. The parsing module 20 is used to parse the preprocessed original code to obtain the information intelligence contained in the original code. The conversion module 30 converts the above-processed original code through a code conversion tool according to the original code information intelligence obtained from the parsing module 20, and outputs a new code. The new code meets the requirements.

[0038] In some preferred embodiments, Figure 5 As shown, the code converter further includes a code shaping module 40, which shapes the new code obtained above and converts it into a code that complies with the new technical framework standard.

[0039] like Figure 1-4 The code conversion method comprises the following steps:

[0040] S100: Process the original code.

[0041] In this step, processing the original code is to preprocess the original code so that the original code meets the subsequent parsing specifications.

[0042] S200, parsing the original code.

[0043] In this step, the preprocessed original code is parsed to obtain information intelligence of the original code.

[0044] S300, conversion code.

[0045] In this step, the original code is converted by a code conversion tool according to the information of the original code obtained, and a new code is output.

[0046] In some preferred embodiments, the steps are further included:

[0047] S400: shaping the new code and outputting it.

[0048] In this step, the new code is shaped to make it fully compliant with the usage standards.

[0049] In some preferred embodiments, the step S100 further includes the following sub-steps:

[0050] S101. Replace the referenced asset content in the original code with the actual asset content.

[0051] In this step, the referenced asset content involved is generally a cpy text, and the code content is updated by replacement.

[0052] S102, replacing the non-standard characters in the original code with standard characters.

[0053] In this step, the characters of the code are standardized by replacing the non-standard characters, which is convenient for subsequent processing. For example, the full-width spaces, TABs, and line breaks that do not conform to the parsing specifications are replaced with regular half-width spaces, TABs, and line breaks, which is the replace operation of the Java string.

[0054] S103: Format the code according to a preset code format.

[0055] In this step, the code formatting process is to adaptively process the original code according to the code format preset by the program configuration, so as to make the format of the original code conform to the standard.

[0056] In some preferred implementations, the original code is parsed by artificial intelligence or by syntax tree. In the parsing step, parsing can be achieved by artificial intelligence or syntax tree.

[0057] In some preferred embodiments, step S200 includes:

[0058] S201. Parse the original code through a parser and convert the original code into an abstract syntax tree.

[0059] In this step, the source code of the current system is parsed into an abstract syntax tree structure through ANTLR4 (ANother Tool for Language Recognition) through a parser. In this way, the abstract syntax tree can be processed through the program to obtain various information intelligence of the current system source code, which is convenient for subsequent processing.

[0060] The syntax tree file (.g4) is generally a standardized associated file of the corresponding development language. For example, for the cobol language, a standard cobol syntax tree file needs to be created first. During the specific implementation, for different specific conversion projects, the adaptability of the standardized syntax tree file will be confirmed first, and then according to the syntax characteristics and development specifications of the original development language, the project engineering code to be adopted will be specially customized to meet the corresponding syntax.

[0061] The syntax tree program part involved is set in the above-mentioned parsing module.

[0062] S202: Decompose the abstract syntax tree in layers.

[0063] In this step, the syntax tree is actually operated. The information of the syntax tree parsed from the current code is obtained. The information of the syntax tree is converted into information that is easy to understand and operate through the core parsing API, which is convenient for subsequent acquisition and use.

[0064] S203: Structuring the information of each layer of the abstract syntax tree and storing it in a syntax container pool.

[0065] In this step, the information of each layer of the syntax tree is structured, and a special syntax container pool is set up in the converter to store the parsed content. Structuring is to store the data of each layer of the abstract syntax tree according to preset rules. In the specific implementation, the obtained information is stored in statements of various syntax types, and the specific content is the decomposed content of each line of syntax. Example: move a to b, decomposed into moveStatement; moveStatement corresponds to a structure of the syntax tree, and its content is two objects, move element and move first; move element stores the content of a; move first stores the content of b.

[0066] The setting of the grammar container pool is the same as that of the grammar tree file. It is first made into a standardized storage, and then customized and modified according to the needs to meet the information storage needs of the grammar tree. The grammar container pool module involved is set in the above-mentioned parsing module.

[0067] In some preferred implementations, in step S300, the conversion code includes:

[0068] S301, obtaining an abstract syntax tree formed after being processed by the parser.

[0069] In this step, the syntax tree generated in step S200 is obtained to facilitate subsequent processing.

[0070] S302: traverse the abstract syntax tree to obtain level information of the syntax tree.

[0071] In this step, information of each level on the syntax tree is further obtained based on the obtained syntax tree.

[0072] S303: Acquire grammatical rules and node information in the hierarchical information and perform matching.

[0073] In this step, the acquired language information is matched with grammatical rules.

[0074] S304, edit the obtained language information and grammar information, and convert them into an Eclipsejdt abstract syntax tree.

[0075] In this step, conversion is performed based on the language information and grammar information, specifically, conversion into an Eclipsejdt abstract syntax tree.

[0076] S305, calling the Eclipsejdt code generation method, and generating converted java source code according to the Eclipsejdt abstract syntax tree.

[0077] In this step, Java code is generated according to the Eclipsejdt code generation method.

[0078] In S300, various syntaxes of the original code are mapped to corresponding converters through the core conversion API to interpret and convert the code.

[0079] The final generated code needs to be shaped, that is, the processing in S400. Specifically, the java code calls the shaping method of eclipseJdt, and the sql part calls the shaping method of sql-formatter.

[0080] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.

Claims

1. A code conversion method, characterized in that: include: Process the original code to make it conform to the subsequent parsing specifications; Analyze the original code to obtain the information intelligence of the original code; Convert the code, convert the original code through a code conversion tool according to the obtained original code information, and output a new code.

2. The code conversion method according to claim 1, characterized in that: Also includes: The new code is shaped and outputted.

3. The code conversion method according to claim 1 or 2, characterized in that: The processing source code also includes: Replace the referenced asset content in the original code with the actual asset content; Replace the non-standard characters in the original code with standard characters; Format the code according to the preset code format.

4. The code conversion method according to claim 1 or 2, characterized in that: The parsing of the original code includes: parsing the original code by artificial intelligence, or parsing the original code by syntax tree.

5. The code conversion method according to claim 4, characterized in that: include: Parse the original code through the parser and convert it into an abstract syntax tree; Decomposing the abstract syntax tree hierarchically; The information of each layer of the abstract syntax tree is structured and stored in a syntax container pool.

6. The code conversion method according to claim 5, characterized in that: The conversion code includes: Obtaining an abstract syntax tree formed after being processed by the parser; Traversing the abstract syntax tree to obtain the level information of the syntax tree; Obtaining grammatical rules and node information in the hierarchical information and performing matching; Edit the obtained language information and grammar information and convert them into Eclipsejdt abstract syntax tree; The Eclipsejdt code generation method is called, and the converted java source code is generated according to the Eclipsejdt abstract syntax tree.

7. A code converter, characterized in that include: The preprocessing module is used to preprocess the original code so that the original code meets the subsequent parsing specifications; The parsing module is used to parse the original code to obtain information intelligence of the original code; The conversion module converts the original code through a code conversion tool according to the acquired original code information and outputs a new code.

8. The conversion method according to claim 7, characterized in that: Also includes: The code shaping module is used to shape the obtained new code and convert it into a code that meets the standards of the new technology framework.