CN106919434B - Code generation method and device - Google Patents

Code generation method and device Download PDF

Info

Publication number
CN106919434B
CN106919434B CN201710174006.4A CN201710174006A CN106919434B CN 106919434 B CN106919434 B CN 106919434B CN 201710174006 A CN201710174006 A CN 201710174006A CN 106919434 B CN106919434 B CN 106919434B
Authority
CN
China
Prior art keywords
language
service
branch
file
code
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.)
Active
Application number
CN201710174006.4A
Other languages
Chinese (zh)
Other versions
CN106919434A (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.)
Hundsun Technologies Inc
Original Assignee
Hundsun Technologies Inc
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 Hundsun Technologies Inc filed Critical Hundsun Technologies Inc
Priority to CN201710174006.4A priority Critical patent/CN106919434B/en
Publication of CN106919434A publication Critical patent/CN106919434A/en
Application granted granted Critical
Publication of CN106919434B publication Critical patent/CN106919434B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/51Source to source
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/73Program documentation

Abstract

The application discloses a code generation method and a device, after a target file to be converted into a code is obtained, the target file including each section of service logic language is analyzed respectively to mark a plurality of language units forming the service logic language, and the language units are annotations, initial source code sections or service branch languages; if the language unit is a service branch language, converting the service branch language into a target source code segment described by a computer programming language, wherein the target source code segment comprises one or two of a target code segment and a comment; combining the analyzed annotations, the initial source code segment and the target source code segment to obtain a source code set corresponding to the service logic language; and combining at least one source code set converted from the at least one section of business logic language and storing the combined source code set into a file to obtain a source file converted from the target file. The scheme realizes efficient and convenient code generation based on the business logic language.

Description

