CN112328257A - Code conversion method and device - Google Patents

Code conversion method and device Download PDF

Info

Publication number
CN112328257A
CN112328257A CN202011330852.9A CN202011330852A CN112328257A CN 112328257 A CN112328257 A CN 112328257A CN 202011330852 A CN202011330852 A CN 202011330852A CN 112328257 A CN112328257 A CN 112328257A
Authority
CN
China
Prior art keywords
syntax tree
egl
java
nodes
node
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011330852.9A
Other languages
Chinese (zh)
Inventor
黄贵敏
李英灯
祁有盛
潘丹铃
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202011330852.9A priority Critical patent/CN112328257A/en
Publication of CN112328257A publication Critical patent/CN112328257A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention provides a code conversion method and a code conversion device, and relates to the technical field of artificial intelligence. The code conversion method comprises the following steps: obtaining a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; generating JAVA source code text based on the JAVA abstract syntax tree. The invention can support the migration and the upgrade of a large-scale data system, and saves a large amount of labor cost investment.

Description

Code conversion method and device
Technical Field
The invention relates to the technical field of artificial intelligence, in particular to a code conversion method and a code conversion device.
Background
With the rapid development of the IT industry, the leading-edge technology in the industry is continuously updated, and the distributed system with the characteristics of high fault tolerance, elastic expansion, resource sharing, flexible configuration, rapid calculation and the like is different from military projects and is widely applied to various fields of the internet. The traditional large-scale host system deployed in a centralized manner faces the situation that the system needs to be rapidly operated, maintained, upgraded and updated, and gradually exits from the historical stage. In the transformation and upgrade of the traditional large-scale host system, because the system framework and the technical components are different from the programming language used by the mainstream distributed architecture, the code rewriting is inevitably required in the transformation process, namely, the two programming languages are mutually converted. In the aspect of code conversion, the conversion of the programming language is completed manually, a large amount of manpower is consumed, the development efficiency is low, and various problems of high complexity, poor readability, high possibility of errors and the like exist, so that the stability of the system is influenced.
Most of the existing code conversion tools in the industry are direct and rough conversion based on source codes, the conversion efficiency is poor, the conversion accuracy is low, and meanwhile, the conversion cannot be flexibly configured and flexibly expanded. The abstract syntax tree converted from the programming language is mainly used for simple program path management, such as branch path search, unit test case generation, coding specification scanning and the like, and the mutual conversion based on the syntax tree between the two languages is seldom involved.
Therefore, an efficient code conversion method based on a syntax tree is urgently needed to meet the requirement of migration and upgrading of a large data system.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides a code conversion method and a code conversion device, which can save a large amount of manual coding investment and realize the rapid conversion and upgrade of a large host system.
In order to solve the technical problems, the invention provides the following technical scheme:
in a first aspect, the present invention provides a transcoding method, comprising:
obtaining a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree;
traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA;
generating JAVA source code text based on the JAVA abstract syntax tree.
Wherein, the converting the target EGL source code text into the abstract syntax tree of the EGL comprises:
dividing a target EGL source code text into a code block set consisting of code blocks; wherein each code block comprises a subset of code lines formed by a plurality of lines of code;
traversing the code block set to convert the code blocks in the code block set into a first syntax tree node set consisting of nodes;
traversing the code block to convert a subset of lines of code in the code block into a second set of syntax tree nodes comprised of nodes;
wherein the first set of syntax tree nodes and the second set of syntax tree nodes form an abstract syntax tree for the EGL.
Wherein, the traversing the abstract syntax tree of the EGL to obtain the abstract syntax tree of JAVA comprises:
gradually converting each type of node on the EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node;
and constructing the JAVA abstract syntax tree according to the JAVA syntax tree nodes.
Further, before the step-by-step converting each type of node on the abstract syntax tree of the EGL into a semantically equivalent JAVA syntax tree node, the method further includes:
preprocessing the abstract syntax tree of the EGL;
correspondingly, the step-by-step conversion of each type of node on the abstract syntax tree of the EGL into a semantically equivalent JAVA syntax tree node includes:
and gradually converting each type of node on the preprocessed EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node.
Wherein, the step-by-step conversion of each type of node on the abstract syntax tree of the EGL into semantically equivalent JAVA syntax tree nodes comprises:
gradually converting Record nodes on the abstract syntax tree of the EGL and DataItem nodes below the Record nodes into semantically equivalent first target JAVA syntax tree nodes;
gradually converting the TopLevelFunction type common function nodes of the non-program entry on the abstract syntax tree of the EGL into semantically equivalent second target JAVA syntax tree nodes;
gradually converting Program type main Program nodes of a Program entry on the abstract syntax tree of the EGL into third target JAVA syntax tree nodes with semantic equivalence;
wherein the first target JAVA syntax tree node, the second target JAVA syntax tree node and the third target JAVA syntax tree node constitute JAVA syntax tree nodes.
In a second aspect, the present invention provides a transcoding apparatus, comprising:
the device comprises an acquisition unit, a transformation unit and a transformation unit, wherein the acquisition unit is used for acquiring a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree;
the conversion unit is used for performing traversal processing on the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA;
and the generating unit is used for generating the JAVA source code text based on the JAVA abstract syntax tree.
Wherein the acquisition unit includes:
the dividing subunit is used for dividing the target EGL source code text into a code block set consisting of code blocks; wherein each code block comprises a subset of code lines formed by a plurality of lines of code;
the first traversal subunit is used for traversing the code block set to convert the code blocks in the code block set into a first syntax tree node set formed by nodes;
a second traversal subunit, configured to traverse the code block to convert the subset of code lines in the code block into a second set of syntax tree nodes composed of nodes;
wherein the first set of syntax tree nodes and the second set of syntax tree nodes form an abstract syntax tree for the EGL.
Wherein the conversion unit includes:
the node subunit is used for converting each type of node on the abstract syntax tree of the EGL into a semantically equivalent JAVA syntax tree node step by step;
and the conversion subunit is used for forming the JAVA abstract syntax tree according to the JAVA syntax tree nodes.
Further, the method also comprises the following steps:
the preprocessing subunit is used for preprocessing the abstract syntax tree of the EGL;
correspondingly, the node subunit includes:
and the node module is used for converting each type of node on the preprocessed EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node step by step.
Wherein the node subunit includes:
the first conversion module is used for converting Record nodes on the EGL abstract syntax tree and DataItem nodes below the Record nodes into semantically equivalent first target JAVA syntax tree nodes step by step;
the second conversion module is used for converting the TopLevelFunction type public function nodes of the non-program entry on the abstract syntax tree of the EGL into semantically equivalent second target JAVA syntax tree nodes step by step;
the third conversion module is used for converting Program type main Program nodes of a Program entry on the abstract syntax tree of the EGL into semantically equivalent third target JAVA syntax tree nodes step by step;
wherein the first target JAVA syntax tree node, the second target JAVA syntax tree node and the third target JAVA syntax tree node constitute JAVA syntax tree nodes.
In a third aspect, the present invention provides an electronic device, comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the transcoding method when executing the program.
In a fourth aspect, the invention provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the transcoding method described.
According to the technical scheme, the invention provides a code conversion method and a code conversion device, which are characterized in that a target EGL source code text is obtained and converted into an EGL abstract syntax tree; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; the JAVA source code text is generated based on the JAVA abstract syntax tree, so that the migration and the upgrade of a large-scale data system can be supported, and a large amount of labor cost investment is saved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a flowchart illustrating a transcoding method according to an embodiment of the present invention.
Fig. 2 is a flowchart illustrating a step S101 in the transcoding method according to the embodiment of the present invention.
Fig. 3 is a schematic flowchart of the first procedure of step S102 in the transcoding method according to the embodiment of the present invention.
Fig. 4 is a schematic diagram of a second process of step S102 in the transcoding method according to the embodiment of the present invention.
Fig. 5 is a schematic structural diagram of a transcoding system in an embodiment of the present invention.
Fig. 6 is a schematic structural diagram of a transcoding device in an embodiment of the present invention.
Fig. 7 is a schematic structural diagram of an electronic device in an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The method aims to solve the problems of large investment of labor, time and codes in transformation and upgrading of a large-scale data system. The invention aims at EGL business programming language developed by IBM, and English is named as: enterprise Generation Language provides an EGL code conversion method based on syntax trees, and realizes the automatic code conversion process of 'EGL source code- > EGL syntax tree- > JAVA source code'.
The present invention provides an embodiment of a transcoding method, and referring to fig. 1, the transcoding method specifically includes the following contents:
s101: obtaining a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree;
the method comprises the step of analyzing an EGL syntax tree based on an EGL source code, and specifically, converting an EGL source code text into a corresponding abstract syntax tree according to an open source software package (com.ibm.etools.edt.core) provided by IBM official.
It should be noted that, like most programming languages, the EGL language official maintenance party provides an open source software package for interconversion between the source code and the Abstract Syntax Tree (AST) structure, and the conversion of the EGL source code into the syntax tree can be realized by means of the com.
It is understood that Abstract Syntax Trees (AST) are structured objects that a computer can traverse and process quickly.
S102: traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA;
the purpose of this step is to convert the EGL syntax tree into a JAVA syntax tree, traverse each node in the EGL abstract syntax tree step by step on the basis of the EGL abstract syntax tree obtained in step S101, and convert the EGL abstract syntax tree nodes into JAVA syntax tree nodes one by one with the JAVA syntax tree as a guide under the premise of keeping semantic equivalence of each node, thereby obtaining a new JAVA abstract syntax tree.
S103: generating JAVA source code text based on the JAVA abstract syntax tree.
The present step is to generate a JAVA source code based on the JAVA syntax tree section. In specific implementation, based on the JAVA abstract syntax tree obtained in step S102, an open source software package (org.
As can be seen from the above description, in the code conversion method provided in the embodiment of the present invention, the target EGL source code text is obtained and converted into the abstract syntax tree of EGL; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; and generating a JAVA source code text based on the JAVA abstract syntax tree, and focusing on the difference adjustment and service branch test coverage of a code service processing flow on the basis of the JAVA source code, so that the transformation and upgrading of the large-scale data system can be completed, a large amount of manual coding investment is saved, and the rapid transformation and upgrading of the large-scale data system is realized.
In an embodiment of the present invention, referring to fig. 2, step S101 in the transcoding method specifically includes the following contents:
s1011: dividing a target EGL source code text into a code block set consisting of code blocks; wherein each code block comprises a subset of code lines formed by a plurality of lines of code;
in this step, the target EGL source code text is converted into a set of unordered code blocks (EGL-PART), i.e., a set of code blocks. Each code block (EGL-PART) in turn contains a series of different types of subsets of code lines.
S1012: traversing the code block set to convert the code blocks in the code block set into a first syntax tree node set consisting of nodes;
in this step, the unordered set of code blocks is traversed, and the unordered set of code blocks is converted into the ordered set of first syntax tree nodes according to the path of the EGL source code.
It is understood that each syntax tree node is an EGL-PART code block. Such as DataItem, Record, TopLevelfunction, etc.
S1013: traversing the code block to convert a subset of lines of code in the code block into a second set of syntax tree nodes comprised of nodes;
wherein the first set of syntax tree nodes and the second set of syntax tree nodes form an abstract syntax tree for the EGL.
In this step, the code line subsets in each code block are recursively traversed, and the code line subsets are converted into an ordered second syntax tree node set according to the path of the EGL source code.
It will be appreciated that each syntax tree node is a subset of lines of code.
From the above description, the present embodiment can convert the EGL source code text into the abstract syntax tree of the EGL, avoid the problem of code line conversion omission, improve the integrity of the code, and enhance the readability of the code.
In an embodiment of the present invention, referring to fig. 3, step S102 in the transcoding method specifically includes the following contents:
s1021: gradually converting each type of node on the EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node;
s1022: and constructing the JAVA abstract syntax tree according to the JAVA syntax tree nodes.
In this embodiment, the step-by-step converting each type of node on the abstract syntax tree of the EGL into a semantically equivalent JAVA syntax tree node includes:
1. gradually converting Record nodes on the abstract syntax tree of the EGL and DataItem nodes below the Record nodes into semantically equivalent first target JAVA syntax tree nodes;
2. gradually converting the TopLevelFunction type common function nodes of the non-program entry on the abstract syntax tree of the EGL into semantically equivalent second target JAVA syntax tree nodes;
3. gradually converting Program type main Program nodes of a Program entry on the abstract syntax tree of the EGL into third target JAVA syntax tree nodes with semantic equivalence;
and after the main program conversion is started, circularly judging the type of the EGL syntax tree node, and if the type of the EGL syntax tree node is the SQLNode type, performing the SQLNode node conversion. If the type of the ConditionNode is the ConditionNode type, the ConditionNode node conversion is performed. And if the type of the functional node is the functional node type, performing functional node conversion. If the type is the Expression type, the Expression node conversion is carried out. If the type is the function InvocationNode type, the conversion of the function InvocationNode is carried out. If the type is the assignmentNode type, the assignmentNode node conversion is carried out. If the ExitNode type is the ExitNode type, the ExitNode node conversion is carried out until no data exits.
In addition, for public class library methods and variables quoted by the EGL codes, the public class library methods and variables are converted into a JAVA class library API with equivalent semantics and added into a JAVA operation class library for operation and quote after being converted into JAVA codes. The detailed class library method and variables include: SysLib, DateTimeLib, MathLib, VGLib, StrLib, SysVar, VGVar.
Wherein the first target JAVA syntax tree node, the second target JAVA syntax tree node and the third target JAVA syntax tree node constitute JAVA syntax tree nodes.
It should be noted that the list of semantic equivalent transformations of the EGL syntax tree nodes is shown in the attached table 1.
Because of the difference in grammar between the two languages, deep mining is required, and semantic equivalence conversion rules are customized to complete the mutual conversion between the two languages. Based on the abstract syntax tree, the one-to-one mapping relation between the sentences of different types of the two languages can be quickly found, a modularized conversion model is established, and efficient conversion between the sentences is realized.
As can be seen from the above description, the equivalent transformation based on the syntax tree node provided in this embodiment maintains the original program computational logic unchanged to the greatest extent after the code transformation, and has strong extensibility, and the transformation between various languages is applicable.
In an embodiment of the present invention, referring to fig. 4, step S102 in the transcoding method further includes the following steps:
s1020: preprocessing the abstract syntax tree of the EGL;
correspondingly, step S1021 further includes:
s10211: and gradually converting each type of node on the preprocessed EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node.
In this embodiment, the EGL syntax tree node preprocessing is performed on some dependency information before the EGL syntax tree conversion. Such as a DataItem node, a Record node, a TopLevelFunction node, etc., the subsequent syntax tree conversion process needs to acquire the information, and supplement and perfect the syntax tree nodes.
The specific pretreatment process comprises the following steps:
after preprocessing is started, the type of the EGL syntax tree node is judged circularly:
if the syntax tree is of the DataItem type, all DataItem type nodes of the EGL syntax tree are converted into semantically equivalent JAVA syntax tree nodes, and the semantically equivalent JAVA syntax tree nodes are stored in a common context environment for being used by subsequent syntax tree conversion.
If the syntax tree is of Record type, all Record type nodes of the EGL syntax tree are converted into semantically equivalent JAVA syntax tree nodes, and the semantically equivalent JAVA syntax tree nodes are stored in a common context environment for being used by subsequent syntax tree conversion.
If the syntax tree is of a TopLevelFunction type, all TopLevelFunction type nodes of the EGL syntax tree are converted into semantically equivalent JAVA syntax tree nodes, and the semantically equivalent JAVA syntax tree nodes are stored in a public context environment for being used by subsequent syntax tree conversion.
The semantic equivalence conversion list of the main nodes of the EGL syntax tree is shown in an attached table 1.
As can be seen from the above description, the equivalent transformation based on the syntax tree node provided in this embodiment maintains the original program computational logic unchanged to the greatest extent after the code transformation, and has strong extensibility, and the transformation between various languages is applicable.
In an embodiment of the present invention, referring to fig. 5, the present invention provides a transcoding system, comprising:
the EGL Source code to EGL syntax tree conversion device 1(EGL-Translator) is responsible for converting the EGL Source code (EGL Source File) of the pure text into an abstract syntax tree structure (EGL-AST) which can be traversed and processed quickly by a computer, and obtaining an EGL syntax tree structure unit 2.
EGL syntax tree structure unit 2(EGL-AST) is a data structure that fully represents EGL source code semantics in a tree structure implemented by means of the com.
The EGL syntax tree to JAVA syntax tree device 3(EGL-Tava) is responsible for traversing the syntax tree structure of the EGL syntax tree structure unit 2, taking the target JAVA syntax tree as a guide, and converting each node on the EGL syntax tree into JAVA syntax tree nodes with equal semantics on the premise of node semantic equivalence, thereby obtaining a new JAVA syntax tree.
A JAVA syntax tree structure unit 4(JAVA-AST) is a data structure that completely represents the semantics of JAVA source code in a tree structure, implemented by means of the org.
The JAVA syntax tree To JAVA Source code device 5(JDT-To-Source) is responsible for converting the syntax tree structure of the AVA syntax tree structure unit 4 into JAVA Source code (JAVA Source File), and the Source code text of the corresponding syntax tree can be obtained by means of the toString method provided by eclipse.
The code conversion system provided by the embodiment of the invention can support the rapid conversion of a large-scale system, and a user only needs to pay attention to the difference adjustment and the service branch test coverage of the service processing flow after transcoding, so that a large amount of labor cost investment is saved.
An embodiment of the present invention provides a specific implementation manner of a transcoding device capable of implementing all contents in the transcoding method, and referring to fig. 6, the transcoding device specifically includes the following contents:
the acquiring unit 10 is configured to acquire a target EGL source code text and convert the target EGL source code text into an abstract syntax tree of EGL;
the conversion unit 20 is configured to perform traversal processing on the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA;
a generating unit 30, configured to generate a JAVA source code text based on the JAVA abstract syntax tree.
Wherein the acquiring unit 10 includes:
the dividing subunit is used for dividing the target EGL source code text into a code block set consisting of code blocks; wherein each code block comprises a subset of code lines formed by a plurality of lines of code;
the first traversal subunit is used for traversing the code block set to convert the code blocks in the code block set into a first syntax tree node set formed by nodes;
a second traversal subunit, configured to traverse the code block to convert the subset of code lines in the code block into a second set of syntax tree nodes composed of nodes;
wherein the first set of syntax tree nodes and the second set of syntax tree nodes form an abstract syntax tree for the EGL.
Wherein the conversion unit 20 includes:
the node subunit is used for converting each type of node on the abstract syntax tree of the EGL into a semantically equivalent JAVA syntax tree node step by step;
and the conversion subunit is used for forming the JAVA abstract syntax tree according to the JAVA syntax tree nodes.
Further, the method also comprises the following steps:
the preprocessing subunit is used for preprocessing the abstract syntax tree of the EGL;
correspondingly, the node subunit includes:
and the node module is used for converting each type of node on the preprocessed EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node step by step.
Wherein the node subunit includes:
the first conversion module is used for converting Record nodes on the EGL abstract syntax tree and DataItem nodes below the Record nodes into semantically equivalent first target JAVA syntax tree nodes step by step;
the second conversion module is used for converting the TopLevelFunction type public function nodes of the non-program entry on the abstract syntax tree of the EGL into semantically equivalent second target JAVA syntax tree nodes step by step;
the third conversion module is used for converting Program type main Program nodes of a Program entry on the abstract syntax tree of the EGL into semantically equivalent third target JAVA syntax tree nodes step by step;
wherein the first target JAVA syntax tree node, the second target JAVA syntax tree node and the third target JAVA syntax tree node constitute JAVA syntax tree nodes.
The embodiment of the code conversion apparatus provided in the present invention may be specifically configured to execute the processing flow of the embodiment of the code conversion method in the foregoing embodiment, and the functions of the embodiment are not described herein again, and refer to the detailed description of the embodiment of the method.
As can be seen from the above description, the code conversion apparatus provided in the embodiment of the present invention converts the target EGL source code text into the abstract syntax tree of the EGL by obtaining the target EGL source code text; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; the JAVA source code text is generated based on the JAVA abstract syntax tree, so that the migration and the upgrade of a large-scale data system can be supported, and a large amount of labor cost investment is saved.
The present application provides an embodiment of an electronic device for implementing all or part of contents in the transcoding method, where the electronic device specifically includes the following contents:
a processor (processor), a memory (memory), a communication Interface (Communications Interface), and a bus; the processor, the memory and the communication interface complete mutual communication through the bus; the communication interface is used for realizing information transmission between related devices; the electronic device may be a desktop computer, a tablet computer, a mobile terminal, and the like, but the embodiment is not limited thereto. In this embodiment, the electronic device may be implemented with reference to the embodiment for implementing the code conversion method and the embodiment for implementing the code conversion apparatus in the embodiments, and the contents thereof are incorporated herein, and repeated details are not repeated.
Fig. 7 is a schematic block diagram of a system configuration of an electronic device 9600 according to an embodiment of the present application. As shown in fig. 7, the electronic device 9600 can include a central processor 9100 and a memory 9140; the memory 9140 is coupled to the central processor 9100. Notably, this fig. 7 is exemplary; other types of structures may also be used in addition to or in place of the structure to implement telecommunications or other functions.
In one embodiment, the transcoding functionality may be integrated into the central processor 9100. The central processor 9100 may be configured to control as follows:
obtaining a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; generating JAVA source code text based on the JAVA abstract syntax tree.
As can be seen from the above description, the electronic device provided in the embodiments of the present application obtains the target EGL source code text and converts the target EGL source code text into the abstract syntax tree of EGL; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; the JAVA source code text is generated based on the JAVA abstract syntax tree, so that the migration and the upgrade of a large-scale data system can be supported, and a large amount of labor cost investment is saved.
In another embodiment, the code conversion apparatus may be configured separately from the central processor 9100, for example, the code conversion apparatus may be configured as a chip connected to the central processor 9100, and the code conversion function is realized by the control of the central processor.
As shown in fig. 7, the electronic device 9600 may further include: a communication module 9110, an input unit 9120, an audio processor 9130, a display 9160, and a power supply 9170. It is noted that the electronic device 9600 also does not necessarily include all of the components shown in fig. 7; further, the electronic device 9600 may further include components not shown in fig. 7, which may be referred to in the art.
As shown in fig. 7, a central processor 9100, sometimes referred to as a controller or operational control, can include a microprocessor or other processor device and/or logic device, which central processor 9100 receives input and controls the operation of the various components of the electronic device 9600.
The memory 9140 can be, for example, one or more of a buffer, a flash memory, a hard drive, a removable media, a volatile memory, a non-volatile memory, or other suitable device. The information relating to the failure may be stored, and a program for executing the information may be stored. And the central processing unit 9100 can execute the program stored in the memory 9140 to realize information storage or processing, or the like.
The input unit 9120 provides input to the central processor 9100. The input unit 9120 is, for example, a key or a touch input device. Power supply 9170 is used to provide power to electronic device 9600. The display 9160 is used for displaying display objects such as images and characters. The display may be, for example, an LCD display, but is not limited thereto.
The memory 9140 can be a solid state memory, e.g., Read Only Memory (ROM), Random Access Memory (RAM), a SIM card, or the like. There may also be a memory that holds information even when power is off, can be selectively erased, and is provided with more data, an example of which is sometimes called an EPROM or the like. The memory 9140 could also be some other type of device. Memory 9140 includes a buffer memory 9141 (sometimes referred to as a buffer). The memory 9140 may include an application/function storage portion 9142, the application/function storage portion 9142 being used for storing application programs and function programs or for executing a flow of operations of the electronic device 9600 by the central processor 9100.
The memory 9140 can also include a data store 9143, the data store 9143 being used to store data, such as contacts, digital data, pictures, sounds, and/or any other data used by an electronic device. The driver storage portion 9144 of the memory 9140 may include various drivers for the electronic device for communication functions and/or for performing other functions of the electronic device (e.g., messaging applications, contact book applications, etc.).
The communication module 9110 is a transmitter/receiver 9110 that transmits and receives signals via an antenna 9111. The communication module (transmitter/receiver) 9110 is coupled to the central processor 9100 to provide input signals and receive output signals, which may be the same as in the case of a conventional mobile communication terminal.
Based on different communication technologies, a plurality of communication modules 9110, such as a cellular network module, a bluetooth module, and/or a wireless local area network module, may be provided in the same electronic device. The communication module (transmitter/receiver) 9110 is also coupled to a speaker 9131 and a microphone 9132 via an audio processor 9130 to provide audio output via the speaker 9131 and receive audio input from the microphone 9132, thereby implementing ordinary telecommunications functions. The audio processor 9130 may include any suitable buffers, decoders, amplifiers and so forth. In addition, the audio processor 9130 is also coupled to the central processor 9100, thereby enabling recording locally through the microphone 9132 and enabling locally stored sounds to be played through the speaker 9131.
An embodiment of the present invention further provides a computer-readable storage medium capable of implementing all the steps in the transcoding method in the above embodiment, where the computer-readable storage medium stores thereon a computer program, and when the computer program is executed by a processor, the computer program implements all the steps in the transcoding method in the above embodiment, for example, when the processor executes the computer program, the processor implements the following steps:
obtaining a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; generating JAVA source code text based on the JAVA abstract syntax tree.
As can be seen from the above description, the computer-readable storage medium provided in the embodiment of the present invention converts a target EGL source code text into an abstract syntax tree of EGL by obtaining the target EGL source code text; traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA; the JAVA source code text is generated based on the JAVA abstract syntax tree, so that the migration and the upgrade of a large-scale data system can be supported, and a large amount of labor cost investment is saved.
It should be noted that the nodes of the EGL syntax tree involved in the above embodiments include the nodes shown in attached table 1.
Attached table 1 EGL syntax tree node list table
Figure BDA0002795770300000131
Figure BDA0002795770300000141
Figure BDA0002795770300000151
Figure BDA0002795770300000161
Figure BDA0002795770300000171
Figure BDA0002795770300000181
Figure BDA0002795770300000191
Figure BDA0002795770300000201
Although the present invention provides method steps as described in the examples or flowcharts, more or fewer steps may be included based on routine or non-inventive labor. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. When an actual apparatus or client product executes, it may execute sequentially or in parallel (e.g., in the context of parallel processors or multi-threaded processing) according to the embodiments or methods shown in the figures.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. It should be noted that the embodiments and features of the embodiments may be combined with each other without conflict. The present invention is not limited to any single aspect, nor is it limited to any single embodiment, nor is it limited to any combination and/or permutation of these aspects and/or embodiments. Moreover, each aspect and/or embodiment of the present invention may be utilized alone or in combination with one or more other aspects and/or embodiments thereof.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the present invention, and they should be construed as being included in the following claims and description.

Claims (12)

1. A method of transcoding, comprising:
obtaining a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree;
traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA;
generating JAVA source code text based on the JAVA abstract syntax tree.
2. The method of transcoding of claim 1, wherein converting the target EGL source code text into an abstract syntax tree for EGL comprises:
dividing a target EGL source code text into a code block set consisting of code blocks; wherein each code block comprises a subset of code lines formed by a plurality of lines of code;
traversing the code block set to convert the code blocks in the code block set into a first syntax tree node set consisting of nodes;
traversing the code block to convert a subset of lines of code in the code block into a second set of syntax tree nodes comprised of nodes;
wherein the first set of syntax tree nodes and the second set of syntax tree nodes form an abstract syntax tree for the EGL.
3. The transcoding method of claim 1, wherein traversing the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA comprises:
gradually converting each type of node on the EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node;
and constructing the JAVA abstract syntax tree according to the JAVA syntax tree nodes.
4. The transcoding method of claim 3, further comprising, prior to said step-wise converting each type of node on the abstract syntax tree of the EGL into semantically equivalent JAVA syntax tree nodes:
preprocessing the abstract syntax tree of the EGL;
correspondingly, the step-by-step conversion of each type of node on the abstract syntax tree of the EGL into a semantically equivalent JAVA syntax tree node includes:
and gradually converting each type of node on the preprocessed EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node.
5. The transcoding method of claim 3, wherein said step-wise converting each type of node on the abstract syntax tree of the EGL into semantically equivalent JAVA syntax tree nodes comprises:
gradually converting Record nodes on the abstract syntax tree of the EGL and DataItem nodes below the Record nodes into semantically equivalent first target JAVA syntax tree nodes;
gradually converting the TopLevelFunction type common function nodes of the non-program entry on the abstract syntax tree of the EGL into semantically equivalent second target JAVA syntax tree nodes;
gradually converting Program type main Program nodes of a Program entry on the abstract syntax tree of the EGL into third target JAVA syntax tree nodes with semantic equivalence;
wherein the first target JAVA syntax tree node, the second target JAVA syntax tree node and the third target JAVA syntax tree node constitute JAVA syntax tree nodes.
6. A transcoding apparatus, comprising:
the device comprises an acquisition unit, a transformation unit and a transformation unit, wherein the acquisition unit is used for acquiring a target EGL source code text and converting the target EGL source code text into an EGL abstract syntax tree;
the conversion unit is used for performing traversal processing on the abstract syntax tree of the EGL to obtain an abstract syntax tree of JAVA;
and the generating unit is used for generating the JAVA source code text based on the JAVA abstract syntax tree.
7. The transcoding apparatus of claim 6, wherein the obtaining unit comprises:
the dividing subunit is used for dividing the target EGL source code text into a code block set consisting of code blocks; wherein each code block comprises a subset of code lines formed by a plurality of lines of code;
the first traversal subunit is used for traversing the code block set to convert the code blocks in the code block set into a first syntax tree node set formed by nodes;
a second traversal subunit, configured to traverse the code block to convert the subset of code lines in the code block into a second set of syntax tree nodes composed of nodes;
wherein the first set of syntax tree nodes and the second set of syntax tree nodes form an abstract syntax tree for the EGL.
8. The transcoding apparatus of claim 6, wherein the converting unit comprises:
the node subunit is used for converting each type of node on the abstract syntax tree of the EGL into a semantically equivalent JAVA syntax tree node step by step;
and the conversion subunit is used for forming the JAVA abstract syntax tree according to the JAVA syntax tree nodes.
9. The transcoding device of claim 8, further comprising:
the preprocessing subunit is used for preprocessing the abstract syntax tree of the EGL;
correspondingly, the node subunit includes:
and the node module is used for converting each type of node on the preprocessed EGL abstract syntax tree into a semantically equivalent JAVA syntax tree node step by step.
10. The transcoding device of claim 8, wherein the node subunit comprises:
the first conversion module is used for converting Record nodes on the EGL abstract syntax tree and DataItem nodes below the Record nodes into semantically equivalent first target JAVA syntax tree nodes step by step;
the second conversion module is used for converting the TopLevelFunction type public function nodes of the non-program entry on the abstract syntax tree of the EGL into semantically equivalent second target JAVA syntax tree nodes step by step;
the third conversion module is used for converting Program type main Program nodes of a Program entry on the abstract syntax tree of the EGL into semantically equivalent third target JAVA syntax tree nodes step by step;
wherein the first target JAVA syntax tree node, the second target JAVA syntax tree node and the third target JAVA syntax tree node constitute JAVA syntax tree nodes.
11. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the transcoding method of any of claims 1 to 5 are implemented when the program is executed by the processor.
12. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the transcoding method of any one of claims 1 to 5.
CN202011330852.9A 2020-11-24 2020-11-24 Code conversion method and device Pending CN112328257A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011330852.9A CN112328257A (en) 2020-11-24 2020-11-24 Code conversion method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011330852.9A CN112328257A (en) 2020-11-24 2020-11-24 Code conversion method and device

Publications (1)

Publication Number Publication Date
CN112328257A true CN112328257A (en) 2021-02-05

Family

ID=74307822

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011330852.9A Pending CN112328257A (en) 2020-11-24 2020-11-24 Code conversion method and device

Country Status (1)

Country Link
CN (1) CN112328257A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113010182A (en) * 2021-03-25 2021-06-22 北京百度网讯科技有限公司 Method and device for generating upgrade file and electronic equipment
CN113778440A (en) * 2021-08-18 2021-12-10 上海瑞家信息技术有限公司 Data processing method and device, electronic equipment and storage medium
CN113805890A (en) * 2021-09-10 2021-12-17 中国银联股份有限公司 Method, device, terminal, system and storage medium for migrating applets across applications

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282444A1 (en) * 2013-03-15 2014-09-18 ArtinSoft Corporation Programming language transformations with abstract syntax tree extensions
CN108170435A (en) * 2018-01-16 2018-06-15 优视科技新加坡有限公司 A kind of source code conversion method, device and equipment
CN110471666A (en) * 2019-07-18 2019-11-19 五八有限公司 Code automatic switching method and device, code converter and medium
CN110543297A (en) * 2018-05-28 2019-12-06 北京京东尚科信息技术有限公司 method and apparatus for generating source code
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN110737466A (en) * 2019-10-16 2020-01-31 南京航空航天大学 Source code coding sequence representation method based on static program analysis
CN111209004A (en) * 2019-12-30 2020-05-29 北京健康之家科技有限公司 Code conversion method and device
CN111752571A (en) * 2020-06-29 2020-10-09 广州华多网络科技有限公司 Program upgrading method, device, equipment and storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282444A1 (en) * 2013-03-15 2014-09-18 ArtinSoft Corporation Programming language transformations with abstract syntax tree extensions
CN108170435A (en) * 2018-01-16 2018-06-15 优视科技新加坡有限公司 A kind of source code conversion method, device and equipment
CN110543297A (en) * 2018-05-28 2019-12-06 北京京东尚科信息技术有限公司 method and apparatus for generating source code
CN110471666A (en) * 2019-07-18 2019-11-19 五八有限公司 Code automatic switching method and device, code converter and medium
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN110737466A (en) * 2019-10-16 2020-01-31 南京航空航天大学 Source code coding sequence representation method based on static program analysis
CN111209004A (en) * 2019-12-30 2020-05-29 北京健康之家科技有限公司 Code conversion method and device
CN111752571A (en) * 2020-06-29 2020-10-09 广州华多网络科技有限公司 Program upgrading method, device, equipment and storage medium

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113010182A (en) * 2021-03-25 2021-06-22 北京百度网讯科技有限公司 Method and device for generating upgrade file and electronic equipment
CN113010182B (en) * 2021-03-25 2022-05-03 北京百度网讯科技有限公司 Method and device for generating upgrade file and electronic equipment
CN114816467A (en) * 2021-03-25 2022-07-29 北京百度网讯科技有限公司 Method and device for generating upgrade file and electronic equipment
CN114816467B (en) * 2021-03-25 2023-04-28 北京百度网讯科技有限公司 Upgrade file generation method and device and electronic equipment
CN113778440A (en) * 2021-08-18 2021-12-10 上海瑞家信息技术有限公司 Data processing method and device, electronic equipment and storage medium
CN113778440B (en) * 2021-08-18 2024-01-26 上海瑞家信息技术有限公司 Data processing method and device, electronic equipment and storage medium
CN113805890A (en) * 2021-09-10 2021-12-17 中国银联股份有限公司 Method, device, terminal, system and storage medium for migrating applets across applications

Similar Documents

Publication Publication Date Title
CN109933752B (en) Method and device for exporting electronic document
CN112328257A (en) Code conversion method and device
CN111736840B (en) Method for compiling applet application, method for running applet application, storage medium and electronic device
US8756407B2 (en) Configuration rule prototyping tool
CN112306884B (en) Program test control, execution method and corresponding device, equipment and medium thereof
US10318621B2 (en) Collating and intelligently sequencing installation documentation
CN110543301A (en) Method and device for generating jenkins code file
CN113110829B (en) Multi-UI component library data processing method and device
CN113010471A (en) File conversion method, file conversion device, storage medium and electronic equipment
CN113448852A (en) Test case obtaining method and device, electronic equipment and storage medium
CN113434123A (en) Service processing method and device and electronic equipment
CN112130830A (en) Interface generation method and device and electronic equipment
CN110221840B (en) Function implementation method and device of application program, equipment and storage medium
US7890548B2 (en) Automation process system and method to upgrade from non-unicode transformation support to unicode data transformation support
CN114968917A (en) Method and device for rapidly importing file data
CN111414232B (en) Virtual machine template data processing method and device
EP1832975A1 (en) Automatic generation of source program
US11797277B2 (en) Neural network model conversion method server, and storage medium
CN113535221A (en) Method and device for managing application version
CN112822190A (en) Message maintenance method and device
CN113448960A (en) Method and device for importing form file
CN113792531B (en) Text editing method and system based on markdown grammar expansion
CN111522548B (en) Project function expansion method, apparatus, electronic device and computer readable medium
CN112688863B (en) Gateway data processing method and device and electronic equipment
CN110908867B (en) Task completion judging method and device, storage medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination