CN111078230A - Code generation method and device - Google Patents

Code generation method and device Download PDF

Info

Publication number
CN111078230A
CN111078230A CN201911242157.4A CN201911242157A CN111078230A CN 111078230 A CN111078230 A CN 111078230A CN 201911242157 A CN201911242157 A CN 201911242157A CN 111078230 A CN111078230 A CN 111078230A
Authority
CN
China
Prior art keywords
primitive
statement
java
current
primitives
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911242157.4A
Other languages
Chinese (zh)
Inventor
陈军
王旻锐
张倩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
CCB Finetech 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 China Construction Bank Corp, CCB Finetech Co Ltd filed Critical China Construction Bank Corp
Priority to CN201911242157.4A priority Critical patent/CN111078230A/en
Publication of CN111078230A publication Critical patent/CN111078230A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/52Binary to binary
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven

Landscapes

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

Abstract

The invention discloses a code generation method and device, and relates to the technical field of computers. One embodiment of the method comprises: determining a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives; for each of the primitives: determining the type of the current primitive; determining a current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive; and converting the current primitive into a code of the current language according to the current analysis rule. The method can generate codes of different languages based on the analysis rules corresponding to the languages and the types of the primitives, thereby avoiding redevelopment and reducing development cost.

Description

Code generation method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a code generation method and apparatus.
Background
During program development, if a development framework is changed, the underlying development language is required to be changed frequently. For example, the development framework before the change is COBOL (Common Business-Oriented Language), and the development framework after the change is Java. At this time, the developer needs to newly develop the image.
However, the cost of redevelopment is high.
Disclosure of Invention
In view of this, embodiments of the present invention provide a code generation method and apparatus, which are capable of generating codes of different languages based on parsing rules corresponding to languages and types of primitives, so as to avoid redevelopment and reduce development cost.
In a first aspect, an embodiment of the present invention provides a code generation method, including:
determining a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives;
for each of the primitives:
determining the type of the current primitive;
determining a current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive;
and converting the current primitive into a code of the current language according to the current analysis rule.
Preferably, the first and second electrodes are formed of a metal,
the language, comprising: COBOL and/or Java.
Preferably, the first and second electrodes are formed of a metal,
the parsing rules corresponding to the Java and the process primitives include:
the segment name of the converted field is m + the hump character string in the flow primitive identification; and the parameters of the converted fields are the parameters of the program corresponding to the model, and the return value is null.
Preferably, the first and second electrodes are formed of a metal,
the parsing rule corresponding to the Java and data transfer primitives includes:
determining whether a conditional statement exists in the data transfer primitive, and if so, generating an if statement, wherein an assignment statement after the conditional statement is located in a statement body of the if statement; and generating a set statement according to the front data and the rear data of the assignment statement.
Preferably, the first and second electrodes are formed of a metal,
the parsing rule corresponding to the Java and the checking error-reporting primitive comprises the following steps:
determining whether a judgment statement exists in the checking error-reporting primitive, if so, converting the judgment statement into an if statement; determining an error reporting code and error reporting information according to the error reporting content node in the analysis and inspection error reporting primitive; and generating a try-catch syntax block according to the error reporting code and the error reporting information.
Preferably, the first and second electrodes are formed of a metal,
the parsing rules corresponding to Java and computational primitives include:
acquiring a plurality of variables of the calculation primitive; and generating set sentences corresponding to the variables.
Preferably, the first and second electrodes are formed of a metal,
the parsing rule corresponding to Java and the operation primitive comprises the following steps:
determining a plurality of variables in the operation graphic primitive; and converting the operation graphic element into a Java code according to the variable and the operator corresponding to the variable.
Preferably, the first and second electrodes are formed of a metal,
the parsing rules corresponding to Java and initialization primitives include:
extracting a data list in the initialized graphic primitive; and assigning initial values to the data in the data list.
Preferably, the first and second electrodes are formed of a metal,
the parsing rule corresponding to Java and string processing primitives includes:
if the character strings are processed as splicing, connecting each first character string through '+';
and if the character string is processed as segmentation, segmenting the second character string by a split method, and assigning elements in the obtained character string array to corresponding variables.
Preferably, the first and second electrodes are formed of a metal,
the parsing rules corresponding to the Java and calling node primitives include:
determining whether the calling node primitive has a corresponding interface, and if so, determining a data structure corresponding to the interface; initializing the data structure; and assigning values to the fields in the interface.
Preferably, the first and second electrodes are formed of a metal,
the parsing rules corresponding to Java and conditional branch primitives include:
converting the conditional branch primitive into an if else statement.
Preferably, the first and second electrodes are formed of a metal,
the parsing rule corresponding to Java and the judgment branch primitive comprises the following steps:
and converting the judgment branch primitive into an if else statement.
Preferably, the first and second electrodes are formed of a metal,
the parsing rules corresponding to Java and loop branch primitives include:
if the circulation branch primitive is posterior circulation, converting the circulation branch primitive into a do while statement;
and if the circulation branch primitive is a prior circulation, converting the circulation branch primitive into a for statement.
In a second aspect, an embodiment of the present invention provides a code generation apparatus, including:
a determination module configured to determine a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives;
a parsing module configured to, for each of the primitives: determining the type of the current primitive; determining a current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive; and converting the current primitive into a code of the current language according to the current analysis rule.
In a third aspect, an embodiment of the present invention provides an electronic device, including:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any of the embodiments described above.
In a fourth aspect, an embodiment of the present invention provides a computer-readable medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method of any one of the above embodiments.
One embodiment of the above invention has the following advantages or benefits: the method can generate codes of different languages based on the analysis rules corresponding to the languages and the types of the primitives, thereby avoiding redevelopment and reducing development cost.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a flow diagram of a method for code generation according to an embodiment of the invention;
FIG. 2 is a flow chart of a method of code generation according to another embodiment of the present invention;
FIG. 3 is a schematic diagram of a code generation apparatus provided by an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
During program development, if a development framework is changed, the underlying development language is required to be changed frequently. For example, the development framework before the change is COBOL, and the development framework after the change is Java. At this time, the developer needs to newly develop the image. Also, in this process, the developer needs to master different languages. Therefore, the conversion cost of the prior art is high.
In view of this, an embodiment of the present invention provides a code generation method, as shown in fig. 1, the method includes:
step 101: determining a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives.
The model may define an abstract description of the service to be implemented. It can be expressed by means of UML (Unified modeling Language), XML (Extensible Markup Language), or the like. The model in the embodiment of the invention can be as follows: business rule models, test models, enterprise architecture models, and the like. Wherein, for the business rule model, the business can be loan, currency exchange, etc.
The current language refers to the language of the converted code, and may be determined based on user input. The current language may be COBOL, Java, etc.
In the embodiment of the present invention, the order of determining the model and determining the current language is not limited, and both of them may be determined at the same time, or the model may be determined first and then the current language, or the current language may be determined first and then the model is determined.
Step 102: for each primitive: the type of the current primitive is determined.
The types of primitives include: the processing system comprises a flow primitive, a data transmission primitive, a supervision error reporting primitive, a calculation primitive, an operation primitive, a self-defined primitive, an initialization primitive, a string processing primitive, an SQL (Structured Query Language) primitive, a calling node primitive, a conditional branch primitive, a judgment branch primitive, a circulation branch primitive and the like.
Step 103: and determining the current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive.
The languages, the types of primitives and the parsing rules may be stored correspondingly in a data table, i.e. each combination of language and primitive type has a corresponding parsing rule. For example, if the current language is COBOL and the current primitive type is a computing primitive, the current parsing rule is 3, if the prestored COBOL and flow primitive correspond to parsing rule 1, Java and flow primitive correspond to parsing rule 2, and COBOL and computing primitive correspond to parsing rule 3.
Step 104: and converting the current primitive into a code of the current language according to the current analysis rule.
And converting each primitive in the flow chart into codes of COBOL, Java and other languages according to the corresponding analysis rule. And when the conversion of each primitive in the flow chart is finished, obtaining the converted program code.
The method can generate codes of different languages based on the analysis rules corresponding to the languages and the types of the primitives, thereby avoiding redevelopment and reducing development cost.
As shown in fig. 2, the model is converted into a COBOL code by an analysis rule corresponding to COBOL, and the model is converted into a Java code by an analysis rule corresponding to Java. The analysis rule corresponding to COBOL comprises the analysis rule of the type of each primitive corresponding to COBOL, and the analysis rule corresponding to Java comprises the analysis rule of the type of each primitive corresponding to Java.
In order to describe the parsing rule of the method provided by the present invention, the following embodiment mainly takes the example of converting a model into Java language, and describes the code generation method in detail.
In an embodiment of the present invention, the parsing rules corresponding to Java and the flow primitives include: the segment name of the converted field is a hump character string in the identifier of the m + flow primitive; the parameters of the converted fields are the parameters of the program corresponding to the model, and the return value is null.
For example, the FLOW primitive is identified as FLOW ID, and the segment name of the converted field is a hump character string in m + FLOW ID; the parameters of the converted fields are Param of the program, and the return value is void.
And the parsing rules corresponding to the COBOL and the flow primitives include: and the segment name of the converted field is the identification of the flow primitive.
For COBOL code, the segment name of the converted field is the FLOW ID of the pre-conversion primitive.
The 0000 segment in the primitive is called in execute of the Java code. And (5) calling an initialization method of 1000 segments in the graphic elements for initialization segments in Java codes according to COPYBOOK needing initialization. 9999 segments in the graphic elements generate param.m9999MessageHandleRtn () methods in Java codes, and 9999 error handling segments in COBOL codes.
In an embodiment of the present invention, the parsing rule corresponding to Java and data transfer primitives includes: determining whether a conditional statement exists in the data transfer primitive, and if so, generating an if statement, wherein an assignment statement after the conditional statement is located in a statement body of the if statement; and generating a set statement according to the front data and the rear data of the assignment statement.
It should be noted that, for TBB (Thread Building Blocks), if TFT fields that do not exist in the input are used in the data transfer primitive, the Java code will generate a line of comments. For IO-CGDBMAIN-CURSOR-N AME in the data transfer primitive, no assignment statement is generated in Java code. And the assignment to the POINTER type field is replaced with an assignment directly from the Object POINTER.
Different from the parsing rules corresponding to Java and data transfer primitives, the parsing rules corresponding to COBOL and data transfer primitives include: determining whether a conditional statement exists in the data transfer primitive, and if so, generating an if statement, wherein an assignment statement after the conditional statement is located in a statement body of the if statement; and generating a move statement according to the front data and the rear data of the assignment statement.
In an embodiment of the present invention, the parsing rules corresponding to Java and the checking of the error-reporting primitive include: determining whether a judgment statement exists in the error-reported primitive, and if so, converting the judgment statement into an if statement; determining an error reporting code and error reporting information according to error reporting content nodes in the analysis and inspection error reporting primitives; and generating a try-catch grammar block according to the error reporting code and the error reporting information.
Different from Java, when converting to COBOL, if statements and move statements are generated according to error reporting codes and error reporting information.
In one embodiment of the present invention, parsing rules corresponding to Java and computational primitives include: acquiring a plurality of variables of the calculated primitives; set statements corresponding to the respective variables are generated.
Generating set statements corresponding to the variables, specifically including: converting each variable into a hump character string; wherein, each hump character string is separated by a blank space; storing the hump character strings corresponding to all the variables in ResultValue; analyzing the input (equation) of the calculation primitive into a get/set method of a POJO (Plain Ordinary Java Object) and a character string connected with the calculation symbol through an analytic function; replacing the calculation symbols in the formula; adding brackets for different levels of calculation; splicing character strings in the ComputeTemplate to obtain set sentences corresponding to all variables; the calculation result in the set statement is converted into the Type of the variable by param.
Table 1 replacement rules
Calculating symbols After replacement
+ add
- subtract
* multiply
/ divide (preservation of 20 decimal places, rounding off)
** pow
Wherein the replacement rule is shown in table 1. When parentheses are added, the priority order based on is power multiplication, multiplication/division, addition/subtraction. And transmitting the isRounded and the onsize Error as judgment conditions into an assignment statement, if the On Size Error exists, capturing an exception generated during calculation through try-catch, and converting Error information into a Java code.
It should be noted that, for the computation primitive, COBOL implements conversion of the formula through syntax, and Java implements conversion of the formula using a class arithmetic method.
In an embodiment of the present invention, the parsing rule corresponding to Java and the operation primitive includes: determining a plurality of variables in the operation graphic primitive; and converting the operation graphic elements into Java codes according to the variables and the corresponding operators thereof.
Converting the operation graphic element into a Java code according to the variable and the corresponding operator thereof, comprising:
if the operator is ADD, converting variables after ADD and variables after INTO INTO get statements, and then adding; converting the variables after the INTO INTO set sentences, and then splicing the two sentences;
if the operator is SUBTRACT, converting the variables after SUBTRACT and the variables after FROM into get statements, then subtracting (the variables after FROM-the variables after SUBTRACT), converting the variables after FROM into set statements, and then splicing the two statements;
if the operator is MULTIPLY, the variables after GIVING are parsed, the variables after MULTIPLY and the variables after BY are converted into get statements, then multiplied (BY MULTIPMULTIPLY, where there may be multiple variables after MULTIPLY), then the variables after GIVING are converted into set statements, and then the two statements are joined.
If the operator is DIVIDE, two cases are distinguished, DIVIDE A INTO B (B/A) and DIVIDE A BYB (A/B).
At this time, the variables after DIVIDE and INTO (or BY) are converted INTO get statements and then divided, and then the variables after GIVING are converted INTO set statements and then the two statements are joined. Note that in this process, a rounded parameter (roundingmode. half _ UP) is introduced and the maximum length is reserved for 20 bits. In addition, if the REMAINDER key exists, a line of code is generated, the variables after DIVIDE and INTO (or BY) are spliced BY the REMAINDER method of BigDecimal, and then the result SET is put INTO the variables after the REMAINDER key.
In an embodiment of the present invention, the parsing rule corresponding to Java, custom primitive includes: and taking the custom primitive as the converted Java code.
Similarly, the parsing rules corresponding to COBOL and custom primitives include: and taking the self-defined primitive as a converted COBOL code.
The custom primitives are used to implement functions that are not amenable to modular development. The custom primitive is directly realized by the current language, so the custom primitive can be directly read as a converted code.
In one embodiment of the present invention, parsing rules corresponding to Java and initialization primitives include: extracting a data list in the initialized graphics primitive; data in the data list is assigned an initial value.
Assigning initial values to data in a data list, comprising: invoke the initialize method of the data structure or initialize the data according to different data types.
Similar to Java, parsing rules corresponding to COBOL and initialization primitives include: extracting a data list in the initialized graphics primitive; data in the data list is assigned an initial value.
Wherein, assign the initial value to the data in the data list, include: and calling an INITIALIZE key to INITIALIZE data.
In one embodiment of the present invention, parsing rules corresponding to Java and string processing primitives include:
if the character strings are processed as splicing, connecting each first character string through '+';
and if the character string is processed as segmentation, segmenting the second character string by a split method, and assigning elements in the obtained character string array to corresponding variables.
It should be noted that, if the number is spliced, a _ value () method of the field is called to obtain a corresponding value; if the deleted by size is, the character string is directly used, but when the space deleted by size is, a space is spliced; if the delimiter is |, it will be replaced with \ \ to be suitable for the split method; if the separators are x '20', x '40', etc., then they will be replaced with a string of equal-length spaces; if the value is assigned to a structural body, a parse method of the structural body is called to analyze the incoming spliced character string; if a Key is assigned, the parseKey method of the corresponding structure is called.
For the character String division, the character String is divided by the String split method, and the delimiter is defined after delimitated by. If the data is x '20', x '40' and the like, the data is replaced by a space string with the same length, then each element in the split array is sequentially acquired, and the value is assigned to the corresponding WK variable. In addition, if there is a count in key, the length of the last string is also calculated and then assigned to the WK variable that stores the length. If the delimiter is \ \ then it will be replaced with \ \ to suit the split method.
In an embodiment of the present invention, the parsing rules corresponding to the Java and SQL primitives include: SQL primitives are converted to Java code by EXEC SQL.
The parsing rules corresponding to the COBOL and SQL primitives include: the SQL primitives are converted into COBOL code through JBDC (Java DataBaseConnectivity).
The SQL primitives mainly store SQL statements to be executed, the SQL statements can be executed in both COBOL and Java, and the SQL statements stored in the SQL primitives are only required to be converted into programs which can be understood by a system and then executed.
In an embodiment of the present invention, the parsing rule corresponding to Java and the calling node primitive includes: determining whether the calling node primitive has a corresponding interface, and if so, determining a data structure corresponding to the interface; initializing a data structure; values are assigned to fields in the interface.
In the embodiment of the invention, aiming at the calling of a program, whether a corresponding interface exists is judged, and if the corresponding interface does not exist, the corresponding interface is generated; then, the related data structure of the called program is obtained, the data structure is initialized, the field assignment in the interface is carried out, and the program is called.
Therefore, the problem that the called component cannot be compiled due to the fact that the called component is not converted can be avoided.
From the above, it can be seen that the calling node primitive completes the analysis of the data structure and the program calling after the primitives of each type are combined. COBOL uses a form keyword to make program call, and Java directly makes execute method call of the class.
In one embodiment of the present invention, the parsing rules corresponding to Java and conditional branch primitives include: the conditional branch primitive is converted into an if else statement.
If there are no code segments in the if or else, the conversion results in a sentence annotation. For conditional branch primitives, the COBOL has the same parsing rule as Java.
In an embodiment of the present invention, the parsing rule corresponding to Java and the judgment branch primitive includes: and converting the judgment branch primitive into an if else statement.
Converting the judgment branch primitive into an if else statement specifically includes: the evaluate while statement is converted to an ifelse statement.
If a plurality of whens share a code block, splicing the conditions in the if statement by or (|); if there is a while other statement, then add an else at the end of the if else statement to base on the scene that has no match. If there is no code segment in the while other statement, the conversion gets a sentence annotation.
In one embodiment of the present invention, parsing rules corresponding to Java and loop branch primitives include:
if the loop branch primitive is posterior loop, converting the loop branch primitive into do while statement;
and if the loop branch primitive is a prior loop, converting the loop branch primitive into a for statement.
The loop branch primitive may be a posterior loop (with test after), or a prior loop (with test before), or a default loop.
If the circulation branch primitive is posterior circulation, the execution sequence of the circulation body of the circulation branch primitive is as follows:
a: if the varying variable is present, the varying variable is assigned an initial value (e.g., 1);
b: an execution loop body;
c: and C, judging whether the circulation ending condition is satisfied, if so, exiting the circulation, otherwise, increasing the step number of the variable varying, and executing the step B.
Converting the loop branch primitive into a do while statement, specifically comprising:
if the variable varying exists, assigning the initial value-step length to the variable varying;
in the do structure body, assigning the value + step length of the varying variable outside the do structure body to the varying variable in the do structure body;
writing the circulation logic into a do structure body and after the assignment statement;
the judgment condition is written in while.
The a priori loop differs from the a posteriori loop in that the a priori loop exit loop condition is verified before the loop body is executed.
Converting the loop branch primitive into a for statement, comprising: generating a for loop; inserting the circulating body.
If there is no with test key in the loop branch primitive, it can be executed according to the prior loop. Specifically, if there is a variable varying, the loop is converted into a for loop of a prior loop; if there is no variable, it is converted directly to a while statement.
The embodiment shows that the codes of different languages are converted based on the same model primitive, so that the converted codes can be ensured to have higher consistency, and the codes of different languages are prevented from generating difference in the service implementation process. Compared with the mode of converting data and logic respectively and then merging converted codes, the conversion mode based on the primitive can realize the conversion of the data and the logic simultaneously, reduce errors generated in the merging process and improve the accuracy of analysis.
TABLE 2 differentiation of COBOL code and Java code for different types of primitives
Figure BDA0002306553410000121
Figure BDA0002306553410000131
Table 2 shows differences of different language codes obtained based on different types of primitive transformations, taking COBOL and Java codes as examples.
As shown in fig. 3, an embodiment of the present invention provides a code generation apparatus, including:
a determining module 301 configured to determine a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives;
a parsing module 302 configured to, for each primitive: determining the type of the current primitive; determining a current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive; and converting the current primitive into a code of the current language according to the current analysis rule.
In one embodiment of the invention, the language comprises: COBOL and/or Java.
In an embodiment of the present invention, the parsing rules corresponding to Java and the flow primitives include: the segment name of the converted field is a hump character string in the identifier of the m + flow primitive; the parameters of the converted fields are the parameters of the program corresponding to the model, and the return value is null.
In an embodiment of the present invention, the parsing rule corresponding to Java and data transfer primitives includes: determining whether a conditional statement exists in the data transfer primitive, and if so, generating an if statement, wherein an assignment statement after the conditional statement is located in a statement body of the if statement; and generating a set statement according to the front data and the rear data of the assignment statement.
In an embodiment of the present invention, the parsing rules corresponding to Java and the checking of the error-reporting primitive include: determining whether a judgment statement exists in the error-reported primitive, and if so, converting the judgment statement into an if statement; determining an error reporting code and error reporting information according to error reporting content nodes in the analysis and inspection error reporting primitives; and generating a try-catch grammar block according to the error reporting code and the error reporting information.
In one embodiment of the present invention, parsing rules corresponding to Java and computational primitives include: acquiring a plurality of variables of the calculated primitives; set statements corresponding to the respective variables are generated.
In an embodiment of the present invention, the parsing rule corresponding to Java and the operation primitive includes: determining a plurality of variables in the operation graphic primitive; and converting the operation graphic elements into Java codes according to the variables and the corresponding operators thereof.
In one embodiment of the present invention, parsing rules corresponding to Java and initialization primitives include: extracting a data list in the initialized graphics primitive; data in the data list is assigned an initial value.
In one embodiment of the present invention, parsing rules corresponding to Java and string processing primitives include: if the character strings are processed as splicing, connecting each first character string through '+'; and if the character string is processed as segmentation, segmenting the second character string by a split method, and assigning elements in the obtained character string array to corresponding variables.
In an embodiment of the present invention, the parsing rule corresponding to Java and the calling node primitive includes: determining whether the calling node primitive has a corresponding interface, and if so, determining a data structure corresponding to the interface; initializing a data structure; values are assigned to fields in the interface.
In one embodiment of the present invention, the parsing rules corresponding to Java and conditional branch primitives include: the conditional branch primitive is converted into an if else statement.
In an embodiment of the present invention, the parsing rule corresponding to Java and the judgment branch primitive includes: and converting the judgment branch primitive into an if else statement.
In one embodiment of the present invention, parsing rules corresponding to Java and loop branch primitives include: if the loop branch primitive is posterior loop, converting the loop branch primitive into do while statement; and if the loop branch primitive is a prior loop, converting the loop branch primitive into a for statement.
An embodiment of the present invention provides an electronic device, including: one or more processors; a storage device for storing one or more programs which, when executed by one or more processors, cause the one or more processors to implement the method of any of the embodiments described above.
Fig. 4 illustrates an exemplary system architecture 400 to which the code generation method or code generation apparatus of embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 401, 402, 403. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the code generation method provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the code generation apparatus is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device 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 invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer 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 of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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. In the present invention, a computer 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. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer 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 computer readable signal medium may also be any computer readable medium that is not a computer 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 computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes a sending module, an obtaining module, a determining module, and a first processing module. The names of these modules do not form a limitation on the modules themselves in some cases, and for example, the sending module may also be described as a "module sending a picture acquisition request to a connected server".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
determining a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives;
for each of the primitives:
determining the type of the current primitive;
determining a current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive;
and converting the current primitive into a code of the current language according to the current analysis rule.
According to the technical scheme of the embodiment of the invention, codes of different languages can be generated based on the parsing rules corresponding to the languages and the types of the primitives, so that redevelopment is avoided, and the development cost is reduced.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (16)