Code generation method and device
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a code generation method and apparatus.
Background
According to the needs of the business process, the user can write some business logic languages describing the business logic (such as the business execution process or the business control process), and the business logic languages are generally written by the user using an interpretative language. In order to convert the file resource containing the business logic language into the executable file executable by the computer, the business logic language needs to be converted into the source code corresponding to the computer programming language, for example, the code in C language or C + + language.
At present, if a service logic language for describing service logic needs to be converted into a source code corresponding to a computer programming language, a user needs to know the C language or the C + + language very much to manually write a corresponding source code according to the service logic language, and the technical requirements on developers are high, which results in high difficulty in a code development process and low development efficiency.
Disclosure of Invention
In view of this, the present application provides a code generation method and apparatus, so as to implement efficient and convenient code generation based on a business logic language.
In order to achieve the above object, the following solutions are proposed:
a code generation method, comprising:
acquiring a target file to be converted into a code, wherein the target file comprises at least one section of service logic language for describing service logic;
analyzing the service logic language corresponding to any section of service logic language to mark a plurality of language units forming the service logic language, wherein the language units are annotations, initial source code segments described by adopting a computer programming language or service branch languages for describing service steps in the service logic;
if the language unit is a service branch language, converting the service branch language into a target source code segment described by a computer programming language according to a conversion rule corresponding to a branch name of the service branch language, wherein the target source code segment comprises one or two of a target code segment and a comment;
combining the determined annotations, the initial source code segment and the target source code segment to obtain a source code set corresponding to the business logic language;
combining at least one source code set converted from the at least one section of service logic language and storing the combined source code set into a file to obtain a source file converted from the target file, wherein the source file comprises the at least one source code set.
Optionally, before parsing the service logic language, the method further includes:
determining the file type of the target file;
loading an analysis engine corresponding to the file type according to the file type of the target file;
the analyzing the service logic language comprises:
and analyzing the business logic language by utilizing the analysis engine.
Optionally, before the parsing the service logic language, the method further includes:
detecting whether configuration information corresponding to the file type of the target file is preset or not, wherein the configuration information is used for changing the composition form of a source code in a source file converted from the business logic language;
and if the configuration information exists, loading the configuration information into the business logic language of the target file.
Optionally, the parsing the service logic language to mark a plurality of language units forming the service logic language includes:
and analyzing the business logic language into a plurality of language units separated by the specified label marks based on the specified label marks contained in the business logic language.
Optionally, the converting the service branch language into a target source code segment described by using a computer programming language according to a conversion rule corresponding to the branch name of the service branch language includes:
determining a parameter conversion rule corresponding to the branch name of the business branch language according to the corresponding relation between the preset branch name and the parameter conversion rule;
converting the parameters to be converted in the service branch language into code parameters described by adopting a computer programming language;
and setting the numerical value associated with the parameter to be converted in the service branch language as the numerical value associated with the code parameter converted by the parameter to be converted.
Optionally, the method further includes:
and if the parameter conversion rule corresponding to the branch name of the service branch language does not exist, marking the service branch language as an annotation.
Optionally, after obtaining the target file and converting the target file into the source file, the method further includes:
determining an operating system for compiling the source file according to the storage path of the target file;
and compiling the source file on the determined operating system to obtain an executable file which can run.
On the other hand, an embodiment of the present application further provides a code generation apparatus, including:
the file acquisition unit is used for acquiring a target file to be converted into a code, and the target file comprises at least one section of service logic language for describing service logic;
the language analysis unit is used for analyzing the service logic language corresponding to any section of service logic language so as to mark a plurality of language units forming the service logic language, and the language units are annotations, initial source code segments described by adopting a computer programming language or service branch languages used for describing service steps in the service logic;
the branch conversion unit is used for converting the business branch language into a target source code segment described by a computer programming language according to a conversion rule corresponding to the branch name of the business branch language if the language unit is the business branch language, wherein the target source code segment comprises one or two of a target code segment and a comment;
the code combination unit is used for combining the annotation, the initial source code and the target source code segment to obtain a source code set corresponding to the business logic language;
a source file generating unit, configured to combine at least one source code set converted from the at least one section of service logic language and store the combined source code set in a file, so as to obtain a source file converted from the target file, where the source file includes the at least one source code set.
Optionally, the method further includes:
a type determining unit, configured to determine a file type of the target file before the language parsing unit parses the service logic language;
the analysis engine loading unit is used for loading an analysis engine corresponding to the file type according to the file type of the target file;
the language parsing unit is specifically configured to parse the service logic language by using the parsing engine when parsing the service logic language.
Optionally, the branch converting unit includes:
a rule determining unit, configured to determine, if the language unit is a service branch language, a parameter conversion rule corresponding to a branch name of the service branch language according to a preset correspondence between the branch name and the parameter conversion rule;
the parameter conversion unit is used for converting the parameters to be converted in the service branch language into code parameters described by a computer programming language;
and the numerical value association unit is used for setting the numerical value associated with the parameter to be converted in the service branch language as the numerical value associated with the code parameter converted by the parameter to be converted.
And the annotation identification unit is used for marking the service branch language as an annotation if the parameter conversion rule corresponding to the branch name of the service branch language does not exist.
As can be seen from the above content, in the embodiment of the present application, after a target file to be converted into a code is obtained, each segment of service logic language is sequentially parsed to mark a plurality of language units forming the service logic language, where the language units are annotations, initial source code segments described by using a computer programming language, or a service branch language for describing service steps in service logic; if the language unit is a service branch language, the service branch language is converted into a target source code segment described by a computer programming language according to a conversion rule corresponding to the branch name of the service branch language, so that a source code set corresponding to the service logic language can be obtained by combining the comment converted from the service logic language, the initial source code and the target source code, and at least one source code set converted from at least one section of the service logic language is combined and stored in a file to obtain a source file, thereby realizing the automatic conversion of the service logic language into the code, avoiding the need of manually writing the code by a person with professional knowledge, reducing the technical requirements for generating the code, reducing the complexity of generating the code and improving the code generation efficiency.
Drawings
In order to more clearly illustrate the embodiments of the present application or technical solutions in the prior art, the drawings required for the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only the embodiments of the present application, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a schematic flow chart diagram illustrating an embodiment of a code generation method according to the present application;
FIG. 2 is a schematic diagram illustrating the structure of a business logic language in an embodiment of the present application;
FIG. 3 is a schematic diagram illustrating a cyclic processing of business logic languages in a target file by the code generation method of the present application;
FIG. 4 is a schematic flow chart diagram illustrating a further embodiment of a code generation method of the present application;
fig. 5 is a schematic diagram illustrating a component structure of an embodiment of a code generation apparatus according to the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. 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 application.
First, a code generation method of the present application will be described.
Referring to fig. 1, which shows a schematic structural diagram of a code generation method according to another embodiment of the present application, the method of this embodiment may be applied to a computer device, such as a stand-alone computer, or a server node in a distributed system, and so on.
The method of the embodiment may include:
s101, acquiring a target file to be converted into a code, wherein the target file comprises at least one section of business logic language for describing business logic.
The target file is a file resource used for converting the target file into a code corresponding to a computer programming language, and is used for describing business logic to be processed by the function body. The service logic language contained in the target file is a logic language for describing service logic, and for example, the target file contains information related to describing a service execution flow, service steps related to the service execution flow and flow control. Since the business logic language included in the object file is not C or C + +, for convenience of description, the business logic language is also referred to as pseudo code in the embodiments of the present application.
The target file may be in various forms in the embodiment of the present application, for example, the target file may be an XML file, a txt file, or a custom file resource. As a preferred implementation, the embodiment of the present application may adopt a custom file resource, such as an atom func atom function resource.
It is understood that the target file may be stored in a directory, and in practical applications, a directory may include a plurality of target files to be converted into codes, but for each target file, the code generation method of the embodiment of the present application may be used to convert codes,
s102, corresponding to any section of service logic language, analyzing the service logic language to mark a plurality of language units forming the service logic language.
The language unit is one of comment, an initial source code segment described by adopting a computer programming language or a service branch language for describing service steps in service logic.
It will be appreciated that multiple business processes or steps may be required for a business logic, and thus, the business logic language describing the business logic may be comprised of one or more business branch languages describing business steps in the business logic. Each business branch language can be considered as a basic unit of a business logic language, and if the business logic language is considered as pseudo code, the business branch language can be considered as a macro in the pseudo code.
Some comments may be added between different service branching languages, and the comments may be used to assist in interpreting the service logic. For example, the annotation may be annotation information described in terms of the C/C + + syntax, such as multiple lines of pseudo code included with "/", or a single line of pseudo code beginning with "//".
There may also be one or more code segments formed by lines of codes between the service branch languages or annotations, wherein, in order to facilitate distinguishing from the code segments converted from the service branch languages, the code segment directly parsed from the service logic language is referred to as an initial source code segment.
It can be understood that, since the original source code segment is the code itself, no further conversion is needed, and the comment in the business logic language can also be directly used to explain the role or meaning of the code, so that the original source code segment and the comment can be directly determined as the code and directly output without conversion for subsequent combination with the code converted from the business branch language.
In one implementation, the business logic language may be separated from each language unit by a specific tag, and therefore, the business logic language may be parsed into a plurality of language units separated by the specific tag based on the specific tag included in the business logic language. Wherein. The designated tag label may have one or more, e.g., the annotation may be a plurality of lines of pseudo code included with "//", or a single line of pseudo code beginning with "//", then the language within "//" may be considered an annotation; the branch of service languages (i.e., macros) may be labeled with a particular label other than a comment, for example, but not limited to, in parentheses "[ ]", such that a line of pseudo code included in a middle parenthesis corresponds to a set of branch of service languages.
It should be noted that a segment of the logical service language may be a service branch language itself, in which case a segment of the logical service language may resolve a service branch language.
S103, if the language unit is a service branch language, converting the service branch language into a target source code segment described by a computer programming language according to a conversion rule corresponding to the branch name of the service branch language.
Wherein the target source code segment includes one or both of a target code segment and an annotation.
Different types of service branch languages can correspond to different conversion rules, and the service branch languages can be converted into code segments based on the conversion rules corresponding to the service branch languages. It is understood that comments or codes can be included in a set of business branch languages, and the comments or codes in the business branch languages can be directly output, that is, for the comments or codes in the business branch languages, the conversion rules can be directly output without conversion, and for the parameters other than the comments and the codes can be converted into codes according to the corresponding conversion rules.
For easy understanding, in the embodiment of the present application, reference may be made to fig. 2 for a composition relationship between a service logic language, a service branch language, and a comment, where in fig. 2, a pseudo code represents the service logic language, and a macro represents the service branch language. As can be seen from fig. 2, the pseudo code may be composed of macro, source code (the initial source code mentioned in the embodiments of the present application) and annotation, and the source code may be plain text or a character string. The macro may include a user macro and a system macro. Wherein, the user macro system macro: the method is characterized by comprising the steps of internally packaging codes for generating and processing logics, such as resource analysis, logic judgment, exception handling and the like; user self-defining: and (4) packaging the self-defined code generation processing logic by using the scheme.
And S104, combining the annotation, the initial source code and the target source code segment to obtain a source code set corresponding to the business logic language.
When the obtained annotations, the initial source code segments and the target source code segments are combined and spliced, the annotations, the initial source codes and the target source code segments can be sequentially spliced to obtain codes according to the annotations, the original codes and the sequence of the service branch language of the converted annotations or the target source codes in the service logic language. The spliced codes are referred to as source code sets in the embodiments of the present application.
S105, combining the at least one source code set converted from the at least one section of business logic language and storing the combined source code set into a file to obtain a source file converted from the target file.
Wherein the source file comprises at least one source code set.
The scheme of the embodiment of the application realizes automatic conversion of the business logic language into the code, does not need personnel with professional knowledge to manually compile the code, reduces the technical requirements for generating the code, also reduces the complexity of generating the code, and improves the code generation efficiency.
It can be understood that, in this embodiment of the present application, for a section of business logic language, after marking out a plurality of language units included in the business logic language, it is still necessary to analyze whether each language unit is already source code or other data that does not need to be further converted, and if the language unit is a business branch language, the language unit needs to be converted to finally obtain source code or annotation, as shown in fig. 3, which shows a schematic diagram of a code generation method performing loop processing on the business logic language in a target file.
Referring to fig. 4 in conjunction with fig. 3, which shows a schematic flowchart of another embodiment of a code generation method of the present application, the method of the present embodiment may include:
s401, obtaining a target file to be converted into a code, wherein the target file comprises at least one section of business logic language for describing business logic.
As shown in fig. 3, taking an object file as an example of a file resource for generating C/C + + source code, the resource is input into a device running the code generation method of the present application to process the resource.
S402, determining the file type of the target file.
The file type is used to distinguish the type of the business logic language in the target file, for example, the file type may be a file in the form of C/C + +.
S403, loading an analysis engine corresponding to the file type according to the file type of the target file.
S404, detecting whether configuration information corresponding to the file type of the target file is preset, wherein the configuration information is used for changing the composition form of the source code in the source file converted from the business logic language.
S405, if the configuration information exists, loading the configuration information into the business logic language of the target file.
Of course, if the configuration information does not exist, the subsequent operation may be directly performed.
As shown in fig. 3, the operations of steps S402 to S404 are completed by managing this program through a blueprint factory extension point, and finally the type of the target file, the required parsing engine (e.g., the context in the blueprint factory obtained in fig. 3), and the configuration model (e.g., the model in the blueprint factory in fig. 3) are obtained through analysis, and after the above information is obtained, a token iteration may be triggered to mark each language unit included in the business logic language in a token iteration manner.
S406, analyzing the business logic language by using the analysis engine corresponding to any section of business logic language to mark a plurality of language units forming the business logic language.
The method comprises the steps of defining a main body framework of source codes required by business logic languages contained in file resources, and defining a token queue in the theme framework, wherein the token can be understood as the minimum logic unit processed by a generation engine in the business logic languages, namely, each language unit is a token. For example, taking a file resource as the resource in the atomfunc form as an example, there are the following parts:
function definition token: defining a description body of the function, and mainly describing information such as a return value, a name, parameters and the like of the function;
parameter initialization token: defining and initializing function input parameters, output parameters and internal variables;
pseudo code resolution token: analyzing a pseudo code structure logic part;
function end token: and function returning operation, namely returning function output parameters to the normal execution of the function, returning an error message if an error occurs, and performing the operation of analyzing and constructing the structure used in the function to release the memory.
In the embodiment of the application, different token modes can be respectively called to perform token processing according to the type of the defined token in the token queue. In the embodiment of the present application, tokens to be processed are divided into 4 types: plain text, comments, macros, pseudo code.
The common code and the comment do not need to be processed any more, and when the final code is generated, the common code is directly taken out and spliced, wherein the common code is the initial source code mentioned in the application, such as a general C/C + + code, for example, a flow control statement, a conditional judgment statement, and the like. The annotation may be annotation information described in terms of the original code syntax, such as annotation information described in terms of the C/C + + syntax, for example, lines of pseudo code included by "/", or a single line of pseudo code beginning with "/", may be considered annotation information.
The pseudo code is a section of business logic language, and specifically, referring to a schematic diagram of a composition structure of the pseudo code in fig. 2, for the pseudo code, a pseudo code parser needs to be called to parse the pseudo code, and then a relevant token iteration is generated, as shown in fig. 3, if the business logic language is not a simple comment or a macro, etc., processing on the left side needs to be performed, so that a common text, a comment and a macro contained in the pseudo code are marked by loading a context (which may be understood as a handler or an engine).
Macros may be understood as a sub-component of pseudo-code, such as a line of pseudo-code that may be included by a special label (e.g., a bracket "[ ]"). The definition of the macro may be: < Macro Mark > [ Macro name ] [ Macro parameter ]. Wherein, the macro mark marks the difference part of the source code generated by the same macro under different logic scenes, and the difference part does not necessarily exist; the macro name uniquely represents the logical scenario that this macro uses for processing, and must exist; macro parameters: auxiliary information for macro processing logic, is not necessarily present. For macros, the relevant macro handler needs to be called for processing, and then the relevant token iteration is generated. As shown in the right side of fig. 3, the macro is processed through the macro processor factory extension point management including processing logic, which can be specifically referred to in subsequent steps S407 to 410.
S407, if the language unit is a service branch language, determining a parameter conversion rule corresponding to the branch name of the service branch language according to a preset correspondence between the branch name and the parameter conversion rule.
S408, converting the parameters to be converted in the service branch language into code parameters described by adopting a computer programming language.
S409, setting the value associated with the parameter to be converted in the service branch language as the value associated with the code parameter converted from the parameter to be converted.
For a service branch language (i.e. macro), if a parameter to be converted in the service branch language is associated with a relevant numerical value, the numerical value associated with the parameter to be converted may be obtained from a database or a designated storage area, and the numerical value is used as data associated with a code parameter corresponding to the parameter to be converted.
S410, if the parameter conversion rule corresponding to the branch name of the service branch language does not exist, marking the service branch language as a comment.
If the parameter conversion rule corresponding to the service branch language does not exist, the service branch language is indicated to be the annotation, and the service branch language can be directly marked as the annotation. As in fig. 3, if the macro is parsed into normal code and enters the token processing section. In the token processing section, if the ordinary code and the comment are finally obtained from the business logic language or the business branch language, the operation of code generation, that is, the subsequent step S411 may be performed.
S411, the annotation, the initial source code, the code parameter and the value associated with the code parameter obtained by analyzing are combined to obtain a source code set corresponding to the business logic language.
After the above S406 to S410, a section of business logic language is completely converted into the annotation, the initial source code and the code parameter, the splicing and combining can be performed, and finally the source code set corresponding to the business logic language is obtained. It is understood that, when performing the splicing combination, the positions of the annotation, the initial source code, and the code parameter in the source code set can be determined according to the original positions of the annotation, the initial source code in the business logic language, and the original position of the business branch language corresponding to the code parameter in the business logic language.
S412, combining the at least one source code set converted from the at least one section of business logic language and then saving the combined source code set into a file to obtain a source file converted from the target file.
Wherein the source file comprises at least one source code set.
S413, determining an operating system for compiling the source file according to the storage path of the target file.
S414, compiling the source file on the determined operating system to obtain an executable file which can run.
On the other hand, the embodiment of the application also provides a code generation device.
Referring to fig. 5, which shows a schematic structural diagram of an embodiment of a code generation apparatus according to the present application, the apparatus of the present embodiment may include:
a file obtaining unit 501, configured to obtain a target file to be converted into a code, where the target file includes at least one service logic language for describing service logic;
a language parsing unit 502, configured to parse a service logic language corresponding to any section of the service logic language to mark a plurality of language units forming the service logic language, where the language units are annotations, initial source code segments described by using a computer programming language, or service branch languages used for describing service steps in the service logic;
a branch conversion unit 503, configured to, if the language unit is a service branch language, convert the service branch language into a target source code segment described in a computer programming language according to a conversion rule corresponding to a branch name of the service branch language, where the target source code segment includes one or both of a target code segment and a comment;
a code combining unit 504, configured to combine the comment, the initial source code, and the target source code segment to obtain a source code set corresponding to the business logic language;
a source file generating unit 505, configured to combine at least one source code set converted from the at least one service logic language and store the combined source code set in a file, so as to obtain a source file converted from the target file, where the source file includes the at least one source code set.
Optionally, the apparatus may further include:
a type determining unit, configured to determine a file type of the target file before the language parsing unit parses the service logic language;
the analysis engine loading unit is used for loading an analysis engine corresponding to the file type according to the file type of the target file;
the language parsing unit is specifically configured to parse the service logic language by using the parsing engine when parsing the service logic language.
Further, the apparatus may further include:
a configuration information detection unit, configured to detect whether configuration information corresponding to the file type of the target file is preset before the language parsing unit parses the service logic language, where the configuration information is used to change a composition form of a source code in a source file converted from the service logic language;
and the configuration information loading unit is used for loading the configuration information into the service logic language of the target file if the configuration information exists.
Optionally, the branch converting unit includes:
a rule determining unit, configured to determine, if the language unit is a service branch language, a parameter conversion rule corresponding to a branch name of the service branch language according to a preset correspondence between the branch name and the parameter conversion rule;
the parameter conversion unit is used for converting the parameters to be converted in the service branch language into code parameters described by a computer programming language;
and the numerical value association unit is used for setting the numerical value associated with the parameter to be converted in the service branch language as the numerical value associated with the code parameter converted by the parameter to be converted.
And the annotation identification unit is used for marking the service branch language as an annotation if the parameter conversion rule corresponding to the branch name of the service branch language does not exist.
Optionally, the apparatus further comprises:
an operating system determining unit, configured to determine, after the source file generating unit obtains the source file converted from the target file, an operating system for compiling the source file according to a storage path of the target file;
and the code compiling unit is used for compiling the source file on the determined operating system to obtain an executable file.
Finally, it should also be noted that, herein, 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. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (9)

