WO2013029399A1 - Code generating method and system - Google Patents

Code generating method and system Download PDF

Info

Publication number
WO2013029399A1
WO2013029399A1 PCT/CN2012/076018 CN2012076018W WO2013029399A1 WO 2013029399 A1 WO2013029399 A1 WO 2013029399A1 CN 2012076018 W CN2012076018 W CN 2012076018W WO 2013029399 A1 WO2013029399 A1 WO 2013029399A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
source file
code generation
data
user
Prior art date
Application number
PCT/CN2012/076018
Other languages
French (fr)
Chinese (zh)
Inventor
张丽娜
Original Assignee
中兴通讯股份有限公司
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 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2013029399A1 publication Critical patent/WO2013029399A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Definitions

  • the present invention relates to the field of communications, and in particular to a code generation method and system.
  • Traditional code generation tools are mainly divided into two categories, one is a Microsoft Foundation Classes (MFC) compiler environment provided by Microsoft Virtual Studio, and a visual graphical interface operation mode is adopted.
  • MFC Microsoft Foundation Classes
  • the built-in graphics parsing module converts the graphical interface built by the user into C++ code according to the built-in graphics parsing module, and generates the corresponding application by compiling the link.
  • the industry calls it the "what you see is what you get” mode.
  • the advantage of this mode is that it uses the MFC integrated compilation environment, which reduces the entry requirements for programmers and can bring products to market faster, but the disadvantages are also obvious.
  • the first is the built-in graphics parsing module parsing mode is fixed mode, user Code generation can only be performed according to the built-in parsing method of MFC, so it can't respond quickly to different needs of users, code generation rules can't be configured, code generation means is too single, and there are major flaws in the flexibility of code generation mode. Therefore, there are inherent shortcomings in the development of large-scale software and the need to meet the code requirements of high-quality software products, which limits the use and promotion of MFC. Therefore, the current large-scale software development in the industry does not use MFC.
  • the other is the transcoding tool represented by Ericsson APG40 and ASN1C of IMAG, which is used for data decoding of complex communication protocols.
  • Code generation for a .1 type communication protocol codec The feature of this type of code generation tool is to increase the flexibility and scope of the code generation tool by importing different communication protocol description files.
  • the defect is mainly that the code generation rules are still not real-time configuration, and the new protocol specification is not compatible, and the code generation is Tool upgrade and maintenance costs are too high, so promotion is difficult. It can be seen that no matter which of the above code generation tools, the code generation rules are fixed when generating the code, and the user's need for flexible configuration of the code generation rules cannot be satisfied.
  • a code generation method including: acquiring a code generation rule and a flow control rule that a user uses an interpreted language configuration; and using a flow control rule to parse a data control flow input by a user to obtain a flow control source file ; Generate code using code generation rules based on the process control source file and user-entered data source files.
  • the step of generating code by using the code generation rule according to the flow control source file and the data source file input by the user includes: driving the engine by using a source file data based on a regular expression The source file and the process control source file are matched, the key information of the data source file and the key information of the process control source file are obtained; the key information of the source file is controlled according to the key information and the process of the data source file, and the code is used.
  • Generate rule generation code includes multiple, the step of generating the code by using the code generation rule includes: acquiring a code language type to be generated configured by the user; and selecting a corresponding code generation according to the code language type Rule generation code.
  • the data control flow includes at least one of the following: a code data processing flow, an input and output parameter, and a code calling sequence.
  • the flow control source file includes a function name, function call information, and a function implementation, wherein the function implementation is pre-filled with an empty function.
  • the above method further comprises: performing validity checking on the generated code by using a grammar checking tool provided by the explanatory language.
  • a code generation system including: a first acquisition module configured to acquire a code generation rule and a flow control rule that a user uses an interpreted language configuration; a data flow analysis engine, configured to use a flow
  • the control rule parses the data control flow input by the user, obtains the process control source file, and generates a module, which is set to control the source file and the data source file input by the user according to the process, and generate code by using the code generation rule.
  • the generating module includes: a source file data driving engine, configured to match the data source file and the flow control source file by using a regular expression, and obtain key information and a process control source file of the data source file.
  • the key information; the pattern matching module is configured to control the key information of the source file according to the key information and the process of the data source file, and generate the code by using the code generation rule.
  • the code generation rule includes a plurality
  • the generation module includes: a second acquisition module, configured to acquire a code language type to be generated configured by the user; and a code generation module configured to be according to the data source file
  • the key information and process control key information of the source file, as well as the type of code language obtained, are generated using the corresponding code generation rules.
  • the apparatus further includes: an checking module, configured to perform a validity check on the generated code by using a grammar checking tool provided in the interpreted language.
  • the code generation rule and the flow control rule are configured by using an explanatory language, and the features of the explanatory language interpretation execution are fully utilized, so that the user can flexibly configure the code generation rule and the flow control rule in the code generation process according to the requirements, and generate The code file that meets the user's requirements solves the problem that the prior art code generation tool is not flexible when generating the code, thereby achieving the effect of enhancing the flexibility of the code generation tool.
  • FIG. 1 is a flow chart showing the steps of a code generating method according to a first embodiment of the present invention
  • FIG. 2 is a flow chart showing the steps of a code generating method according to a second embodiment of the present invention
  • FIG. 4 is a structural block diagram of a code generating system according to Embodiment 4 of the present invention
  • Embodiment 5 is a block diagram of a code generating system according to Embodiment 5 of the present invention; Structure diagram. BEST MODE FOR CARRYING OUT THE INVENTION
  • FIG. 1 a flow chart of steps of a code generating method according to Embodiment 1 of the present invention is shown.
  • the code generating method of this embodiment includes the following steps S102 to S106.
  • the code generation rule and the flow control rule are written by the user in an explanatory language, and are flexibly configured as needed.
  • Interpretive languages such as scripting languages do not need to be compiled, and can be interpreted and executed, so that users can configure code generation rules and process control rules in real time and dynamically.
  • Step S104 Parse the data control flow input by the user by using the flow control rule, and obtain the flow control source file.
  • the data control flow input by the user is parsed using the flow control rules written in the explanatory language, and the flow control source file is acquired to control the flow of the generated code.
  • Step S106 The code generation rule generates the code according to the flow control source file and the data source file input by the user.
  • the code generation rules written in the explanatory language are used to parse and convert the process control source file and the data source file input by the user, and finally generate the code.
  • the code generation tool is not flexible enough when generating code.
  • the code generation rule and the flow control rule are configured by the interpreted language, and the features of the explanatory language interpretation execution are fully utilized, so that the user can flexibly configure the code generation rule and the flow control rule in the code generation process according to the requirements.
  • the generation of a code file that meets the user's requirements solves the problem that the prior art code generation tool is not flexible when generating the code, thereby achieving the effect of enhancing the flexibility of the code generation tool.
  • Embodiment 2 Referring to FIG.
  • Step S202 The user configures the code generation rule and the flow control rule using an interpreted language. In this step, the user can write the input code generation rules and the flow control rules in an explanatory language through an input interface, such as a user interface UI interface. Of course, the code generation rules and flow control rules can also be pre-set, and can be reused or edited in this code generation.
  • Step S204 The user inputs a data control flow and a data source file. In this step, the user can input the data control process and the data source file through the UI interface. However, it is not limited thereto.
  • the user may also input the data control flow and the data source file by any other suitable means.
  • the data control process mainly includes: code data processing flow, input and output parameters, and code calling sequence.
  • the data control flow may include all of the above, and may also include one or a part thereof.
  • Step S206 Parse the data control flow input by the user by using the flow control rule to obtain the flow control source file.
  • the system analyzes the data control flow by using the flow control rule written in the explanatory language to obtain the flow control source file.
  • the process control source file may include: a function name, a function call information, and a function implementation. Function implementations can be pre-populated with empty functions.
  • Step S208 Matching the data source file and the process control file by using the source file data driving engine based on the regular expression to obtain key information of the data source file and key information of the process control file.
  • the source file data driver engine is mainly used for parsing data source files and process control source files. It matches the data source files and process control source files through the regular expression function of the explanatory language, extracts key information, and then submits the key information. Subsequent processes are processed.
  • the key to matching the data source file and the flow control source file is to use regular expressions to extract and match keywords in the data source file and the flow control source file.
  • the regular expression uses a "character” The string "describes a feature, and then verifies that another "string” conforms to this feature.
  • the expression “ab+” describes the feature “one 'a' and any 'b'", then 'ab', 'abb', 'abbbbbbbb' all conform to this feature.
  • the key information includes: function name, function call information, the composition of the data type in the function, and function input parameters and output parameters.
  • the key information is used for subsequent generation of code.
  • the composition of the code is divided into two categories: (1) Data structure: including function type, parameter type, structure variable composition, class structure; (2) Algorithm: including input and output parameter order, Function call order.
  • Step S210 Generate code according to the key information of the data source file and the key information of the process control file, and use the code generation rule.
  • the default code language type to be generated such as JAVA
  • the key information of the data source file and the key information of the process control source file may be converted, and generated according to the default code language type style.
  • Code Preferably, different code language types to be generated may be configured in advance, as configured in step S202, and different types of code are generated according to different code language type styles when generating the code.
  • different code generation rules may be configured according to different code language types to be generated, and when the code is generated, the corresponding code generation rule generation code is selected according to different code language type styles.
  • the generated code can also be checked for validity by using a grammar checking tool provided by the interpretive language to improve code generation efficiency and correctness.
  • a grammar checking tool provided by the interpretive language to improve code generation efficiency and correctness.
  • the user can input code generation rules and flow control rules written in an interpreted language through a "what you see is what you get" user interface, and then use the code generation rules and flow control rules to control the flow of data and data input by the user.
  • the source file is parsed to generate the required code, which effectively solves the problem that the prior art code generation tool is not flexible when generating the code, and achieves the effect of enhancing the flexibility of the code generation tool.
  • Embodiment 3 Referring to FIG. 3, a flow chart of steps of a code generating method according to Embodiment 3 of the present invention is shown.
  • the code generating method of this embodiment includes the following steps S302 to S318.
  • Step S302 The user inputs through the UI interface, where the input items include: a configuration code generation rule, a flow control rule, and a code language type to be generated. Then, using the provided graphic model to describe and control the code data processing flow, input and output parameters, and code calling sequence to be generated, and complete the description of the generated code on the UI interface, that is, in the "what you see is what you get" display mode. Perform the above input (ie input data control flow and data source file).
  • Step S304 Select a corresponding flow control analysis mode by reading the configured flow control rule. Among them, the flow control rules are written in an interpretive language.
  • Step S306 Parse the data control flow input by the user according to the read flow control rule. Among them, the main parsing items are information such as input and output parameters, function call order, and so on.
  • Step S308 Generate a flow control source file.
  • the process control source file describes the overall architecture and control flow that the user is ready to generate code, including the function name, function call information, and the function implementation is pre-populated with an empty function.
  • Step S310 Acquire a data source file. Among them, the data source file can also be dynamically and real-time configured, which is the specific information part of the code generation.
  • the data source file contains the composition, data type, etc. of the specific data structure in the generated code.
  • Step S312 Parsing the data source file and the flow control source file. In this step, the data source file and the process control source file are matched by the regular expression function of the explanatory language, and the key information is extracted.
  • Step S314 Select a corresponding code generation rule.
  • the code generation rules are also described in an interpreted language, so the description rules can be dynamically changed to transform the key information in the data source files and process control source files.
  • the system carries multiple language tools.
  • Step S316 Code generation is performed according to the selected code generation rule, and code validity check is performed. In the code validity check, you can use the syntax check tool that comes with an interpreted language (such as the PERL scripting language) to perform basic syntax checking to improve the efficiency and correctness of code generation tool code conversion.
  • Step S318 Generate a code file of a corresponding type according to the code language type selected by the user, and prompt the user that the code is generated.
  • Embodiment 4 Referring to FIG. 4, a block diagram of a code generation system according to Embodiment 4 of the present invention is shown.
  • the code generation system of this embodiment includes: a first obtaining module 402 configured to acquire a code generation rule and a flow control rule configured by the user using an interpreted language; and a data flow analysis engine 404 configured to parse the data input by the user using the flow control rule
  • the control process obtains the process control source file;
  • the generating module 406 is configured to generate the code by using the code generation rule according to the process control source file and the data source file input by the user.
  • the generating module 406 includes: a source file data driving engine 4062, configured to match the data source file and the process control source file by using a regular expression, and obtain key information of the data source file and key information of the process control source file;
  • the pattern matching module 4064 is configured to control key information of the source file according to key information and processes of the data source file, and generate code by using a code generation rule.
  • the key of the source file data driving engine 4062 to match the data source file and the flow control source file is to use a regular expression to extract and match keywords of the data source file and the process control source file, when the search is found to meet expectations. When the keyword is successful, the key information is extracted.
  • the key information includes: function name, function call information, the composition of the data type in the function, and function input parameters and output parameters.
  • the code generation rule includes a plurality
  • the generating module 406 includes: a second obtaining module 4066, configured to acquire a code language type to be generated configured by the user; and a code generating module 4068, configured to be based on key information and processes of the data source file Control the key information of the source file, as well as the type of code language obtained, and generate the code using the appropriate code generation rules.
  • the code generating system of this embodiment further includes: an checking module 408, configured to perform a validity check on the generated code by using a syntax checking tool provided in the explanatory language.
  • the data control flow comprises at least one of the following: a code data processing flow, an input and output parameter, and a code calling sequence.
  • the flow control source file includes a function name, function call information, and a function implementation, wherein the function implementation is pre-populated with an empty function.
  • the method implemented in this embodiment can refer to the related description of the foregoing embodiment, and has the beneficial effects of the foregoing embodiments, and details are not described herein again.
  • the code generation rule and the flow control rule are configured by the interpreted language, and the features of the explanatory language interpretation execution are fully utilized, so that the user can flexibly configure the code generation rule and the flow control rule in the code generation process according to the requirements.
  • Embodiment 5 a block diagram of a code generation system according to Embodiment 5 of the present invention is shown.
  • the code generation system of this embodiment includes a UI input module 502, a data flow analysis engine 504, a source file data drive engine 506, a pattern matching module 508, and a code generation module 510.
  • the UI input module 502 is mainly configured to provide a UI interface to receive user input, including a configuration information input interface and an interface display module.
  • the information input through the configuration information input interface mainly includes code generation rules, flow control rules, and generated code language types.
  • the code generation rule affects the data structure of the code
  • the flow control rule affects the code algorithm
  • the generated code language type determines the generated code language specification format, such as generating C or JAVA language
  • the interface display module is mainly used for receiving and displaying user input. Parameter control, the user can modify and view the parameters of the configuration information input interface through the interface display module.
  • the user Through the UI input module 502, the user first uses the explanatory language configuration code generation rule, the flow control rule 1", and the code language type to be generated, and then uses the provided graphic model to input the output parameter to the code data processing flow to be generated.
  • the code call sequence is described and controlled, that is, the input data control flow and the data source file. And, after the user inputs, acquiring the foregoing information input by the user, including a code generation rule, a flow control rule, a code language type to be generated, a data control process, and a data source file (corresponding to the first obtaining module 402 in the fourth embodiment) ).
  • the data flow analysis engine 504 is mainly used to parse the code data processing flow input by the UI input module 502, input and output parameters, code calling sequence and the like, that is, the input data control flow is parsed through the input flow control rule.
  • Process control rules can be dynamically set through an interpreted language such as a scripting language to support different requirements and different language types.
  • the process control source file is generated.
  • the source file data driving engine 506 is mainly used for parsing data source files and process control source files, and matching the data source files and the process control source files through the regular expression function of the explanatory language to extract key information, and further The processing is performed by the pattern matching module 508.
  • the pattern matching module 508, the main function is based on the user-configured code generation rules, the type of the code language to be generated, and the corresponding matching pattern is selected to match the data source file and the process control source file key information delivered by the source file data driving engine, and the key information is transmitted. Code generation is performed for code generation module 510.
  • the code generation module 510 is a multi-language type code generation module that generates configuration information according to the code passed by the pattern matching module 508, converts key information of the data source file into code, and controls key information of the source file according to the process. Generate a code call flow to complete the code generation.
  • the above-mentioned script-based dynamic visual code generation system provided by the embodiment includes a flow control rule configuration script, a data source file, a code generation rule configuration script, a data flow control rule, a code generation rule, and a data source file. Dynamic configuration and changes can be made, which greatly enhances the flexibility of the code generation tool. It has obvious advantages in upgrading and maintaining the code generation tool and reducing the software's post-use cost.
  • the present invention is based on the shortcomings of two mainstream code generation tools in the industry, and provides a dynamic visual code generation method and system based on script control, using regular expressions of a scripting language.
  • the data flow analysis engine and the source file data drive engine are constructed. Therefore, the script language can be modified in real time, the data flow analysis engine is utilized, the UI visual graphical interface is parsed, the data source file and the flow control source file are dynamically generated, the source file data driving engine based on the regular expression is configured, and the data source file is completed.
  • the flow of process control source files to dynamically generate code.
  • the invention utilizes the script language as the characteristic of the interpretation execution, and can realize the real-time and dynamic modification of the matching rules, thereby greatly improving the flexibility of the code generation tool.
  • the robustness and efficiency of the code generation tool can be greatly improved, and the source file data driving engine can be corrected for the data characteristics of the source file in real time, thereby reducing the maintenance code generation tool.
  • the cost because of the variety of code that can be generated, also extends the scope of application of the code generation tool.
  • the computing device may be implemented by program code executable by the computing device, such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein.
  • the steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module.
  • the invention is not limited to any specific combination of hardware and software.
  • the above is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.