1. A code generation method, comprising:
determining a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives;
for each of the primitives:
determining the type of the current primitive;
determining a current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive;
and converting the current primitive into a code of the current language according to the current analysis rule.
2. The method of claim 1,
the language, comprising: the business-oriented general languages COBOL and/or Java.
3. The method of claim 1,
the parsing rules corresponding to the Java and the process primitives include:
the segment name of the converted field is m + the hump character string in the flow primitive identification; and the parameters of the converted fields are the parameters of the program corresponding to the model, and the return value is null.
4. The method of claim 1,
the parsing rule corresponding to the Java and data transfer primitives includes:
determining whether a conditional statement exists in the data transfer primitive, and if so, generating an if statement, wherein an assignment statement after the conditional statement is located in a statement body of the if statement; and generating a set statement according to the front data and the rear data of the assignment statement.
5. The method of claim 1,
the parsing rule corresponding to the Java and the checking error-reporting primitive comprises the following steps:
determining whether a judgment statement exists in the checking error-reporting primitive, if so, converting the judgment statement into an if statement; determining an error reporting code and error reporting information according to the error reporting content node in the analysis and inspection error reporting primitive; and generating a try-catch syntax block according to the error reporting code and the error reporting information.
6. The method of claim 1,
the parsing rules corresponding to Java and computational primitives include:
acquiring a plurality of variables of the calculation primitive; and generating set sentences corresponding to the variables.
7. The method of claim 1,
the parsing rule corresponding to Java and the operation primitive comprises the following steps:
determining a plurality of variables in the operation graphic primitive; and converting the operation graphic element into a Java code according to the variable and the operator corresponding to the variable.
8. The method of claim 1,
the parsing rules corresponding to Java and initialization primitives include:
extracting a data list in the initialized graphic primitive; and assigning initial values to the data in the data list.
9. The method of claim 1,
the parsing rule corresponding to Java and string processing primitives includes:
if the character strings are processed as splicing, connecting each first character string through '+';
and if the character string is processed as segmentation, segmenting the second character string by a split method, and assigning elements in the obtained character string array to corresponding variables.
10. The method of claim 1,
the parsing rules corresponding to the Java and calling node primitives include:
determining whether the calling node primitive has a corresponding interface, and if so, determining a data structure corresponding to the interface; initializing the data structure; and assigning values to the fields in the interface.
11. The method of claim 1,
the parsing rules corresponding to Java and conditional branch primitives include:
converting the conditional branch primitive into an if else statement.
12. The method of claim 1,
the parsing rule corresponding to Java and the judgment branch primitive comprises the following steps:
and converting the judgment branch primitive into an if else statement.
13. The method of any one of claims 1-12,
the parsing rules corresponding to Java and loop branch primitives include:
if the circulation branch primitive is posterior circulation, converting the circulation branch primitive into a do while statement;
and if the circulation branch primitive is a prior circulation, converting the circulation branch primitive into a for statement.
14. A code generation apparatus, comprising:
a determination module configured to determine a model and a current language; wherein, the model comprises: a flow chart; the flow chart is composed of a plurality of primitives;
a parsing module configured to, for each of the primitives: determining the type of the current primitive; determining a current parsing rule corresponding to the current language and the type of the current primitive according to the parsing rule corresponding to the language and the type of the primitive; and converting the current primitive into a code of the current language according to the current analysis rule.
15. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-13.
16. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-13.
CN201911242157.4A 2019-12-06 2019-12-06 Code generation method and device Pending CN111078230A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911242157.4A CN111078230A (en) 2019-12-06 2019-12-06 Code generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911242157.4A CN111078230A (en) 2019-12-06 2019-12-06 Code generation method and device