1. A code generation method for automatically converting a business logic language into code, the method comprising:
acquiring a target file to be converted into a code, wherein the target file comprises at least one section of service logic language for describing service logic;
analyzing the service logic language corresponding to any section of service logic language to mark a plurality of language units forming the service logic language, wherein the language units are annotations, initial source code segments described by adopting a computer programming language or service branch languages for describing service steps in the service logic;
if the language unit is a service branch language, converting the service branch language into a target source code segment described by a computer programming language according to a conversion rule corresponding to a branch name of the service branch language, wherein the target source code segment comprises one or two of a target code segment and a comment, and the method comprises the following steps: determining a parameter conversion rule corresponding to the branch name of the business branch language according to the corresponding relation between the preset branch name and the parameter conversion rule; converting the parameters to be converted in the service branch language into code parameters described by adopting a computer programming language; setting the numerical value associated with the parameter to be converted in the service branch language as the numerical value associated with the code parameter converted by the parameter to be converted;
combining the determined annotations, the initial source code segment and the target source code segment to obtain a source code set corresponding to the business logic language;
combining at least one source code set converted from the at least one section of service logic language and storing the combined source code set into a file to obtain a source file converted from the target file, wherein the source file comprises the at least one source code set.
2. The code generation method of claim 1, wherein before parsing the business logic language, further comprising:
determining the file type of the target file;
loading an analysis engine corresponding to the file type according to the file type of the target file;
the analyzing the service logic language comprises:
and analyzing the business logic language by utilizing the analysis engine.
3. The code generation method of claim 2, further comprising, prior to said parsing the business logic language:
detecting whether configuration information corresponding to the file type of the target file is preset or not, wherein the configuration information is used for changing the composition form of a source code in a source file converted from the business logic language;
and if the configuration information exists, loading the configuration information into the business logic language of the target file.
4. The code generation method of any one of claims 1 to 3, wherein the parsing the business logic language to mark out a plurality of language units constituting the business logic language comprises:
and analyzing the business logic language into a plurality of language units separated by the specified label marks based on the specified label marks contained in the business logic language.
5. The code generation method according to claim 1, further comprising:
and if the parameter conversion rule corresponding to the branch name of the service branch language does not exist, marking the service branch language as an annotation.
6. The code generation method of claim 1, further comprising, after said obtaining the target file and converting it into a source file:
determining an operating system for compiling the source file according to the storage path of the target file;
and compiling the source file on the determined operating system to obtain an executable file which can run.
7. A code generation apparatus for automatically converting a business logic language into code, the apparatus comprising:
the file acquisition unit is used for acquiring a target file to be converted into a code, and the target file comprises at least one section of service logic language for describing service logic;
the language analysis unit is used for analyzing the service logic language corresponding to any section of service logic language so as to mark a plurality of language units forming the service logic language, and the language units are annotations, initial source code segments described by adopting a computer programming language or service branch languages used for describing service steps in the service logic;
the branch conversion unit is used for converting the business branch language into a target source code segment described by a computer programming language according to a conversion rule corresponding to the branch name of the business branch language if the language unit is the business branch language, wherein the target source code segment comprises one or two of a target code segment and a comment;
the code combination unit is used for combining the annotation, the initial source code and the target source code segment to obtain a source code set corresponding to the business logic language;
a source file generating unit, configured to combine at least one source code set converted from the at least one section of service logic language and store the combined source code set in a file to obtain a source file converted from the target file, where the source file includes the at least one source code set;
a branch conversion unit comprising:
a rule determining unit, configured to determine, if the language unit is a service branch language, a parameter conversion rule corresponding to a branch name of the service branch language according to a preset correspondence between the branch name and the parameter conversion rule;
the parameter conversion unit is used for converting the parameters to be converted in the service branch language into code parameters described by a computer programming language;
and the numerical value association unit is used for setting the numerical value associated with the parameter to be converted in the service branch language as the numerical value associated with the code parameter converted by the parameter to be converted.
8. The code generation apparatus according to claim 7, further comprising:
a type determining unit, configured to determine a file type of the target file before the language parsing unit parses the service logic language;
the analysis engine loading unit is used for loading an analysis engine corresponding to the file type according to the file type of the target file;
the language parsing unit is specifically configured to parse the service logic language by using the parsing engine when parsing the service logic language.
9. The code generating apparatus according to claim 7, wherein the branch conversion unit further comprises: and the annotation identification unit is used for marking the service branch language as an annotation if the parameter conversion rule corresponding to the branch name of the service branch language does not exist.
CN201710174006.4A 2017-03-22 2017-03-22 Code generation method and device Active CN106919434B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710174006.4A CN106919434B (en) 2017-03-22 2017-03-22 Code generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710174006.4A CN106919434B (en) 2017-03-22 2017-03-22 Code generation method and device