Landscapes

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

Abstract

Disclosed are a code generating method and system. The code generating method comprises: acquiring a code generating rule and a process control rule configured by a user using an interpreting language; using the process control rule to parse a data control process input by the user, to obtain a process control source file; and according to the process control source file and a data source file input by the user, using the code generating rule to generate a code. The present invention solves the problem that an existing code generating tool is not flexible enough in generating a code, so that the flexibility of the code generating tool is enhanced.

Description

代码生成方法及系统 技术领域 本发明涉及通信领域, 具体而言, 涉及一种代码生成方法及系统。 背景技术 传统的代码生成工具主要分为两大类, 一类是以微软公司的 Virtual Studio提供的 微软基础类 (Microsoft Foundation Classes, 简称为 MFC)编译环境、 采用可视图形界 面的操作模式, 通过内置的图形解析模块, 将用户搭建的图形界面按照内置的图形解 析模块转换为 C++代码, 通过编译链接生成对应的应用程序, 业界称为"所见即所得" 模式。 该模式的好处是利用 MFC集成编译环境, 降低了对程序员的入门要求, 能够 更快地将产品推向市场, 但是缺点也非常明显, 首先是内置的图形解析模块解析模式 为固定模式, 用户只能根据 MFC 内置的解析方法来进行代码生成, 因而无法快速响 应用户不同需求, 代码生成规则无法进行配置, 代码生成手段过于单一, 在代码生成 模式的灵活性方面有重大缺陷。 因此, 在进行大型软件开发和满足高品质软件产品的 代码需求方面存在先天不足, 故限制了 MFC 的使用和推广, 因而目前业界的大型软 件开发均没有使用 MFC的案例。 另一类是爱立信 APG40 、美国 IMAG公司的 ASN1C为代表的代码转换工具,用 于复杂通信协议的数据解码, 通过提取通信协议中的关键字段, 利用脚本进行规则匹 配, 可以很好地解决 ASN.1类型的通信协议编解码程序的代码生成。 该类型代码生成 工具的特点是通过导入不同的通信协议描述文件, 增加了代码生成工具的灵活性和适 用范围,缺陷主要在于代码生成规则依然不能进行实时配置,对新协议规范无法兼容, 代码生成工具升级维护成本过高, 因此推广困难。 可见, 无论是上述哪种代码生成工具, 在生成代码时都存在代码生成规则较为固 定, 无法满足用户对代码生成规则进行灵活配置的需求。 发明内容 本发明提供了一种代码生成方法及系统, 以至少解决上述现有技术的代码生成工 具在生成代码时不够灵活的问题。 根据本发明的一个方面, 提供了一种代码生成方法, 包括: 获取用户使用解释性 语言配置的代码生成规则和流程控制规则; 使用流程控制规则解析用户输入的数据控 制流程, 获得流程控制源文件; 根据流程控制源文件和用户输入的数据源文件, 使用 代码生成规则生成代码。 优选地, 所述根据所述流程控制源文件和所述用户输入的数据源文件, 使用所述 代码生成规则生成代码的步骤包括: 通过基于正则表达式的源文件数据驱动引擎, 对所述数据源文件和流程控制源文 件进行匹配, 获取所述数据源文件的关键信息和流程控制源文件的关键信息; 根据所述数据源文件的关键信息和流程控制源文件的关键信息, 使用所述代码生 成规则生成代码。 优选地, 所述代码生成规则包括多个, 所述使用所述代码生成规则生成代码的步 骤包括: 获取所述用户配置的待生成的代码语言类型; 根据所述代码语言类型选择相 应的代码生成规则生成代码。 优选地, 所述数据控制流程包括以下至少之一: 代码数据处理流程、 输入输出参 数、 代码调用顺序。 优选地, 所述流程控制源文件包括函数名、 函数调用信息、 和函数实现, 其中, 所述函数实现以空函数预先填充。 优选地, 上述方法还包括: 使用所述解释性语言自带的语法检查工具, 对生成的 所述代码进行有效性检查。 根据本发明的另一方面, 提供了一种代码生成系统, 包括: 第一获取模块, 设置 为获取用户使用解释性语言配置的代码生成规则和流程控制规则;数据流程解析引擎, 设置为使用流程控制规则解析用户输入的数据控制流程, 获得流程控制源文件; 生成 模块, 设置为根据流程控制源文件和用户输入的数据源文件, 使用代码生成规则生成 代码。 优选地, 所述生成模块包括: 源文件数据驱动引擎, 设置为通过正则表达式, 对 所述数据源文件和流程控制源文件进行匹配, 获取所述数据源文件的关键信息和流程 控制源文件的关键信息; 模式匹配模块, 设置为根据所述数据源文件的关键信息和流 程控制源文件的关键信息, 使用所述代码生成规则生成代码。 优选地, 所述代码生成规则包括多个, 所述生成模块包括: 第二获取模块, 设置 为获取所述用户配置的待生成的代码语言类型; 代码生成模块, 设置为根据所述数据 源文件的关键信息和流程控制源文件的关键信息, 以及获取的所述代码语言类型, 使 用相应的代码生成规则生成代码。 优选地, 上述装置还包括: 检查模块, 设置为使用所述解释性语言自带的语法检 查工具, 对生成的所述代码进行有效性检查。 通过本发明, 采用解释性语言配置代码生成规则和流程控制规则, 充分利用了解 释性语言解释执行的特点, 使得用户可以根据需求, 在代码生成过程中灵活配置代码 生成规则和流程控制规则, 生成符合用户需求的代码文件, 从而解决了现有技术的代 码生成工具在生成代码时不够灵活的问题, 进而达到了增强代码生成工具灵活性的效 果。 附图说明 此处所说明的附图用来提供对本发明的进一步理解, 构成本申请的一部分, 本发 明的示意性实施例及其说明用于解释本发明, 并不构成对本发明的不当限定。 在附图 中: 图 1是根据本发明实施例一的一种代码生成方法的步骤流程图; 图 2是根据本发明实施例二的一种代码生成方法的步骤流程图; 图 3是根据本发明实施例三的一种代码生成方法的步骤流程图; 图 4是根据本发明实施例四的一种代码生成系统的结构框图; 图 5是根据本发明实施例五的一种代码生成系统的结构框图。 具体实施方式 下文中将参考附图并结合实施例来详细说明本发明。 需要说明的是, 在不冲突的 情况下, 本申请中的实施例及实施例中的特征可以相互组合。 实施例一 参照图 1, 示出了根据本发明实施例一的一种代码生成方法的步骤流程图。 本实施例的代码生成方法包括以下步骤 S102至步骤 S106。 步骤 S102: 获取用户使用解释性语言配置的代码生成规则和流程控制规则。 本实施例中, 代码生成规则和流程控制规则由用户使用解释性语言编写, 根据需 要灵活配置。 解释性语言如脚本语言无须编译, 可解释执行, 便于用户实时、 动态对 代码生成规则和流程控制规则进行配置。 步骤 S104: 使用流程控制规则解析用户输入的数据控制流程, 获得流程控制源文 件。 本步骤中, 对用户输入的数据控制流程, 使用解释性语言编写的流程控制规则进 行解析, 获取流程控制源文件, 以对生成的代码的流程进行控制。 步骤 S106: 根据流程控制源文件和用户输入的数据源文件, 使用代码生成规则生 成代码。 本步骤中, 使用解释性语言编写的代码生成规则, 对流程控制源文件和用户输入 的数据源文件进行解析和转化, 最终生成代码。 相关技术中, 代码生成工具在生成代码时不够灵活。 通过本实施例, 采用解释性 语言配置代码生成规则和流程控制规则, 充分利用了解释性语言解释执行的特点, 使 得用户可以根据需求, 在代码生成过程中灵活配置代码生成规则和流程控制规则, 生 成符合用户需求的代码文件, 从而解决了现有技术的代码生成工具在生成代码时不够 灵活的问题, 进而达到了增强代码生成工具灵活性的效果。 实施例二 参照图 2, 示出了根据本发明实施例二的一种代码生成方法的步骤流程图。 本实施例的代码生成方法包括以下步骤 S202至步骤 S210。 步骤 S202: 用户使用解释性语言配置代码生成规则和流程控制规则。 本步骤中, 用户可以通过输入界面, 如用户接口 UI界面, 使用解释性语言编写输 入代码生成规则和流程控制规则。 当然, 该代码生成规则和流程控制规则也可以是预 先设置好的, 在本次代码生成中可以进行重复使用或可以进行编辑的。 步骤 S204: 用户输入数据控制流程和数据源文件。 本步骤中, 用户可以通过 UI界面输入数据控制流程和数据源文件。 但不限于此, 在实际使用中, 用户也可以采用其它任意适当方式输入数据控制流程和数据源文件。 其中, 数据控制流程主要包括: 代码数据处理流程、 输入输出参数、 和代码调用 顺序。 数据控制流程可以包括上述全部, 也可以包括其中之一或部分。 步骤 S206: 使用流程控制规则解析用户输入的数据控制流程, 获得流程控制源文 件。 本步骤中, 在用户输入数据控制流程后, 系统使用解释性语言编写的流程控制规 则对数据控制流程进行解析, 获得流程控制源文件。其中, 流程控制源文件可以包括: 函数名、 函数调用信息、 和函数实现。 函数实现可以以空函数预先填充。 步骤 S208: 通过基于正则表达式的源文件数据驱动引擎, 对数据源文件和流程控 制文件进行匹配, 获取数据源文件的关键信息和流程控制文件的关键信息。 源文件数据驱动引擎主要用于对数据源文件和流程控制源文件的解析, 其通过解 释性语言的正则表达式功能, 对数据源文件和流程控制源文件进行匹配, 提取关键信 息, 进而交由后续流程进行处理。 其中, 对数据源文件和流程控制源文件进行匹配的关键是采用正则表达式, 对数 据源文件和流程控制源文件进行关键字的提取和匹配,正则表达式(regular expression) 就是用一个"字符串 "来描述一个特征, 然后去验证另一个"字符串"是否符合这个特征。 比如, 表达式 "ab+" 描述的特征是 "一个 'a' 和 任意个 'b' ", 那么 'ab', 'abb', 'abbbbbbbbbb' 都符合这个特征。 当查找到符合预期的关键字时, 也就是匹配成功, 则 将关键信息进行提取。 其中, 关键信息包含: 函数名、 函数调用信息、 函数中数据类型的组成、 以及函 数输入参数和输出参数。 关键信息的作用是为后续生成代码使用, 代码的组成分成两 类: (1 )数据结构: 包括函数类型, 参数类型, 结构体变量构成, 类结构; (2)算法: 包括输入输出参数顺序, 函数调用顺序。 步骤 S210: 根据数据源文件的关键信息和流程控制文件的关键信息, 使用代码生 成规则生成代码。 本步骤中, 若系统中配置有默认的待生成的代码语言类型 (如 JAVA), 则可以将 数据源文件的关键信息和流程控制源文件的关键信息进行转化, 按照默认的代码语言 类型风格生成代码。 优选地, 可以提前配置不同的待生成的代码语言类型, 如在步骤 S202中配置, 则 在生成代码时, 按照不同的代码语言类型风格生成不同类型的代码。 优选地,可以根据不同的待生成的代码语言类型, 配置编写不同的代码生成规则, 则在生成代码时, 按照不同的代码语言类型风格, 选择相对应的代码生成规则生成代 码。 优选地, 还可以使用解释性语言自带的语法检查工具对生成的代码进行有效性检 查, 以提高代码生成效率和正确性。 通过本实施例, 用户可以通过 "所见即所得 "的用户界面输入解释性语言编写的代 码生成规则和流程控制规则, 进而使用该代码生成规则和流程控制规则对用户输入的 数据控制流程和数据源文件进行解析, 进而生成所需的代码, 从而有效解决了现有技 术的代码生成工具在生成代码时不够灵活的问题, 达到了增强代码生成工具灵活性的 效果。 实施例三 参照图 3, 示出了根据本发明实施例三的一种代码生成方法的步骤流程图。 本实施例的代码生成方法包括以下步骤 S302至步骤 S318。 步骤 S302: 用户通过 UI界面进行输入, 输入项包括: 配置代码生成规则、 流程 控制规则、 和欲生成的代码语言类型。 然后, 利用提供的图形模型对欲生成的代码数 据处理流程、输入输出参数、代码调用顺序进行描述和控制, 在 UI界面上完成对生成 代码的描述, 即在"所见即所得"的显示模式下进行上述输入 (即输入数据控制流程和 数据源文件)。 步骤 S304: 通过读取配置的流程控制规则, 选择对应的流程控制解析模式。 其中, 流程控制规则采用解释性语言进行编写, 由于是非编译性语言, 因此可以 做到进行实时更改和重新配置, 以适应不同用户的需求。 步骤 S306: 根据读取的流程控制规则, 对用户输入的数据控制流程进行解析。 其中, 主要解析项为输入输出参数, 函数调用顺序等信息。 步骤 S308: 生成流程控制源文件。 其中, 该流程控制源文件描述了用户准备生成代码的整体架构和控制流程, 包括 函数名, 函数调用信息, 函数实现以空函数预先填充。 步骤 S310: 获取数据源文件。 其中, 数据源文件也可动态实时配置, 是代码生成中的具体信息部分。 数据源文 件中包含了生成代码中具体数据结构的构成, 数据类型等。 步骤 S312: 解析数据源文件和流程控制源文件。 本步骤中, 通过解释性语言的正则表达式功能, 对数据源文件和流程控制源文件 进行匹配, 提取关键信息。 步骤 S314: 选择对应的代码生成规则。 该代码生成规则也采用解释性语言进行描述,因此可以对描述规则进行动态更改, 将数据源文件和流程控制源文件中的关键信息进行转化。 系统中携带有多种语言工具, 在根据代码语言类型生成代码时, 若存在多个相应 的代码生成规则, 则可以按照不同的语言类型风格, 选择不同的代码生成规则进行转 化; 若仅存在一个代码生成规则, 则可以交由该代码生成规则进行判断选择, 进而调 用不同的语言生成工具生成不同语言类型的代码。 步骤 S316: 按照选择的代码生成规则进行代码生成, 并且进行代码有效性检查。 在进行代码有效性检查时, 可以利用解释性语言 (如 PERL脚本语言) 自带的语 法检查工具进行基本的语法校验, 以提高代码生成工具代码转换的效率和正确性。 步骤 S318: 根据用户选择的代码语言类型, 生成对应类型的代码文件, 提示用户 代码生成完毕。 通过本实施例, 数据流程控制规则、 代码生成规则以及数据源文件都可以使用解 释性语言进行动态地配置和更改, 大大增强了代码生成工具的灵活性, 便于代码生成 工具的升级和维护, 降低了软件的后期使用成本。 实施例四 参照图 4, 示出了根据本发明实施例四的一种代码生成系统的结构框图。 本实施例的代码生成系统包括: 第一获取模块 402, 设置为获取用户使用解释性 语言配置的代码生成规则和流程控制规则; 数据流程解析引擎 404, 设置为使用流程 控制规则解析用户输入的数据控制流程, 获得流程控制源文件; 生成模块 406, 设置 为根据流程控制源文件和用户输入的数据源文件, 使用代码生成规则生成代码。 优选地, 生成模块 406包括:源文件数据驱动引擎 4062,设置为通过正则表达式, 对数据源文件和流程控制源文件进行匹配, 获取数据源文件的关键信息和流程控制源 文件的关键信息; 模式匹配模块 4064, 设置为根据数据源文件的关键信息和流程控制 源文件的关键信息, 使用代码生成规则生成代码。 其中,源文件数据驱动引擎 4062对数据源文件和流程控制源文件进行匹配的关键 是采用正则表达式, 对数据源文件和流程控制源文件进行关键字的提取和匹配, 当查 找到符合预期的关键字时, 也就是匹配成功, 则将关键信息进行提取。关键信息包含: 函数名、 函数调用信息、 函数中数据类型的组成、 以及函数输入参数和输出参数。 优选地, 代码生成规则包括多个, 生成模块 406包括: 第二获取模块 4066, 设置 为获取用户配置的待生成的代码语言类型; 代码生成模块 4068, 设置为根据数据源文 件的关键信息和流程控制源文件的关键信息, 以及获取的代码语言类型, 使用相应的 代码生成规则生成代码。 优选地, 本实施例的代码生成系统还包括: 检查模块 408, 设置为使用解释性语 言自带的语法检查工具, 对生成的代码进行有效性检查。 优选地, 数据控制流程包括以下至少之一: 代码数据处理流程、 输入输出参数、 代码调用顺序。 优选地, 流程控制源文件包括函数名、 函数调用信息、 和函数实现, 其中, 函数 实现以空函数预先填充。 本实施例实现的方法可以参照前述实施例的相关描述, 并具有上述实施例的有益 效果, 在此不再赘述。 通过本实施例, 采用解释性语言配置代码生成规则和流程控制规则, 充分利用了 解释性语言解释执行的特点, 使得用户可以根据需求, 在代码生成过程中灵活配置代 码生成规则和流程控制规则, 生成符合用户需求的代码文件, 从而解决了现有技术的 代码生成工具在生成代码时不够灵活的问题, 进而达到了增强代码生成工具灵活性的 效果。 实施例五 参照图 5, 示出了根据本发明实施例五的一种代码生成系统的结构框图。 本实施例的代码生成系统, 包括 UI输入模块 502、 数据流程解析引擎 504、 源文 件数据驱动引擎 506、 模式匹配模块 508、 代码生成模块 510。 其中: UI输入模块 502, 主要用于提供 UI界面接收用户输入, 包括配置信息输 入接口和界面显示模块。 其中, 通过配置信息输入接口输入的信息主要包含代码生成 规则、流程控制规则、 生成的代码语言类型。其中代码生成规则影响代码的数据结构, 流程控制规则影响代码的算法, 生成的代码语言类型决定生成的代码语言规范格式, 比如生成 C还是 JAVA语言; 界面显示模块主要用于接收和显示用户对输入参数的控 制, 用户通过界面显示模块, 可以对配置信息输入接口的参数进行修改和查看。 用户通过 UI输入模块 502, 首先使用解释性语言配置代码生成规则、 流程控制规 贝1」、 及欲生成的代码语言类型, 然后利用提供的图形模型对欲生成的代码数据处理流 程, 输入输出参数, 代码调用顺序进行描述和控制, 即输入数据控制流程及数据源文 件。 并且, 在用户输入后, 获取用户输入的上述信息, 包括代码生成规则、 流程控制 规则、 欲生成的代码语言类型、 数据控制流程及数据源文件 (相当于实施例四中的第 一获取模块 402)。 数据流程解析引擎 504,主要用于解析用户通过 UI输入模块 502输入的代码数据 处理流程, 输入输出参数, 代码调用顺序等信息, 即通过输入的流程控制规则解析输 入的数据控制流程。 流程控制规则可以通过解释性语言如脚本语言进行动态设置, 从 而达到对不同需求, 不同语言类型的支持, 解析完毕后生成流程控制源文件。 源文件数据驱动引擎 506, 主要用于对数据源文件和流程控制源文件的解析, 其 通过解释性语言的正则表达式功能, 对数据源文件和流程控制源文件进行匹配, 提取 关键信息, 进而交由模式匹配模块 508进行处理。 模式匹配模块 508, 主要功能是根据用户配置的代码生成规则, 欲生成的代码语 言类型, 选择对应的匹配模式来匹配源文件数据驱动引擎下发的数据源文件和流程控 制源文件关键信息, 传递给代码生成模块 510进行代码生成。 代码生成模块 510, 该模块为多语言类型的代码生成模块, 其按照模式匹配模块 508 传下来的代码生成配置信息, 将数据源文件的关键信息转化为代码, 根据流程控 制源文件的关键信息来生成代码调用流程, 从而完成代码的生成。 通过本实施例提供的上述基于脚本控制的动态可视代码生成系统, 包含了流程控 制规则配置脚本, 数据源文件, 代码生成规则配置脚本, 对数据流程控制规则和代码 生成规则以及数据源文件都可以进行动态的配置和更改, 从而大大增强了该代码生成 工具的灵活性, 对于代码生成工具的升级和维护, 降低软件的后期使用成本上具有明 显的优势。 从以上的描述中, 可以看出, 本发明基于目前业界两类主流的代码生成工具存在 的缺陷, 提供了一种基于脚本控制的动态可视代码生成方法及系统, 利用脚本语言的 正则表达式构造了数据流程解析引擎, 源文件数据驱动引擎。 从而可以通过实时修改 脚本语言, 利用数据流程解析引擎, 解析 UI可视图形界面, 动态生成数据源文件和流 程控制源文件, 配置基于正则表达式的源文件数据驱动引擎, 完成对数据源文件和流 程控制源文件动态生成代码的流程。 本发明利用了脚本语言为解释执行的特点, 可以 实现实时, 动态修改匹配规则, 从而极大提高了代码生成工具的灵活性。 同时, 利用 基于正则表达式的动态代码生成方法, 可以极大提高代码生成工具的鲁棒性和效率, 可以实时针对源文件的数据特征, 修正源文件数据驱动引擎, 从而降低了维护代码生 成工具的成本, 由于可生成代码的多样性, 也扩展了代码生成工具的应用范围。 显然, 本领域的技术人员应该明白, 上述的本发明的各模块或各步骤可以用通用 的计算装置来实现, 它们可以集中在单个的计算装置上, 或者分布在多个计算装置所 组成的网络上, 可选地, 它们可以用计算装置可执行的程序代码来实现, 从而, 可以 将它们存储在存储装置中由计算装置来执行, 并且在某些情况下, 可以以不同于此处 的顺序执行所示出或描述的步骤, 或者将它们分别制作成各个集成电路模块, 或者将 它们中的多个模块或步骤制作成单个集成电路模块来实现。 这样, 本发明不限制于任 何特定的硬件和软件结合。 以上所述仅为本发明的优选实施例而已, 并不用于限制本发明, 对于本领域的技 术人员来说, 本发明可以有各种更改和变化。 凡在本发明的精神和原则之内, 所作的 任何修改、 等同替换、 改进等, 均应包含在本发明的保护范围之内。 TECHNICAL FIELD The present invention relates to the field of communications, and in particular to a code generation method and system. BACKGROUND OF THE INVENTION Traditional code generation tools are mainly divided into two categories, one is a Microsoft Foundation Classes (MFC) compiler environment provided by Microsoft Virtual Studio, and a visual graphical interface operation mode is adopted. The built-in graphics parsing module converts the graphical interface built by the user into C++ code according to the built-in graphics parsing module, and generates the corresponding application by compiling the link. The industry calls it the "what you see is what you get" mode. The advantage of this mode is that it uses the MFC integrated compilation environment, which reduces the entry requirements for programmers and can bring products to market faster, but the disadvantages are also obvious. The first is the built-in graphics parsing module parsing mode is fixed mode, user Code generation can only be performed according to the built-in parsing method of MFC, so it can't respond quickly to different needs of users, code generation rules can't be configured, code generation means is too single, and there are major flaws in the flexibility of code generation mode. Therefore, there are inherent shortcomings in the development of large-scale software and the need to meet the code requirements of high-quality software products, which limits the use and promotion of MFC. Therefore, the current large-scale software development in the industry does not use MFC. The other is the transcoding tool represented by Ericsson APG40 and ASN1C of IMAG, which is used for data decoding of complex communication protocols. By extracting the key fields in the communication protocol and using the script to perform rule matching, ASN can be well solved. Code generation for a .1 type communication protocol codec. The feature of this type of code generation tool is to increase the flexibility and scope of the code generation tool by importing different communication protocol description files. The defect is mainly that the code generation rules are still not real-time configuration, and the new protocol specification is not compatible, and the code generation is Tool upgrade and maintenance costs are too high, so promotion is difficult. It can be seen that no matter which of the above code generation tools, the code generation rules are fixed when generating the code, and the user's need for flexible configuration of the code generation rules cannot be satisfied. SUMMARY OF THE INVENTION The present invention provides a code generation method and system to at least solve the problem that the above-described prior art code generation tool is not flexible when generating code. According to an aspect of the present invention, a code generation method is provided, including: acquiring a code generation rule and a flow control rule that a user uses an interpreted language configuration; and using a flow control rule to parse a data control flow input by a user to obtain a flow control source file ; Generate code using code generation rules based on the process control source file and user-entered data source files. Preferably, the step of generating code by using the code generation rule according to the flow control source file and the data source file input by the user includes: driving the engine by using a source file data based on a regular expression The source file and the process control source file are matched, the key information of the data source file and the key information of the process control source file are obtained; the key information of the source file is controlled according to the key information and the process of the data source file, and the code is used. Generate rule generation code. Preferably, the code generation rule includes multiple, the step of generating the code by using the code generation rule includes: acquiring a code language type to be generated configured by the user; and selecting a corresponding code generation according to the code language type Rule generation code. Preferably, the data control flow includes at least one of the following: a code data processing flow, an input and output parameter, and a code calling sequence. Preferably, the flow control source file includes a function name, function call information, and a function implementation, wherein the function implementation is pre-filled with an empty function. Preferably, the above method further comprises: performing validity checking on the generated code by using a grammar checking tool provided by the explanatory language. According to another aspect of the present invention, a code generation system is provided, including: a first acquisition module configured to acquire a code generation rule and a flow control rule that a user uses an interpreted language configuration; a data flow analysis engine, configured to use a flow The control rule parses the data control flow input by the user, obtains the process control source file, and generates a module, which is set to control the source file and the data source file input by the user according to the process, and generate code by using the code generation rule. Preferably, the generating module includes: a source file data driving engine, configured to match the data source file and the flow control source file by using a regular expression, and obtain key information and a process control source file of the data source file. The key information; the pattern matching module is configured to control the key information of the source file according to the key information and the process of the data source file, and generate the code by using the code generation rule. Preferably, the code generation rule includes a plurality, the generation module includes: a second acquisition module, configured to acquire a code language type to be generated configured by the user; and a code generation module configured to be according to the data source file The key information and process control key information of the source file, as well as the type of code language obtained, are generated using the corresponding code generation rules. Preferably, the apparatus further includes: an checking module, configured to perform a validity check on the generated code by using a grammar checking tool provided in the interpreted language. Through the invention, the code generation rule and the flow control rule are configured by using an explanatory language, and the features of the explanatory language interpretation execution are fully utilized, so that the user can flexibly configure the code generation rule and the flow control rule in the code generation process according to the requirements, and generate The code file that meets the user's requirements solves the problem that the prior art code generation tool is not flexible when generating the code, thereby achieving the effect of enhancing the flexibility of the code generation tool. BRIEF DESCRIPTION OF THE DRAWINGS The accompanying drawings, which are set to illustrate,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, BRIEF DESCRIPTION OF THE DRAWINGS FIG. 1 is a flow chart showing the steps of a code generating method according to a first embodiment of the present invention; FIG. 2 is a flow chart showing the steps of a code generating method according to a second embodiment of the present invention; FIG. 4 is a structural block diagram of a code generating system according to Embodiment 4 of the present invention; FIG. 5 is a block diagram of a code generating system according to Embodiment 5 of the present invention; Structure diagram. BEST MODE FOR CARRYING OUT THE INVENTION Hereinafter, the present invention will be described in detail with reference to the accompanying drawings. It should be noted that the embodiments in the present application and the features in the embodiments may be combined with each other without conflict. Embodiment 1 Referring to FIG. 1, a flow chart of steps of a code generating method according to Embodiment 1 of the present invention is shown. The code generating method of this embodiment includes the following steps S102 to S106. Step S102: Obtain a code generation rule and a flow control rule that the user uses the interpreted language configuration. In this embodiment, the code generation rule and the flow control rule are written by the user in an explanatory language, and are flexibly configured as needed. Interpretive languages such as scripting languages do not need to be compiled, and can be interpreted and executed, so that users can configure code generation rules and process control rules in real time and dynamically. Step S104: Parse the data control flow input by the user by using the flow control rule, and obtain the flow control source file. In this step, the data control flow input by the user is parsed using the flow control rules written in the explanatory language, and the flow control source file is acquired to control the flow of the generated code. Step S106: The code generation rule generates the code according to the flow control source file and the data source file input by the user. In this step, the code generation rules written in the explanatory language are used to parse and convert the process control source file and the data source file input by the user, and finally generate the code. In the related art, the code generation tool is not flexible enough when generating code. Through the embodiment, the code generation rule and the flow control rule are configured by the interpreted language, and the features of the explanatory language interpretation execution are fully utilized, so that the user can flexibly configure the code generation rule and the flow control rule in the code generation process according to the requirements. The generation of a code file that meets the user's requirements solves the problem that the prior art code generation tool is not flexible when generating the code, thereby achieving the effect of enhancing the flexibility of the code generation tool. Embodiment 2 Referring to FIG. 2, a flow chart of steps of a code generating method according to Embodiment 2 of the present invention is shown. The code generation method of this embodiment includes the following steps S202 to S210. Step S202: The user configures the code generation rule and the flow control rule using an interpreted language. In this step, the user can write the input code generation rules and the flow control rules in an explanatory language through an input interface, such as a user interface UI interface. Of course, the code generation rules and flow control rules can also be pre-set, and can be reused or edited in this code generation. Step S204: The user inputs a data control flow and a data source file. In this step, the user can input the data control process and the data source file through the UI interface. However, it is not limited thereto. In actual use, the user may also input the data control flow and the data source file by any other suitable means. Among them, the data control process mainly includes: code data processing flow, input and output parameters, and code calling sequence. The data control flow may include all of the above, and may also include one or a part thereof. Step S206: Parse the data control flow input by the user by using the flow control rule to obtain the flow control source file. In this step, after the user inputs the data control flow, the system analyzes the data control flow by using the flow control rule written in the explanatory language to obtain the flow control source file. The process control source file may include: a function name, a function call information, and a function implementation. Function implementations can be pre-populated with empty functions. Step S208: Matching the data source file and the process control file by using the source file data driving engine based on the regular expression to obtain key information of the data source file and key information of the process control file. The source file data driver engine is mainly used for parsing data source files and process control source files. It matches the data source files and process control source files through the regular expression function of the explanatory language, extracts key information, and then submits the key information. Subsequent processes are processed. Among them, the key to matching the data source file and the flow control source file is to use regular expressions to extract and match keywords in the data source file and the flow control source file. The regular expression uses a "character" The string "describes a feature, and then verifies that another "string" conforms to this feature. For example, the expression "ab+" describes the feature "one 'a' and any 'b'", then 'ab', 'abb', 'abbbbbbbbbb' all conform to this feature. When a keyword that meets expectations is found, that is, if the match is successful, the key information is extracted. Among them, the key information includes: function name, function call information, the composition of the data type in the function, and function input parameters and output parameters. The key information is used for subsequent generation of code. The composition of the code is divided into two categories: (1) Data structure: including function type, parameter type, structure variable composition, class structure; (2) Algorithm: including input and output parameter order, Function call order. Step S210: Generate code according to the key information of the data source file and the key information of the process control file, and use the code generation rule. In this step, if the default code language type to be generated (such as JAVA) is configured in the system, the key information of the data source file and the key information of the process control source file may be converted, and generated according to the default code language type style. Code. Preferably, different code language types to be generated may be configured in advance, as configured in step S202, and different types of code are generated according to different code language type styles when generating the code. Preferably, different code generation rules may be configured according to different code language types to be generated, and when the code is generated, the corresponding code generation rule generation code is selected according to different code language type styles. Preferably, the generated code can also be checked for validity by using a grammar checking tool provided by the interpretive language to improve code generation efficiency and correctness. Through this embodiment, the user can input code generation rules and flow control rules written in an interpreted language through a "what you see is what you get" user interface, and then use the code generation rules and flow control rules to control the flow of data and data input by the user. The source file is parsed to generate the required code, which effectively solves the problem that the prior art code generation tool is not flexible when generating the code, and achieves the effect of enhancing the flexibility of the code generation tool. Embodiment 3 Referring to FIG. 3, a flow chart of steps of a code generating method according to Embodiment 3 of the present invention is shown. The code generating method of this embodiment includes the following steps S302 to S318. Step S302: The user inputs through the UI interface, where the input items include: a configuration code generation rule, a flow control rule, and a code language type to be generated. Then, using the provided graphic model to describe and control the code data processing flow, input and output parameters, and code calling sequence to be generated, and complete the description of the generated code on the UI interface, that is, in the "what you see is what you get" display mode. Perform the above input (ie input data control flow and data source file). Step S304: Select a corresponding flow control analysis mode by reading the configured flow control rule. Among them, the flow control rules are written in an interpretive language. Because it is a non-compiled language, real-time changes and reconfigurations can be made to suit the needs of different users. Step S306: Parse the data control flow input by the user according to the read flow control rule. Among them, the main parsing items are information such as input and output parameters, function call order, and so on. Step S308: Generate a flow control source file. The process control source file describes the overall architecture and control flow that the user is ready to generate code, including the function name, function call information, and the function implementation is pre-populated with an empty function. Step S310: Acquire a data source file. Among them, the data source file can also be dynamically and real-time configured, which is the specific information part of the code generation. The data source file contains the composition, data type, etc. of the specific data structure in the generated code. Step S312: Parsing the data source file and the flow control source file. In this step, the data source file and the process control source file are matched by the regular expression function of the explanatory language, and the key information is extracted. Step S314: Select a corresponding code generation rule. The code generation rules are also described in an interpreted language, so the description rules can be dynamically changed to transform the key information in the data source files and process control source files. The system carries multiple language tools. When generating code according to the code language type, if there are multiple corresponding code generation rules, you can select different code generation rules according to different language type styles; if there is only one Code generation rules can be passed to the code generation rules for decision selection, and then different language generation tools are invoked to generate code of different language types. Step S316: Code generation is performed according to the selected code generation rule, and code validity check is performed. In the code validity check, you can use the syntax check tool that comes with an interpreted language (such as the PERL scripting language) to perform basic syntax checking to improve the efficiency and correctness of code generation tool code conversion. Step S318: Generate a code file of a corresponding type according to the code language type selected by the user, and prompt the user that the code is generated. Through this embodiment, data flow control rules, code generation rules, and data source files can be dynamically configured and changed using an interpreted language, which greatly enhances the flexibility of the code generation tool, facilitates the upgrade and maintenance of the code generation tool, and reduces The late use cost of the software. Embodiment 4 Referring to FIG. 4, a block diagram of a code generation system according to Embodiment 4 of the present invention is shown. The code generation system of this embodiment includes: a first obtaining module 402 configured to acquire a code generation rule and a flow control rule configured by the user using an interpreted language; and a data flow analysis engine 404 configured to parse the data input by the user using the flow control rule The control process obtains the process control source file; the generating module 406 is configured to generate the code by using the code generation rule according to the process control source file and the data source file input by the user. Preferably, the generating module 406 includes: a source file data driving engine 4062, configured to match the data source file and the process control source file by using a regular expression, and obtain key information of the data source file and key information of the process control source file; The pattern matching module 4064 is configured to control key information of the source file according to key information and processes of the data source file, and generate code by using a code generation rule. The key of the source file data driving engine 4062 to match the data source file and the flow control source file is to use a regular expression to extract and match keywords of the data source file and the process control source file, when the search is found to meet expectations. When the keyword is successful, the key information is extracted. The key information includes: function name, function call information, the composition of the data type in the function, and function input parameters and output parameters. Preferably, the code generation rule includes a plurality, and the generating module 406 includes: a second obtaining module 4066, configured to acquire a code language type to be generated configured by the user; and a code generating module 4068, configured to be based on key information and processes of the data source file Control the key information of the source file, as well as the type of code language obtained, and generate the code using the appropriate code generation rules. Preferably, the code generating system of this embodiment further includes: an checking module 408, configured to perform a validity check on the generated code by using a syntax checking tool provided in the explanatory language. Preferably, the data control flow comprises at least one of the following: a code data processing flow, an input and output parameter, and a code calling sequence. Preferably, the flow control source file includes a function name, function call information, and a function implementation, wherein the function implementation is pre-populated with an empty function. The method implemented in this embodiment can refer to the related description of the foregoing embodiment, and has the beneficial effects of the foregoing embodiments, and details are not described herein again. Through the embodiment, the code generation rule and the flow control rule are configured by the interpreted language, and the features of the explanatory language interpretation execution are fully utilized, so that the user can flexibly configure the code generation rule and the flow control rule in the code generation process according to the requirements. The generation of a code file that meets the user's requirements solves the problem that the prior art code generation tool is not flexible when generating the code, thereby achieving the effect of enhancing the flexibility of the code generation tool. Embodiment 5 Referring to FIG. 5, a block diagram of a code generation system according to Embodiment 5 of the present invention is shown. The code generation system of this embodiment includes a UI input module 502, a data flow analysis engine 504, a source file data drive engine 506, a pattern matching module 508, and a code generation module 510. The UI input module 502 is mainly configured to provide a UI interface to receive user input, including a configuration information input interface and an interface display module. The information input through the configuration information input interface mainly includes code generation rules, flow control rules, and generated code language types. The code generation rule affects the data structure of the code, the flow control rule affects the code algorithm, and the generated code language type determines the generated code language specification format, such as generating C or JAVA language; the interface display module is mainly used for receiving and displaying user input. Parameter control, the user can modify and view the parameters of the configuration information input interface through the interface display module. Through the UI input module 502, the user first uses the explanatory language configuration code generation rule, the flow control rule 1", and the code language type to be generated, and then uses the provided graphic model to input the output parameter to the code data processing flow to be generated. The code call sequence is described and controlled, that is, the input data control flow and the data source file. And, after the user inputs, acquiring the foregoing information input by the user, including a code generation rule, a flow control rule, a code language type to be generated, a data control process, and a data source file (corresponding to the first obtaining module 402 in the fourth embodiment) ). The data flow analysis engine 504 is mainly used to parse the code data processing flow input by the UI input module 502, input and output parameters, code calling sequence and the like, that is, the input data control flow is parsed through the input flow control rule. Process control rules can be dynamically set through an interpreted language such as a scripting language to support different requirements and different language types. After the analysis is completed, the process control source file is generated. The source file data driving engine 506 is mainly used for parsing data source files and process control source files, and matching the data source files and the process control source files through the regular expression function of the explanatory language to extract key information, and further The processing is performed by the pattern matching module 508. The pattern matching module 508, the main function is based on the user-configured code generation rules, the type of the code language to be generated, and the corresponding matching pattern is selected to match the data source file and the process control source file key information delivered by the source file data driving engine, and the key information is transmitted. Code generation is performed for code generation module 510. The code generation module 510 is a multi-language type code generation module that generates configuration information according to the code passed by the pattern matching module 508, converts key information of the data source file into code, and controls key information of the source file according to the process. Generate a code call flow to complete the code generation. The above-mentioned script-based dynamic visual code generation system provided by the embodiment includes a flow control rule configuration script, a data source file, a code generation rule configuration script, a data flow control rule, a code generation rule, and a data source file. Dynamic configuration and changes can be made, which greatly enhances the flexibility of the code generation tool. It has obvious advantages in upgrading and maintaining the code generation tool and reducing the software's post-use cost. From the above description, it can be seen that the present invention is based on the shortcomings of two mainstream code generation tools in the industry, and provides a dynamic visual code generation method and system based on script control, using regular expressions of a scripting language. The data flow analysis engine and the source file data drive engine are constructed. Therefore, the script language can be modified in real time, the data flow analysis engine is utilized, the UI visual graphical interface is parsed, the data source file and the flow control source file are dynamically generated, the source file data driving engine based on the regular expression is configured, and the data source file is completed. The flow of process control source files to dynamically generate code. The invention utilizes the script language as the characteristic of the interpretation execution, and can realize the real-time and dynamic modification of the matching rules, thereby greatly improving the flexibility of the code generation tool. At the same time, using the dynamic code generation method based on regular expressions, the robustness and efficiency of the code generation tool can be greatly improved, and the source file data driving engine can be corrected for the data characteristics of the source file in real time, thereby reducing the maintenance code generation tool. The cost, because of the variety of code that can be generated, also extends the scope of application of the code generation tool. Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general-purpose computing device, which can be concentrated on a single computing device or distributed over a network composed of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device, such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein. The steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module. Thus, the invention is not limited to any specific combination of hardware and software. The above is only the preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes can be made to the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and scope of the present invention are intended to be included within the scope of the present invention.