Publications (1)

Publication Number Publication Date
CN111078230A true CN111078230A (en) 2020-04-28

Family

ID=70312996

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911242157.4A Pending CN111078230A (en) 2019-12-06 2019-12-06 Code generation method and device

Country Status (1)

Country Link
CN (1) CN111078230A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112764763A (en) * 2020-12-31 2021-05-07 亿企赢网络科技有限公司 Code conversion method, system, equipment and computer readable storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001008007A1 (en) * 1999-07-22 2001-02-01 Passage Software, Llc Method and system of automated generation of program code from an object oriented model
US20050283758A1 (en) * 2002-07-29 2005-12-22 Interad Technology Limited Bi-directional programming system/method for program development
CN102360291A (en) * 2011-10-07 2012-02-22 云南爱迪科技有限公司 Service-oriented business rule design method based on business rule engine
CN108829395A (en) * 2018-06-19 2018-11-16 中国电子科技集团公司第四十研究所 A kind of signal-oriented driver code automatic generation method and device
CN108874386A (en) * 2018-06-14 2018-11-23 中国电子科技集团公司第四十研究所 A kind of patterned signal-oriented driver modeling method and device
US20190079738A1 (en) * 2015-10-15 2019-03-14 Philip Samuel Bytecode generation from uml models

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2001008007A1 (en) * 1999-07-22 2001-02-01 Passage Software, Llc Method and system of automated generation of program code from an object oriented model
US20050283758A1 (en) * 2002-07-29 2005-12-22 Interad Technology Limited Bi-directional programming system/method for program development
CN102360291A (en) * 2011-10-07 2012-02-22 云南爱迪科技有限公司 Service-oriented business rule design method based on business rule engine
US20190079738A1 (en) * 2015-10-15 2019-03-14 Philip Samuel Bytecode generation from uml models
CN108874386A (en) * 2018-06-14 2018-11-23 中国电子科技集团公司第四十研究所 A kind of patterned signal-oriented driver modeling method and device
CN108829395A (en) * 2018-06-19 2018-11-16 中国电子科技集团公司第四十研究所 A kind of signal-oriented driver code automatic generation method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王晓宇: "基于UML类图和顺序图的C++代码自动生成方法的研究", 《计算机应用与软件》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112764763A (en) * 2020-12-31 2021-05-07 亿企赢网络科技有限公司 Code conversion method, system, equipment and computer readable storage medium
CN112764763B (en) * 2020-12-31 2024-01-26 亿企赢网络科技有限公司 Code conversion method, system, equipment and computer readable storage medium

