CN110554875A - Code conversion method and device, electronic equipment and storage medium - Google Patents

Code conversion method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN110554875A
CN110554875A CN201810541370.4A CN201810541370A CN110554875A CN 110554875 A CN110554875 A CN 110554875A CN 201810541370 A CN201810541370 A CN 201810541370A CN 110554875 A CN110554875 A CN 110554875A
Authority
CN
China
Prior art keywords
morpheme
source
morphemes
grammar
language
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.)
Granted
Application number
CN201810541370.4A
Other languages
Chinese (zh)
Other versions
CN110554875B (en
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.)
Beijing Sankuai Online Technology Co Ltd
Original Assignee
Beijing Sankuai Online Technology Co Ltd
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 Beijing Sankuai Online Technology Co Ltd filed Critical Beijing Sankuai Online Technology Co Ltd
Priority to CN201810541370.4A priority Critical patent/CN110554875B/en
Publication of CN110554875A publication Critical patent/CN110554875A/en
Application granted granted Critical
Publication of CN110554875B publication Critical patent/CN110554875B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Abstract

The disclosure provides a code conversion method and device, electronic equipment and a computer readable storage medium, and belongs to the technical field of computers. The method comprises the following steps: splitting a source code into a plurality of source morphemes, and determining the grammar type of each source morpheme; mapping each source morpheme into a morpheme of a target language through a preset morpheme table based on the grammar type of each source morpheme; and generating a code based on the target language according to the morphemes of the target language obtained by mapping each source morpheme. The method and the system can realize automatic code conversion, improve the efficiency of code conversion work in the development process of software or program products, reduce labor cost, reduce risks caused by human errors, and have better expandability and universality.

Description