Claims

权 利 要 求 书 Claim
1. 一种代码生成方法, 包括: 1. A code generation method, comprising:
获取用户使用解释性语言配置的代码生成规则和流程控制规则; 使用所述流程控制规则解析所述用户输入的数据控制流程, 获得流程控制 源文件;  Obtaining a code generation rule and a flow control rule configured by the user using an interpreted language; using the flow control rule to parse the data control flow input by the user, and obtaining a flow control source file;
根据所述流程控制源文件和所述用户输入的数据源文件, 使用所述代码生 成规则生成代码。  The code generation rule is generated using the code generation source code and the user input data source file according to the flow.
2. 根据权利要求 1所述的方法, 其中, 所述根据所述流程控制源文件和所述用户 输入的数据源文件, 使用所述代码生成规则生成代码的步骤包括: 2. The method according to claim 1, wherein the step of generating a code using the code generation rule according to the flow control source file and the data source file input by the user comprises:
通过基于正则表达式的源文件数据驱动引擎, 对所述数据源文件和流程控 制源文件进行匹配, 获取所述数据源文件的关键信息和流程控制源文件的关键 信息;  Matching the data source file and the process control source file by using a source file data driving engine based on a regular expression, and acquiring key information of the data source file and key information of the process control source file;
根据所述数据源文件的关键信息和流程控制源文件的关键信息, 使用所述 代码生成规则生成代码。  Controlling the key information of the source file according to the key information and the process of the data source file, and generating the code by using the code generation rule.
3. 根据权利要求 1或 2所述的方法, 其中, 所述代码生成规则包括多个, 所述使 用所述代码生成规则生成代码的步骤包括: The method according to claim 1 or 2, wherein the code generation rule comprises a plurality of, the step of generating the code by using the code generation rule comprises:
获取所述用户配置的待生成的代码语言类型;  Obtaining a code language type to be generated by the user configuration;
根据所述代码语言类型选择相应的代码生成规则生成代码。  The corresponding code generation rule generation code is selected according to the code language type.
4. 根据权利要求 1所述的方法, 其中, 所述数据控制流程包括以下至少之一: 代 码数据处理流程、 输入输出参数、 代码调用顺序。 The method according to claim 1, wherein the data control flow comprises at least one of the following: a code data processing flow, an input and output parameter, and a code calling sequence.
5. 根据权利要求 1所述的方法, 其中, 所述流程控制源文件包括函数名、 函数调 用信息、 和函数实现, 其中, 所述函数实现以空函数预先填充。 The method according to claim 1, wherein the flow control source file comprises a function name, function call information, and a function implementation, wherein the function implementation is pre-filled with an empty function.
6. 根据权利要求 1所述的方法, 其中, 还包括: 6. The method according to claim 1, further comprising:
使用所述解释性语言自带的语法检查工具, 对生成的所述代码进行有效性 检查。  The generated code is checked for validity using the grammar checking tool that comes with the interpreted language.
7. 一种代码生成系统, 包括: 第一获取模块, 设置为获取用户使用解释性语言配置的代码生成规则和流 程控制规则; 7. A code generation system, comprising: a first obtaining module, configured to obtain a code generation rule and a flow control rule configured by the user using an interpreted language;
数据流程解析引擎, 设置为使用所述流程控制规则解析所述用户输入的数 据控制流程, 获得流程控制源文件;  a data flow parsing engine configured to parse the data control flow input by the user by using the flow control rule to obtain a flow control source file;
生成模块,设置为根据所述流程控制源文件和所述用户输入的数据源文件, 使用所述代码生成规则生成代码。 根据权利要求 7所述的系统, 其中, 所述生成模块包括: 源文件数据驱动引擎, 设置为通过正则表达式, 对所述数据源文件和流程 控制源文件进行匹配, 获取所述数据源文件的关键信息和流程控制源文件的关 键信息;  Generating a module, configured to control the source file and the data source file input by the user according to the flow, and generate the code using the code generation rule. The system according to claim 7, wherein the generating module comprises: a source file data driving engine configured to match the data source file and the flow control source file by using a regular expression to obtain the data source file Key information and process control key information for source files;
模式匹配模块, 设置为根据所述数据源文件的关键信息和流程控制源文件 的关键信息, 使用所述代码生成规则生成代码。 根据权利要求 7所述的系统, 其中, 所述代码生成规则包括多个, 所述生成模 块包括:  The pattern matching module is configured to control key information of the source file according to the key information and the process of the data source file, and generate the code by using the code generation rule. The system according to claim 7, wherein the code generation rule comprises a plurality, and the generation module comprises:
第二获取模块, 设置为获取所述用户配置的待生成的代码语言类型; 代码生成模块, 设置为根据所述数据源文件的关键信息和流程控制源文件 的关键信息, 以及获取的所述代码语言类型, 使用相应的代码生成规则生成代 码。 根据权利要求 7所述的系统, 其中, 还包括: 检查模块, 设置为使用所述解释性语言自带的语法检查工具, 对生成的所 述代码进行有效性检查。  a second obtaining module, configured to acquire a code language type to be generated configured by the user; a code generating module, configured to control key information of the source file according to key information and a process of the data source file, and the obtained code The language type, generated by the corresponding code generation rules. The system of claim 7, further comprising: an inspection module configured to perform a validity check on the generated code using a grammar checking tool provided in the interpreted language.
PCT/CN2012/076018 2011-09-02 2012-05-24 Code generating method and system WO2013029399A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201110258795.2A CN102289375B (en) 2011-09-02 2011-09-02 Code generating method and system
CN201110258795.2 2011-09-02