Publications (2)

Publication Number Publication Date
CN106919434A CN106919434A (en) 2017-07-04
CN106919434B true CN106919434B (en) 2021-02-12

Family

ID=59462103

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710174006.4A Active CN106919434B (en) 2017-03-22 2017-03-22 Code generation method and device

Country Status (1)

Country Link
CN (1) CN106919434B (en)

Families Citing this family (28)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108304175B (en) * 2018-01-29 2021-06-08 口碑(上海)信息技术有限公司 Code file isolation packaging method and device
CN108563447A (en) * 2018-04-13 2018-09-21 郑州云海信息技术有限公司 A kind of code adding method, system, device and computer readable storage medium
CN108762764A (en) * 2018-06-05 2018-11-06 中国平安人寿保险股份有限公司 Code automatic generation method, device, computer equipment and storage medium
CN109240672B (en) * 2018-07-20 2022-02-11 北京航空航天大学 Artificial intelligence writing method for information transmission source code of single machine component of digital aircraft
CN109101231B (en) * 2018-08-07 2022-09-23 百度在线网络技术(北京)有限公司 Script code generation method and device, computer equipment and storage medium
CN109298880B (en) * 2018-08-09 2022-02-18 恒生电子股份有限公司 Multi-version code generation method and device and electronic device
CN109325217B (en) * 2018-09-19 2023-04-18 深圳市元征科技股份有限公司 File conversion method, system, device and computer readable storage medium
CN109344230B (en) * 2018-10-31 2023-08-11 任志颖 Code library file generation, code search, coupling, optimization and migration method
CN109828754A (en) * 2018-12-14 2019-05-31 深圳壹账通智能科技有限公司 A kind of intelligent handover method, device and the equipment of program development project
CN109739512B (en) * 2018-12-28 2022-04-12 江苏极光网络技术有限公司 Analytic language text type analysis and conversion method
CN110134404A (en) * 2019-04-12 2019-08-16 深圳壹账通智能科技有限公司 Code translation method, apparatus, computer equipment and storage medium
CN110109675A (en) * 2019-04-30 2019-08-09 翟红鹰 Intelligent contract processing method, device and computer readable storage medium
CN110297633B (en) * 2019-06-28 2023-05-23 百度在线网络技术(北京)有限公司 Transcoding method, device, equipment and storage medium
CN110737431B (en) * 2019-09-18 2023-07-14 深圳市金证科技股份有限公司 Software development method, development platform, terminal device and storage medium
CN110716798B (en) * 2019-09-29 2021-11-19 微梦创科网络科技(中国)有限公司 PHP (hypertext preprocessor) timing task management method and system
CN110795080A (en) * 2019-10-21 2020-02-14 山东舜知信息科技有限公司 Automatic code generation system based on database annotation and construction method
CN110752895A (en) * 2019-10-22 2020-02-04 盛科网络(苏州)有限公司 Programming method and device of Ethernet message
CN111142852B (en) * 2019-12-30 2023-10-27 亚信科技(中国)有限公司 Interface conversion function generation method and device
CN111475150B (en) * 2020-04-07 2023-12-05 广州致远电子股份有限公司 Cross-language binding method, device, equipment and storage medium
CN111427578B (en) * 2020-04-15 2023-08-29 赞同科技股份有限公司 Data conversion method, device and equipment
CN111625224B (en) * 2020-05-28 2023-11-24 北京百度网讯科技有限公司 Code generation method, device, equipment and storage medium
CN111966584A (en) * 2020-07-30 2020-11-20 上海泛微网络科技股份有限公司 Automatic detection method and device for jsp code language specification
CN112199086A (en) * 2020-09-18 2021-01-08 北京达佳互联信息技术有限公司 Automatic programming control system, method, device, electronic device and storage medium
CN112395843B (en) * 2020-11-16 2024-04-09 杭州安恒信息技术股份有限公司 PHP code-based service processing method, device and medium
CN113434125A (en) * 2021-06-24 2021-09-24 广州欢网科技有限责任公司 Method and system for interconversion between sets based on java language
CN113254026B (en) * 2021-07-19 2021-10-01 国网汇通金财(北京)信息科技有限公司 Low code development method and device
CN116088855B (en) * 2023-02-15 2023-06-23 天翼云科技有限公司 Development method, development device, electronic device, and storage medium
CN115993955B (en) * 2023-03-23 2023-06-23 山东大学 Source code generation and test method and system for symmetric cryptographic algorithm

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8397223B2 (en) * 2000-03-17 2013-03-12 Gutenberg Printing Llc Web application generator
US20040015832A1 (en) * 2001-05-25 2004-01-22 Michael Stapp Method and apparatus for generating source code
CN100517222C (en) * 2006-10-25 2009-07-22 中兴通讯股份有限公司 Model conversion frame supporting separation of conversion engine and mapping rule and the method
CN101055521B (en) * 2007-04-04 2011-08-10 中兴通讯股份有限公司 Mapping rule visualized generation method and system
CN103176830A (en) * 2013-04-15 2013-06-26 西安电子科技大学 Method for generating C++code based on combination of class diagram and activity diagram
CN103412783A (en) * 2013-08-27 2013-11-27 杭州友声科技有限公司 Method for converting script codes into user flow diagram based on business logic layer
CN104572072B (en) * 2014-12-01 2017-09-29 北京百度网讯科技有限公司 A kind of language transfer method and equipment to the program based on MVC pattern