Code conversion method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a code conversion method and apparatus, an electronic device, and a computer-readable storage medium.
Background
In the development process of software or program products, existing projects, templates, etc. often need to be transcoded to adapt to different application environments, interface different operating systems, etc.
most of the existing code conversion is based on manual conversion, a developer is relied on to understand the logic of a source code and manually rewrite the source code into a target code, a large amount of manpower is needed when the product scale is large, and the manual conversion of codes also faces risks of error modification, missing modification and the like caused by human errors, so that the development quality of the product is influenced.
It is to be noted that the information disclosed in the above background section is only for enhancement of understanding of the background of the present disclosure, and thus may include information that does not constitute prior art known to those of ordinary skill in the art.
Disclosure of Invention
An object of the present disclosure is to provide a transcoding method and apparatus, an electronic device, and a computer-readable storage medium, which overcome, at least to some extent, the problems of requiring a lot of manpower and being prone to errors in transcoding due to the limitations and disadvantages of the related art.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
According to an aspect of the present disclosure, there is provided a transcoding method including: splitting a source code into a plurality of source morphemes, and determining the grammar type of each source morpheme; mapping each source morpheme into a morpheme of a target language through a preset morpheme table based on the grammar type of each source morpheme; and generating a code based on the target language according to the morphemes of the target language obtained by mapping each source morpheme.
In an exemplary embodiment of the present disclosure, splitting source code into a plurality of source morphemes, and determining a grammar type for each of the source morphemes includes: performing structural analysis on the source code to generate an abstract syntax tree consisting of the source morphemes; and determining the grammar type of each source morpheme according to the node position of each source morpheme in the abstract grammar tree.
In an exemplary embodiment of the present disclosure, further comprising: acquiring grammar rules of a preset language and a morpheme set of the preset language, wherein the preset language at least comprises the language of the source code and the target language; obtaining a self-defined grammar rule and a self-defined morpheme set; and classifying the morpheme set of the preset language and the self-defined morpheme set according to the grammar rule of the preset language and the self-defined grammar rule to obtain the preset morpheme table.
in an exemplary embodiment of the present disclosure, mapping each of the source morphemes to a morpheme of a target language through a preset morpheme table based on a grammar type of each of the source morphemes includes: searching morphemes, which are the same as the grammar types of the source morphemes, in the target language in the preset morpheme table; and mapping each source morpheme into morphemes with the same grammar type.
In an exemplary embodiment of the present disclosure, mapping each of the source morphemes to a morpheme of a target language through a preset morpheme table based on a grammar type of each of the source morphemes includes: converting the abstract syntax tree into a general syntax tree according to the syntax type of each source morpheme; and mapping each node of the general syntax tree into the morpheme of the target language through the preset morpheme table.
in an exemplary embodiment of the present disclosure, the source morphemes include special morphemes that cannot be mapped to morphemes of the target language; the method further comprises the following steps: highlighting the special morpheme in the source code.
In an exemplary embodiment of the present disclosure, the language of the source code and the target language include a high-level programming language or an assembly language.
According to an aspect of the present disclosure, there is provided a transcoding apparatus including: the grammar analysis module is used for splitting a source code into a plurality of source morphemes and determining the grammar type of each source morpheme; the morpheme mapping module is used for mapping each source morpheme into the morpheme of the target language through a preset morpheme table according to the grammar type of each source morpheme; and the code generation module is used for generating a code based on the target language according to the morphemes of the target language obtained by mapping each source morpheme.
According to an aspect of the present disclosure, there is provided an electronic device including: a processor; and a memory for storing executable instructions of the processor; wherein the processor is configured to perform the method of any one of the above via execution of the executable instructions.
according to an aspect of the present disclosure, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method of any one of the above.
Exemplary embodiments of the present disclosure have the following advantageous effects:
In the method and the device, the source morpheme is split from the source code, the grammar type of the source morpheme is determined, and each source morpheme is mapped into the morpheme of the target language according to the preset morpheme table, so that the code of the target language is obtained, and the conversion from the source code to the target code is completed. On one hand, automatic code conversion can be realized based on the mapping relation between the morphemes of the source language and the target language in the preset morpheme table, so that the efficiency of code conversion work in the development process of software or program products is improved, the labor cost is reduced, and the risk caused by human errors is reduced. On the other hand, the method has better expandability, and the mutual conversion of codes among multiple languages can be supported by integrating the morpheme mapping relation of the multiple languages in the preset morpheme table, so that the universality is stronger.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and together with the description, serve to explain the principles of the disclosure. It is to be understood that the drawings in the following description are merely exemplary of the disclosure, and that other drawings may be derived from those drawings by one of ordinary skill in the art without the exercise of inventive faculty.
FIG. 1 illustrates a flow diagram of a method of transcoding in an exemplary embodiment of the present disclosure;
FIG. 2 illustrates a sub-flow diagram of a method of transcoding in an exemplary embodiment of the present disclosure;
FIG. 3 is a diagram illustrating a syntax type set relationship of source code and object code in an exemplary embodiment of the present disclosure;
Fig. 4 is a block diagram illustrating a structure of a transcoding apparatus in an exemplary embodiment of the present disclosure;
FIG. 5 illustrates an electronic device for implementing the above method in an exemplary embodiment of the present disclosure;
fig. 6 illustrates a computer-readable storage medium for implementing a method in an exemplary embodiment of the disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The described attributes, structures or characteristics may be combined in any suitable manner in one or more embodiments.
An exemplary embodiment of the present disclosure first provides a code conversion method for converting source code into object code, wherein the source code and the object code may be codes written by different high-level programming languages or assembly languages. Referring to fig. 1, the method may include the steps of:
step S11, the source code is split into a plurality of source morphemes, and the grammar type of each source morpheme is determined.
the source code, i.e. the code to be converted, is written in the source language. Morphemes are the smallest unit of language with complete meaning in a code, and include various function names, arguments, operators, and the like. The grammar type is a result of classifying the morphemes according to the grammar function embodied by the morphemes, and for example, the morphemes indicating addition operation are one grammar type, and the morphemes indicating selection conditions are one grammar type. Since each source morpheme expresses a specific grammatical function in the source code, its grammatical type can be determined.
To facilitate determining the grammatical function corresponding to each source morpheme in the source code, in an exemplary embodiment, step S11 may be implemented by: performing structural analysis on the source code to generate an abstract syntax tree consisting of all source morphemes; and determining the grammar type of each source morpheme according to the node position of each source morpheme in the abstract grammar tree. The abstract syntax tree is a tree representation of the abstract syntax structure of the source code. The method comprises the steps of performing structural analysis on statements such as variable definitions, condition judgment, circulation and functions of source codes, wherein the statements comprise structural relationship analysis among the statements and phrase structural analysis inside the statements, dividing all source morphemes into a plurality of associated nodes and levels according to grammatical and logical relations, and performing corresponding connection or identification to form an abstract syntax tree. The connection relation of each node in the abstract syntax tree directly reflects the syntax and logic relation of each node, so that the syntax function of each node is easy to determine according to the tree structure of each node, and further the syntax type corresponding to the source morpheme of each node can be determined.
and step S12, mapping each source morpheme into the morpheme of the target language through a preset morpheme table based on the grammar type of each source morpheme.
Wherein the target language is the language of the target code. The preset morpheme table is a table integrating the mapping relationship between morphemes of a source language and a target language based on grammar types, and in each grammar type, a specific morpheme of the source language and a specific morpheme of the target language express the same function, so that the mapping relationship can be formed, and each source morpheme can be replaced by a corresponding morpheme in the target language. For example, mapping a source morpheme representing an addition operation in the source code to a morpheme also representing an addition operation in the target language; and mapping the source morphemes which represent the selection conditions in the source codes to the morphemes which also represent the selection conditions in the target language, and the like.
it should be noted that the mapping relationship of the morphemes in the preset morpheme table is not limited to a specific source language and a specific target language, and the mapping relationship can be established between the morphemes of multiple languages, so that when code conversion is performed, different target languages can be selected according to actual requirements, and the morphemes of the source language are mapped to the morphemes of different target languages.
step S13, a code based on the target language is generated from the morphemes of the target language mapped by the source morphemes.
The code of the target language is the target code. After the morpheme mapping is completed, the morpheme after mapping can be subjected to word sequence or structure adjustment and the like according to the grammar rule of the target language so as to generate codes conforming to the expression habit of the target language. Under the condition that the grammar type of the source morpheme is determined through the abstract grammar tree, the morpheme mapped by each node can be reorganized according to the hierarchy structure of the abstract grammar tree to form a complete target code.
In the code conversion method, the source morphemes are split from the source codes, the grammar types of the source morphemes are determined, and each source morpheme is mapped into the morpheme of the target language according to the preset morpheme table, so that the codes of the target language are obtained, and the conversion from the source codes to the target codes is completed. On one hand, automatic code conversion can be realized based on the mapping relation between the morphemes of the source language and the target language in the preset morpheme table, so that the efficiency of code conversion work in the development process of software or program products is improved, the labor cost is reduced, and the risk caused by human errors is reduced. On the other hand, the method has better expandability, and the mutual conversion of codes among multiple languages can be supported by integrating the morpheme mapping relation of the multiple languages in the preset morpheme table, so that the universality is stronger.
In an exemplary embodiment, performing a structural analysis on the source code to generate an abstract syntax tree consisting of source tokens may include the steps of: performing lexical analysis on a source code, reading in character streams forming the source code, scanning one by one according to grammar rules, identifying source morphemes, and organizing the source morphemes into a meaningful source morpheme sequence; and carrying out syntactic analysis on the source word sequence, organizing the source words into a plurality of syntactic phrases, connecting the source words in the syntactic phrases through syntactic and logical relations to form syntactic subtrees, organizing the tree structure of the syntactic phrases according to the logical relations of the source codes, and combining the syntactic subtrees into an abstract syntactic tree.
In an exemplary embodiment, the preset morpheme table may be obtained through steps S21 to S23 in fig. 2: step S21, acquiring grammar rules of a preset language and a morpheme set of the preset language, wherein the preset language at least comprises a source code language and a target language; step S22, obtaining a self-defined grammar rule and a self-defined morpheme set; and step S23, classifying the morpheme set of the preset language and the self-defined morpheme set according to the grammar rule of the preset language and the self-defined grammar rule to obtain a preset morpheme table.
The predetermined language refers to all existing programming languages involved in software or program development, is not limited to a specific source or target language, and may include three or more languages. In addition, the method can also support the self-defined grammar rule and the morpheme set of the developer, and add new morphemes in the preset morpheme table according to the self-defined edition of the developer. When each morpheme is divided according to grammar rules in a grammar type, the morpheme is subdivided to the maximum degree by taking a grammar function embodied by the morpheme as a unit, particularly, some morpheme combinations can form a function with a larger range, and each morpheme in the morpheme combinations corresponds to a small function of subdivision, for example, in a sentence with selection conditions, some morphemes correspond to reasons, some morphemes correspond to results, and the morphemes are divided into the morphemes with the minimum functions. Of course, some minimum functions are also formed by fixed morpheme combinations, and the morpheme combinations can be recorded in the preset morpheme table as the minimum unit of division. Therefore, a preset morpheme table with the language type as a row and the grammar type as a column (or the language type as a column and the grammar type as a row) can be constructed.
It should be noted that the preset morpheme table is usually configured in the program background, and therefore, the preset morpheme table is not limited to specific expression forms, such as table styles, line and column partitions, as long as syntax type partitions and morpheme mapping relationships of different languages are reflected, and may even be expressed in other forms besides the table, such as text sequences, morpheme vectors, and the like, which is not particularly limited in this embodiment.
Based on the above-mentioned preset morpheme table, step S12 can be implemented by the following steps: searching morphemes, which have the same grammar types as the source morphemes, in the target language in a preset morpheme table; and mapping each source morpheme into morphemes with the same grammar type. Because the morphemes with the same grammar type express the same function, after the source morphemes of the source code are mapped into the morphemes with the same grammar type in the target language, the logical relations of operation, circulation, conditions, nesting and the like in the source code can be kept unchanged.
It should be added that the morphemes of different languages in the preset morpheme table in the same grammar type may not be in a one-to-one mapping relationship, for example, multiple morphemes of the target language may express the same meaning and be divided into the same grammar type in the preset morpheme table. In the mapping process, the problem of which morpheme the source morpheme is mapped to is solved by setting selection logic, such as setting different priorities in several morphemes with the same meaning, or randomly selecting. This embodiment is not particularly limited thereto.
In addition, different language codes can be directly mapped to the uniform reference code in the preset morpheme table, and indirect mapping is formed among the different language codes through the reference code. In an exemplary embodiment, mapping each source morpheme to a morpheme of a target language through a preset morpheme table based on a grammar type of each source morpheme may be implemented by: converting the abstract syntax tree into a general syntax tree according to the syntax type of each source morpheme; and mapping each node of the general syntax tree into the morpheme of the target language through a preset morpheme table. The general syntax tree is a syntax tree expressed by a reference code, the reference code usually covers all syntax types, semantic expression is intuitive, and for example, a pseudo code can be used as the reference code, and the general syntax tree written by the pseudo code can be used as an intermediate form to realize conversion from a source code to a target code. In some cases, the logical representation of the source code and the object code are significantly different, which is reflected in the organization and distribution of the nodes on the abstract syntax tree. The abstract syntax tree of the source code is firstly converted into the general syntax tree and then mapped into the morpheme of the target language, the original mapping process can be divided into two mappings, and the general syntax tree has better mapping performance on the source code and the target code, and the two mappings do not need to change the structure of the abstract syntax tree to a great extent, so the method is easier to realize.
In practice, the source code may contain portions that cannot be converted into target code, e.g., the source morphemes contain special morphemes that cannot be mapped to morphemes in the target language. The inability to map may be due to a number of reasons: the source code has errors in code writing, part of source morphemes cannot determine grammar types, and part of source morphemes cannot find mapping in the target language. Based on this, in an exemplary embodiment, special morphemes may be highlighted in the source code. Highlighting may include adding a background color to a particular morpheme, changing a color, changing a font, etc., to facilitate a developer in finding and determining a reason for unsuccessful transcoding and handling the same accordingly.
In particular, in an exemplary embodiment, the occurrence of a special morpheme cannot be mapped because the morpheme in the target language that is of the same syntax type as the special morpheme is null.
The grammar types contained in different languages may be different, and specifically, assuming that all sets of grammar types in the source language are a and all sets of grammar types in the target language are B, referring to fig. 3, the set a and the set B generally have the following relationships:
(1) B, the most ideal case is that the grammar type of the target language is completely coincident with that of the source language, in this case, the morpheme of the target code has a complete mapping relation with the morpheme of the source language, and the mutual conversion of the two codes is easily realized.
(2).Ideally, if the grammar type of the source language is a subset of the grammar type of the target language, then the source morphemes all have mapped morphemes in the target language, and the conversion from the source code to the target code can be realized.
(3).that is, the syntax type of the source language is not a subset of the syntax type of the target language, which is the case in the above embodiment, the mapping morpheme of a part of the source morpheme in the target language may be null, that is, the morpheme corresponding to the syntax type of the part of a- (a ∞ B), and the mapping cannot be realized in the target language.
For the above embodiment, when the morpheme in the target language that is the same as the syntax type of the special morpheme is a null value, the conversion may be completed through manual configuration by a developer, for example, a new morpheme is added to the target language in a preset word bank table, so that the target language may cover all syntax types of the source language, or contents that cannot be mapped in the source code are manually converted into the target code, and the like.
In addition, in an exemplary embodiment, the conversion can be realized by configuring grammar conversion rules between the source language and the target language and performing regular matching on the source code.
Exemplary embodiments of the present disclosure also provide a transcoding apparatus, as shown in fig. 4, the transcoding apparatus 400 may include: a syntax analysis module 410, configured to split the source code into a plurality of source morphemes, and determine a syntax type of each source morpheme; a morpheme mapping module 420, configured to map, according to a syntax type of each source morpheme, each source morpheme into a morpheme of the target language through a preset morpheme table; and the code generating module 430 is configured to generate a code based on the target language according to the morphemes of the target language obtained by mapping each source morpheme. The specific details of each module have been described in detail in the embodiments of the method section, and thus are not described again.
Exemplary embodiments of the present disclosure also provide an electronic device capable of implementing the above method.
As will be appreciated by one skilled in the art, aspects of the present disclosure may be embodied as a system, method or program product. Accordingly, various aspects of the present disclosure may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
an electronic device 500 according to such an exemplary embodiment of the present disclosure is described below with reference to fig. 5. The electronic device 500 shown in fig. 5 is only an example and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
as shown in fig. 5, the electronic device 500 is embodied in the form of a general purpose computing device. The components of the electronic device 500 may include, but are not limited to: the at least one processing unit 510, the at least one memory unit 520, a bus 530 connecting various system components (including the memory unit 520 and the processing unit 510), and a display unit 540.
wherein the storage unit stores program code that is executable by the processing unit 510 to cause the processing unit 510 to perform steps according to various exemplary embodiments of the present disclosure as described in the above section "exemplary methods" of this specification. For example, the processing unit 510 may perform the steps as shown in fig. 1: step S11, splitting the source code into a plurality of source morphemes, and determining the grammar type of each source morpheme; step S12, mapping each source morpheme into the morpheme of the target language through a preset morpheme table based on the grammar type of each source morpheme; step S13, a code based on the target language is generated from the morphemes of the target language mapped by the source morphemes.
the storage unit 520 may include readable media in the form of volatile storage units, such as a random access memory unit (RAM)521 and/or a cache memory unit 522, and may further include a read only memory unit (ROM) 523.
The storage unit 520 may also include a program/utility 524 having a set (at least one) of program modules 525, such program modules 525 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 530 may be one or more of any of several types of bus structures including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
the electronic device 500 may also communicate with one or more external devices 700 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 500, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 500 to communicate with one or more other computing devices. Such communication may occur via input/output (I/O) interfaces 550. Also, the electronic device 500 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via the network adapter 560. As shown, the network adapter 560 communicates with the other modules of the electronic device 500 over the bus 530. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the electronic device 500, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present disclosure may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (which may be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which may be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the exemplary embodiments of the present disclosure.
Exemplary embodiments of the present disclosure also provide a computer-readable storage medium having stored thereon a program product capable of implementing the above-described method of the present specification. In some possible embodiments, various aspects of the disclosure may also be implemented in the form of a program product comprising program code for causing a terminal device to perform the steps according to various exemplary embodiments of the disclosure described in the "exemplary methods" section above of this specification, when the program product is run on the terminal device.
Referring to fig. 6, a program product 600 for implementing the above method according to an exemplary embodiment of the present disclosure is described, which may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto, and in this document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
a computer readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
Furthermore, the above-described figures are merely schematic illustrations of processes included in methods according to exemplary embodiments of the present disclosure, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functions of two or more modules or units described above may be embodied in one module or unit according to an exemplary embodiment of the present disclosure. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is to be limited only by the terms of the appended claims.

Claims (10)

1. A method of transcoding, comprising:
Splitting a source code into a plurality of source morphemes, and determining the grammar type of each source morpheme;
Mapping each source morpheme into a morpheme of a target language through a preset morpheme table based on the grammar type of each source morpheme;
And generating a code based on the target language according to the morphemes of the target language obtained by mapping each source morpheme.
2. The method of claim 1, wherein splitting source code into a plurality of source morphemes and determining a grammar type for each of the source morphemes comprises:
performing structural analysis on the source code to generate an abstract syntax tree consisting of the source morphemes;
And determining the grammar type of each source morpheme according to the node position of each source morpheme in the abstract grammar tree.
3. The method of claim 1, further comprising:
Acquiring grammar rules of a preset language and a morpheme set of the preset language, wherein the preset language at least comprises the language of the source code and the target language;
Obtaining a self-defined grammar rule and a self-defined morpheme set;
and classifying the morpheme set of the preset language and the self-defined morpheme set according to the grammar rule of the preset language and the self-defined grammar rule to obtain the preset morpheme table.
4. the method of claim 1, wherein mapping each of the source morphemes to a morpheme in a target language via a preset morpheme table based on a grammar type of each of the source morphemes comprises:
Searching morphemes, which are the same as the grammar types of the source morphemes, in the target language in the preset morpheme table;
And mapping each source morpheme into morphemes with the same grammar type.
5. The method of claim 2, wherein mapping each of the source morphemes to a morpheme in a target language via a preset morpheme table based on a grammar type of each of the source morphemes comprises:
Converting the abstract syntax tree into a general syntax tree according to the syntax type of each source morpheme;
And mapping each node of the general syntax tree into the morpheme of the target language through the preset morpheme table.
6. The method of claim 1, wherein the source morphemes comprise special morphemes that cannot be mapped to morphemes in the target language; the method further comprises the following steps:
highlighting the special morpheme in the source code.
7. The method of any of claims 1-6, wherein the language of the source code and the target language comprise a high level programming language or an assembly language.
8. a transcoding apparatus, comprising:
The grammar analysis module is used for splitting a source code into a plurality of source morphemes and determining the grammar type of each source morpheme;
The morpheme mapping module is used for mapping each source morpheme into the morpheme of the target language through a preset morpheme table according to the grammar type of each source morpheme;
And the code generation module is used for generating a code based on the target language according to the morphemes of the target language obtained by mapping each source morpheme.
9. an electronic device, comprising:
A processor; and
A memory for storing executable instructions of the processor;
Wherein the processor is configured to perform the method of any of claims 1-7 via execution of the executable instructions.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method of any one of claims 1 to 7.
CN201810541370.4A 2018-05-30 2018-05-30 Code conversion method and device, electronic equipment and storage medium Active CN110554875B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810541370.4A CN110554875B (en) 2018-05-30 2018-05-30 Code conversion method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810541370.4A CN110554875B (en) 2018-05-30 2018-05-30 Code conversion method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110554875A true CN110554875A (en) 2019-12-10
CN110554875B CN110554875B (en) 2021-01-15

Family

ID=68734140

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810541370.4A Active CN110554875B (en) 2018-05-30 2018-05-30 Code conversion method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110554875B (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111309301A (en) * 2020-01-17 2020-06-19 广东三维家信息科技有限公司 Program language conversion method, device and conversion equipment
CN111367527A (en) * 2020-02-18 2020-07-03 北京字节跳动网络技术有限公司 Language processing method, device, medium and electronic equipment
CN111625243A (en) * 2020-05-13 2020-09-04 北京字节跳动网络技术有限公司 Cross-language task processing method and device and electronic equipment
CN111708539A (en) * 2020-06-17 2020-09-25 腾讯科技(深圳)有限公司 Application program code conversion method and device, electronic equipment and storage medium
CN111857709A (en) * 2020-06-12 2020-10-30 北京三快在线科技有限公司 Mapping method and device for React component and Flutter component, electronic equipment and storage medium
CN114896477A (en) * 2022-06-08 2022-08-12 徐州医科大学 Data mining safety visualization system and method supporting multiple language algorithms

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0510616B1 (en) * 1991-04-23 2000-03-01 Hitachi, Ltd. Retargetable information processing system
CN101192171A (en) * 2006-11-29 2008-06-04 国际商业机器公司 Method and system for transforming a single language program into multiple language programs
CN101208660A (en) * 2005-06-27 2008-06-25 奎朴兹有限公司 Code transformation
CN103645931A (en) * 2013-12-25 2014-03-19 盛杰 Method and device for code conversion
CN104503816A (en) * 2014-12-30 2015-04-08 西安电子科技大学 System for automatically converting hardware language VHDL (Vhsic Hardware Description Language) into MSVL (Modeling, Simulation and Verification Language)
CN106293677A (en) * 2015-06-08 2017-01-04 阿里巴巴集团控股有限公司 A kind of code conversion method and device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0510616B1 (en) * 1991-04-23 2000-03-01 Hitachi, Ltd. Retargetable information processing system
CN101208660A (en) * 2005-06-27 2008-06-25 奎朴兹有限公司 Code transformation
CN101192171A (en) * 2006-11-29 2008-06-04 国际商业机器公司 Method and system for transforming a single language program into multiple language programs
CN103645931A (en) * 2013-12-25 2014-03-19 盛杰 Method and device for code conversion
CN104503816A (en) * 2014-12-30 2015-04-08 西安电子科技大学 System for automatically converting hardware language VHDL (Vhsic Hardware Description Language) into MSVL (Modeling, Simulation and Verification Language)
CN106293677A (en) * 2015-06-08 2017-01-04 阿里巴巴集团控股有限公司 A kind of code conversion method and device

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111309301A (en) * 2020-01-17 2020-06-19 广东三维家信息科技有限公司 Program language conversion method, device and conversion equipment
CN111309301B (en) * 2020-01-17 2023-09-01 广东三维家信息科技有限公司 Program language conversion method, device and conversion equipment
CN111367527A (en) * 2020-02-18 2020-07-03 北京字节跳动网络技术有限公司 Language processing method, device, medium and electronic equipment
CN111367527B (en) * 2020-02-18 2023-03-28 北京字节跳动网络技术有限公司 Language processing method, device, medium and electronic equipment
CN111625243A (en) * 2020-05-13 2020-09-04 北京字节跳动网络技术有限公司 Cross-language task processing method and device and electronic equipment
CN111625243B (en) * 2020-05-13 2023-07-18 北京字节跳动网络技术有限公司 Cross-language task processing method and device and electronic equipment
CN111857709A (en) * 2020-06-12 2020-10-30 北京三快在线科技有限公司 Mapping method and device for React component and Flutter component, electronic equipment and storage medium
CN111708539A (en) * 2020-06-17 2020-09-25 腾讯科技(深圳)有限公司 Application program code conversion method and device, electronic equipment and storage medium
CN111708539B (en) * 2020-06-17 2021-07-06 腾讯科技(深圳)有限公司 Application program code conversion method and device, electronic equipment and storage medium
CN114896477A (en) * 2022-06-08 2022-08-12 徐州医科大学 Data mining safety visualization system and method supporting multiple language algorithms

Also Published As

Publication number Publication date
CN110554875B (en) 2021-01-15

Similar Documents

Publication Publication Date Title
CN110554875B (en) Code conversion method and device, electronic equipment and storage medium
US11036937B2 (en) Contraction aware parsing system for domain-specific languages
EP4170515A1 (en) Query translation
CN109495392B (en) Message conversion processing method and device, electronic equipment and storage medium
JP2018533126A (en) Method, system, and computer program product for a natural language interface to a database
CN110502227B (en) Code complement method and device, storage medium and electronic equipment
US10191946B2 (en) Answering natural language table queries through semantic table representation
US10572597B2 (en) Resolution of acronyms in question answering systems
CN111736840A (en) Compiling method and running method of applet, storage medium and electronic equipment
CN109408834B (en) Auxiliary machine translation method, device, equipment and storage medium
CN109344374B (en) Report generation method and device based on big data, electronic equipment and storage medium
US11537448B1 (en) Adapting application programming interfaces with schema mappings
US9886251B2 (en) Optimized compiling of a template function
US11487801B2 (en) Dynamic data visualization from factual statements in text
CN111078228A (en) Method and device for converting webpage into small program, server and storage medium
CN111104796A (en) Method and device for translation
CN111796833A (en) Code language conversion method, system, equipment and storage medium
CN108932225B (en) Method and system for converting natural language requirements into semantic modeling language statements
US11675980B2 (en) Bias identification and correction in text documents
CN111125154B (en) Method and apparatus for outputting structured query statement
CN112860233B (en) Method for generating target grammar tree and related equipment
CN108008947B (en) Intelligent prompting method and device for programming statement, server and storage medium
CN110716949A (en) Method, device, medium and electronic equipment for automatically optimizing structured query statement
US11971887B2 (en) Identifying and replacing logically neutral phrases in natural language queries for query processing
US20190362257A1 (en) Predicting keywords in an application

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
GR01 Patent grant
GR01 Patent grant