Publications (1)

Publication Number Publication Date
WO2013029399A1 true WO2013029399A1 (en) 2013-03-07

Family

ID=45335828

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2012/076018 WO2013029399A1 (en) 2011-09-02 2012-05-24 Code generating method and system

Country Status (2)

Country Link
CN (1) CN102289375B (en)
WO (1) WO2013029399A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109799985A (en) * 2019-01-23 2019-05-24 中国银行股份有限公司 Front-end code generation method and device, storage medium and electronic equipment

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102289375B (en) * 2011-09-02 2017-10-20 中兴通讯股份有限公司 Code generating method and system
CN102646035A (en) * 2012-02-17 2012-08-22 南京南瑞继保电气有限公司 Visualized code generation method based on combination of API (application programming interface) and script definition
CN103577166B (en) * 2012-07-25 2017-11-14 上海斐讯数据通信技术有限公司 OMCI coding methods and its device
CN107291522B (en) * 2016-04-11 2020-09-29 中国科学院信息工程研究所 Compiling optimization method and system for user-defined rule file
CN109388385B (en) * 2018-09-18 2022-08-19 西门子(中国)有限公司 Method and apparatus for application development
CN109325900A (en) * 2018-09-19 2019-02-12 北京润科通用技术有限公司 A kind of dispositions method and system of algorithm
CN109408049A (en) * 2018-10-13 2019-03-01 彭熹 A kind of method and system from natural language automatically generating program code
CN111124378B (en) * 2018-10-31 2024-02-13 北京国双科技有限公司 Code generation method and device
CN109509467B (en) * 2018-11-01 2022-06-24 北京车和家信息技术有限公司 Code generation method and device
CN111670091B (en) * 2018-12-25 2022-12-13 深圳配天智能技术研究院有限公司 Robot program instruction compiling method, robot control system and storage device
CN109947423A (en) * 2019-03-27 2019-06-28 北京字节跳动网络技术有限公司 Code generating method, device, terminal and medium
CN112698832B (en) * 2020-12-28 2024-02-13 东软集团股份有限公司 Method, device and equipment for identifying code change influence range
TWI783463B (en) * 2021-04-28 2022-11-11 博橡科技股份有限公司 Method for generating a human-machine interface, computer readable storage medium, computing device, and function operating device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6877155B1 (en) * 1994-09-30 2005-04-05 International Business Machines Corporation System and method for generating target language code utilizing an object oriented code generator
CN101645010A (en) * 2009-08-20 2010-02-10 深圳市珍爱网信息技术有限公司 System and method for automatically generating code
CN102289375A (en) * 2011-09-02 2011-12-21 中兴通讯股份有限公司 Code generation method and system

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100481001C (en) * 2006-01-17 2009-04-22 大唐移动通信设备有限公司 Interface automatic forming method and interface automatic forming system
CN100520716C (en) * 2007-08-28 2009-07-29 北京中企开源信息技术有限公司 Code automatically generating device based on model component, system and method
CN101604241A (en) * 2009-07-10 2009-12-16 杭州电子科技大学 A kind of code generating method of embedded system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6877155B1 (en) * 1994-09-30 2005-04-05 International Business Machines Corporation System and method for generating target language code utilizing an object oriented code generator
CN101645010A (en) * 2009-08-20 2010-02-10 深圳市珍爱网信息技术有限公司 System and method for automatically generating code
CN102289375A (en) * 2011-09-02 2011-12-21 中兴通讯股份有限公司 Code generation method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
CHEN, XIANG ET AL.: "Code Generating Implementation in Model Driven Architecture", APPLICATION RESEARCH OF COMPUTERS, vol. 1, 31 January 2006 (2006-01-31), pages 147 - 150 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109799985A (en) * 2019-01-23 2019-05-24 中国银行股份有限公司 Front-end code generation method and device, storage medium and electronic equipment