Similar Documents

Publication Publication Date Title
CN113342346B (en) Operator registration method, device, equipment and storage medium of deep learning framework
CN108933695B (en) Method and apparatus for processing information
CN109766148B (en) Method and apparatus for processing interface method calls
CN114911465B (en) Method, device and equipment for generating operator and storage medium
CN110858202A (en) Method and device for generating where clause in database query statement
CN110706093A (en) Accounting processing method and device
CN109062560B (en) Method and apparatus for generating information
CN111125064A (en) Method and device for generating database mode definition statement
CN112860356A (en) API call control method and device, electronic equipment and storage medium
CN107729001B (en) Expression processing method and device
CN115509522A (en) Interface arranging method and system for low-code scene and electronic equipment
CN114675820A (en) Service arrangement data processing method and device, electronic equipment and storage medium
US10606843B2 (en) Irreducible modules
CN111078230A (en) Code generation method and device
CN111414154A (en) Method and device for front-end development, electronic equipment and storage medium
CN112579151A (en) Method and device for generating model file
CN113656433B (en) Entity object expansion method, entity object expansion device, electronic equipment and storage medium
CN110764768A (en) Method and device for mutual conversion between model object and JSON object
CN114661747A (en) Index calculation method and device, storage medium and computer equipment
CN113760240A (en) Method and device for generating data model
CN112947941A (en) Method and device for adding exception handling code
CN113312900A (en) Data verification method and device
CN114428615B (en) CSS compiling method, style updating device, medium and equipment
CN110069514B (en) Message processing method and device
CN116483370A (en) Code conversion method, device, electronic equipment and storage medium

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
TA01 Transfer of patent application right

Effective date of registration: 20220921

Address after: 25 Financial Street, Xicheng District, Beijing 100033

Applicant after: CHINA CONSTRUCTION BANK Corp.

Address before: 25 Financial Street, Xicheng District, Beijing 100033

Applicant before: CHINA CONSTRUCTION BANK Corp.

Applicant before: Jianxin Financial Science and Technology Co.,Ltd.

TA01 Transfer of patent application right
RJ01 Rejection of invention patent application after publication

Application publication date: 20200428

RJ01 Rejection of invention patent application after publication