Also Published As

Publication number Publication date
CN106919434A (en) 2017-07-04

Similar Documents

Publication Publication Date Title
CN106919434B (en) Code generation method and device
US10698682B1 (en) Computerized software development environment with a software database containing atomic expressions
US9063672B2 (en) Systems and methods for verifying model equivalence
US7958493B2 (en) Type inference system and method
US8365163B2 (en) Method for configuring a computer program
US9710243B2 (en) Parser that uses a reflection technique to build a program semantic tree
CN110704063B (en) Method and device for compiling and executing intelligent contract
CN110688122B (en) Method and device for compiling and executing intelligent contract
CN110704064B (en) Method and device for compiling and executing intelligent contract
US9304893B1 (en) Integrated software development and test case management system
CN113050953A (en) Method, device and storage medium for generating code based on annotation
CN112799718A (en) Enumerated document generation method and device, electronic equipment and storage medium
CA2428558C (en) System and method for defining and using subclasses declaratively within markup
CN109325217B (en) File conversion method, system, device and computer readable storage medium
US9405739B1 (en) Source code format for IDE code development with embedded objects
CN111694726A (en) Python program type derivation method based on type labeling
KR102614967B1 (en) Automation system and method for extracting intermediate representation based semantics of javascript
US20130042224A1 (en) Application analysis device
CN114816425B (en) Method and system for converting an automation language program into a LUA language program
Chodarev et al. Development of custom notation for XML-based language: A model-driven approach
CN116880826B (en) Visualized code generation method
JP2010282248A (en) Programming language analysis execution program
van der Spek The overture project: Designing an open source tool set
Strömbäck A Syntax Highlighting and Code Formatting Tool for Extensible Languages
CN114237573A (en) Method and system for automatically constructing back-end code of compiler

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