Also Published As

Publication number Publication date
CN102289375A (en) 2011-12-21
CN102289375B (en) 2017-10-20

Similar Documents

Publication Publication Date Title
WO2013029399A1 (en) Code generating method and system
CN105765527B (en) The method and apparatus of software development kit (SDK) for customization
CN105814539B (en) The method and apparatus generated for code virtualization and remote process call
CN109725897A (en) Software customized methods, devices and systems, terminal
CN107885590A (en) Task processing method and device for smart machine
WO2010091623A1 (en) Apparatus and method for dynamically generating application program interface
WO2011035663A1 (en) Method and device for constructing compiling system
JPH08202545A (en) Object-oriented system and method for generation of target language code
KR20120095372A (en) The method and device for development environment converting
WO2020199423A1 (en) Automated construction method and system for yang model configuration interface
CN107291522B (en) Compiling optimization method and system for user-defined rule file
CN110196720B (en) Optimization method for generating dynamic link library by Simulink
WO2023065629A1 (en) Dialogue management method and system, and terminal and storage medium
AU2008287331B2 (en) Voice enabled telnet interface
WO2015188463A1 (en) Ivr external interface configuration method and device, and computer storage medium
CN110362317B (en) Code conversion method, device and storage medium
CN107092474A (en) Program developing method, ETL processing method and processing devices
WO2012129864A1 (en) Method and system for expressing value-added service flow in the form of scripts
CN111596905A (en) Method, device, storage medium and terminal for generating java object
US20140046984A1 (en) Compact type layouts
US20050273774A1 (en) Method and system for flexible/extendable at command interpreter
US20220004526A1 (en) Method and apparatus of converting schema in deep learning framework, and computer storage medium
WO2022099913A1 (en) Interface configuration method and apparatus, and device and medium
CN112860244A (en) Graphical programming method and system
CN107832046A (en) Data creation method and device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 12828646

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 12828646

Country of ref document: EP

Kind code of ref document: A1