A domain-specific language design method, device, equipment and storage medium

By using regular expressions and language workbench detection in the rule engine, a package adaptable to any business domain can be generated, solving the problem of insufficient flexibility of the rule engine and enabling flexible operation and low-cost development in different environments.

CN114265582BActive Publication Date: 2026-05-01HANGZHOU DBAPPSECURITY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU DBAPPSECURITY CO LTD
Filing Date
2021-12-22
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

In existing technologies, the syntax rules of rule engine components are simple and cannot be adapted to various business domains. They also do not support extension and customization, have low flexibility, are difficult to develop, require a specified runtime environment, and have poor portability.

Method used

By determining the syntax rules based on the business logic of the target domain, writing the syntax rules using regular expressions, and using the language workbench for logic and scenario detection, a program package for the target runtime environment is generated.

Benefits of technology

It improves the flexibility of domain-specific language design, lowers the design threshold and development cost, and allows developers to complete syntax definitions without understanding implementation details. The package can run in any environment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114265582B_ABST
    Figure CN114265582B_ABST
Patent Text Reader

Abstract

The application discloses a domain-specific language design method, device, equipment and storage medium. The method comprises the following steps: determining a syntax rule corresponding to a target domain according to a business logic of the target domain; writing the syntax rule according to a regular expression to obtain a target syntax described based on the regular expression; and generating a program package under a target running environment based on the target syntax, so as to develop the business logic by using the program package. The syntax rule is written by using the regular syntax, is not limited by a predefined syntax, and can be customized according to any business domain. Meanwhile, the running program under any environment can be output by specifying the target running environment, so that the generated program package can run in any specified environment, and the flexibility of the domain-specific language design is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of domain-specific language technology, and in particular to a domain-specific language design method, apparatus, device, and storage medium. Background Technology

[0002] Domain-specific languages ​​(DSLs) are computer programming languages ​​that focus on a specific application domain and possess limited expressiveness. As programming languages, they are executable by computers and have coherent expressive capabilities, but they are only useful within a clearly defined, small domain. Their primary purpose is to solve functionalities within a specific domain. Examples of good DSL implementations include SQL (Structured Query Language) and HTML (Hypertext Markup Language). When building domain-specific software, it is often necessary to communicate implementation details with domain experts who are not developers. For instance, when building a medical application, it is necessary to communicate with doctors to understand the treatment methods that the accompanying software should recommend. DSLs aim to standardize the communication methods between developers and domain experts.

[0003] In existing technologies, rule engine components use predefined semantic modules to write business decisions, separating these decisions from application code. Domain experts or developers need to understand the predefined semantics and complete the writing and maintenance of business rules, which ultimately make the business decisions. However, rule engine components can only use predefined syntax, which is limited and cannot adapt to various business domains. Furthermore, they do not support extensions or customization, resulting in low flexibility. Additionally, rule engines require a specified runtime environment; for example, some rule engines require a Java environment, limiting portability. Moreover, customizing a rule engine based on the business domain is feasible, but implementing a complete rule engine requires extensive expertise, making development very difficult. Summary of the Invention

[0004] In view of this, the purpose of this invention is to provide a domain-specific language design method, apparatus, device, and medium, which can improve the flexibility of domain-specific language design. The specific solution is as follows:

[0005] Firstly, this application discloses a domain-specific language design method, including:

[0006] Based on the business logic of the target domain, determine the corresponding syntax rules for the target domain;

[0007] The syntax rules are written based on the regular expressions to obtain the target syntax described by the regular expressions;

[0008] Based on the target syntax, a program package is generated for the target runtime environment so that the program package can be used for business logic development.

[0009] Optionally, after writing the syntax rules based on the regular expression to obtain the target syntax described by the regular expression, the method further includes:

[0010] The target grammar is subjected to logical checks to determine whether its logic and syntax are correct.

[0011] If the logic and syntax are correct, then scenario detection is performed on the target syntax to detect whether the logic of the target syntax is correct in the target business scenario.

[0012] If the target syntax is logically correct in the target business scenario, then the step of generating the program package in the target runtime environment based on the target syntax and the target runtime environment is executed.

[0013] Optionally, the logical detection of the target syntax includes:

[0014] The syntax tree generator of the language workbench is used to generate a corresponding syntax tree based on the target syntax, so as to perform logical and grammatical checks on the target syntax according to the syntax tree;

[0015] The scene detection of the target grammar includes:

[0016] Using the simulation test environment module of the language workbench, the target syntax is run based on the target business scenario to generate running results, so as to perform scenario detection on the target syntax based on the running results.

[0017] Optionally, the step of generating a corresponding syntax tree based on the target syntax using the syntax tree generator of the language workbench includes:

[0018] Using the syntax tree generator of the language workbench, the target syntax is recursively parsed in the direction of the byte stream and regular expression matching is performed according to the pre-built method library to determine the function corresponding to each regular expression in the target syntax, so as to generate the syntax tree based on the function.

[0019] Optionally, the step of writing the syntax rules based on the regular expression to obtain the target syntax described by the regular expression includes:

[0020] The syntax rules are expressed using regular expressions in the language workbench's syntax editor, resulting in multiple regular expression syntaxes. Each regular expression syntax is then matched with a corresponding function to generate a method library corresponding to the syntax rules.

[0021] Optionally, after detecting whether the logic and syntax of the target grammar are correct, the method further includes:

[0022] If the logic and syntax of the target syntax are incorrect, the syntax rules are revised based on the detection results and the business logic.

[0023] After detecting whether the logic of the target syntax is correct in the target business scenario, the method further includes:

[0024] If the target syntax is logically incorrect in the target business scenario, the syntax rules will be revised based on the detection results and the business logic.

[0025] Optionally, generating the program package in the target runtime environment based on the target syntax includes:

[0026] Obtain the software runtime environment requirements, and determine the target runtime environment based on the software runtime environment requirements;

[0027] Using the specified environment code generation module of the language workbench, source code in the target runtime environment is generated based on the target syntax to obtain the program package.

[0028] Secondly, this application discloses a domain-specific language design apparatus, comprising:

[0029] The syntax rule determination module is used to determine the syntax rules corresponding to the target domain based on the business logic of the target domain;

[0030] The target syntax generation module is used to write the syntax rules based on the regular expression to obtain the target syntax described by the regular expression.

[0031] The package generation module is used to generate a package in the target runtime environment based on the target syntax, so as to use the package for business logic development.

[0032] Thirdly, this application discloses an electronic device, including:

[0033] Memory, used to store computer programs;

[0034] A processor for executing the computer program to implement the aforementioned domain-specific language design method.

[0035] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the aforementioned domain-specific language design method.

[0036] In this application, based on the business logic of the target domain, the corresponding syntax rules are determined; the syntax rules are written according to regular expressions to obtain a target syntax described by regular expressions; and a program package in the target runtime environment is generated based on the target syntax, so that the program package can be used for business logic development. It is evident that by using regular expressions to write syntax rules and describing syntax based on regular expressions, it is not limited by the predefined syntax of rule engines. Syntax rules can be customized according to any business domain. Furthermore, by describing a specific domain syntax based on regular expressions, requirements and developers only need to understand the regular expression syntax to complete the definition of a domain-specific language, without needing to understand the implementation details, thus reducing the design threshold and development cost. Simultaneously, by specifying the target runtime environment output, a program that can run in any environment can be output, so that the generated program package can run in any specified environment, improving the flexibility of domain-specific language design. Attached Figure Description

[0037] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0038] Figure 1 A flowchart of a domain-specific language design method provided in this application;

[0039] Figure 2 A flowchart illustrating a specific domain-specific language design method provided in this application;

[0040] Figure 3 This application provides a specific flowchart for syntax parsing and generation.

[0041] Figure 4 A specific language workbench structure diagram is provided for this application;

[0042] Figure 5 A schematic diagram of a domain-specific language design device provided in this application;

[0043] Figure 6 This application provides a structural diagram of an electronic device. Detailed Implementation

[0044] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0045] In existing technologies, business decisions are written using predefined semantic modules through rule engine components. However, this approach cannot adapt to various business domains, does not support extension and customization, and suffers from low flexibility and portability. To overcome these technical problems, this application proposes a domain-specific language design method based on regular expressions, which can improve the flexibility of domain-specific language design.

[0046] This application discloses a domain-specific language design method. See also Figure 1 As shown, the method may include the following steps:

[0047] Step S11: Determine the syntax rules corresponding to the target domain based on the business logic of the target domain.

[0048] In this embodiment, the syntax rules for the target domain are first formulated based on the business logic of the target domain. Specifically, the business logic can be determined by developers communicating directly with domain experts, and then the syntax rules for the domain-specific language of the target domain are formulated based on the business logic.

[0049] Step S12: Write the syntax rules based on the regular expression to obtain the target syntax described by the regular expression.

[0050] In this embodiment, after obtaining the above-mentioned syntax rules, the syntax rules are written according to regular expressions, that is, regular expressions are used to describe the syntax rules to obtain the target syntax described by the regular expressions. Developers can write the syntax regular expressions after meetings with domain personnel or during communication, striving for a direct translation of the syntax and business logic. It is understandable that regular expressions, as a text processing tool, have very strong flexibility and functionality, and can quickly achieve complex string control in a very simple way. Regular expressions can be well used to define DSLs.

[0051] In this embodiment, after writing the syntax rules based on regular expressions to obtain the target syntax described by the regular expressions, the process may further include: performing logical testing on the target syntax to check whether the logic and syntax of the target syntax are correct; if the logic and syntax are correct, performing scenario testing on the target syntax to check whether the logic of the target syntax is correct in the target business scenario; if the logic of the target syntax is correct in the target business scenario, then executing the step of generating a program package in the target runtime environment based on the target syntax according to the target runtime environment. That is, logical testing is performed on the edited syntax to ensure that the syntax is logically correct and unambiguous, guaranteeing that the syntax can work normally; then, specific business scenarios are determined through communication with domain experts, scenario testing is performed on the syntax program, and the results are fed back to the domain experts to ensure logical correctness in the business scenario.

[0052] In this embodiment, after detecting whether the logic and syntax of the target syntax are correct, it may further include: if the logic and syntax of the target syntax are incorrect, then revising the syntax rules according to the detection results and the business logic; after detecting whether the logic of the target syntax is correct in the target business scenario, it may further include: if the logic of the target syntax is incorrect in the target business scenario, then revising the syntax rules according to the detection results and the business logic. That is, for example... Figure 2 As shown, by continuously performing logic and scenario testing, and by constantly communicating with domain personnel to improve the grammar rules when problems arise, the target grammar is improved until there are no logical or grammatical issues.

[0053] In this embodiment, the logical detection of the target grammar may include: using the syntax tree generator of the language workbench to generate a corresponding syntax tree based on the target grammar, and then performing logical and grammatical detection on the target grammar according to the syntax tree. That is, the syntax tree corresponding to the target grammar is generated by the syntax tree generator of the language workbench, so that logical and grammatical detection of the target grammar can be performed using the aforementioned syntax tree.

[0054] In this embodiment, the scenario detection of the target grammar may include: using the simulation testing environment module of the language workbench to run the target grammar based on the target business scenario and generate running results, so as to perform scenario detection on the target grammar based on the running results. Specifically, the target grammar can be run in the target business scenario and running results can be generated through the simulation testing environment module of the language workbench, and then scenario detection can be performed on the target grammar based on the running results, thereby ensuring the logical correctness of the grammar in the business scenario.

[0055] In this embodiment, generating a corresponding syntax tree based on the target syntax using the syntax tree generator of the language workbench may include: recursively parsing the target syntax in the direction of the byte stream using the syntax tree generator of the language workbench and performing regular expression rule matching according to a pre-built method library to determine the function corresponding to each regular expression in the target syntax, so as to generate the syntax tree based on the function. In this embodiment, writing the syntax rules based on regular expressions to obtain the target syntax described by regular expressions may include: using the syntax editor of the language workbench to express the syntax rules using regular expressions to obtain multiple regular expressions, and matching a corresponding function for each regular expression to generate a method library corresponding to the syntax rules.

[0056] It is understandable that in this embodiment, the operating principle of the domain-specific language uses regular expressions to describe syntax rules (regex rules) for regular expression-based syntax descriptions. For example, in arithmetic operations, such as:

[0057] (1) Number: 32.55; can be described using regular expressions as: number = "\s*(\d+(\.\d+)?)\s*";

[0058] (2) Addition and subtraction: 45.23 + 327; Based on the above numbers, it can be described as: addOrSub = number 1 + "(+|-)" + number 2;

[0059] (3) Multiplication and division: 376*43.23; Similarly, it can be expressed as: mulOrDiv=number 3+“(*| / )”+number4;

[0060] Based on the above, by adding precedence and parentheses to continuously improve the regular expression logic, complex expressions such as 38*32-(43 / 32+43) can be finally expressed.

[0061] For defining a method library, a function is matched for each regular expression syntax, ultimately generating the method library. Let's take arithmetic calculations as an example.

[0062] (1) Numerical functions:

[0063] deftoNumber(str)=parserNumber(str)

[0064] (2) Addition and subtraction:

[0065]

[0066] (3) Multiplication and division:

[0067]

[0068] In this way, each rule can find its corresponding execution method.

[0069] For syntax parsing generation, for example Figure 3 As shown, a DSL Parser is generated by taking a DSL script as input. The parser recursively parses and matches regular expression rules as a byte stream, finds the corresponding function, and finally generates a syntax tree. Finally, the defined syntax rules are generated into a package for the corresponding working environment. Importing the package into the environment allows the parsing of the domain-specific language script, the generation of the syntax tree, and the calculation of the result.

[0070] In this embodiment, for example Figure 4 As shown, the aforementioned language workbench includes a syntax editor, a syntax tree generator, a simulated testing environment module, and a specified environment code generation module. The syntax editor is a regular expression-based syntax editor used for real-time compilation and verification of syntax. The syntax tree generator generates a syntax tree structure from the generated syntax rules in real-time, displaying it graphically to visually check syntax correctness. The simulated testing environment module allows users to run and generate results based on input test scenarios, verifying the correctness of the syntax in specific scenarios. The specified environment code generation module generates code based on the runtime environments of different programs; importing this code into a program provides language interpretation and execution capabilities. In essence, a domain-specific language workbench provides a dedicated IDE (Integrated Development Environment) for defining and building a DSL. It not only determines the language structure of the DSL but also serves as the editing environment for writing DSL scripts, ultimately helping us complete the DSL implementation. Building a DSL requires not only solid professional knowledge but also thorough verification and testing. A language workbench provides a complete working environment to help developers define and build DSLs. Through the workbench, DSL design and testing can be completed, and the output can be a package based on any language environment, working in different environments. Furthermore, in this embodiment, the DSL workbench is implemented based on regular expressions, meaning that anyone who understands regular expression syntax can easily complete DSL design on the workbench.

[0071] Step S13: Based on the target syntax, generate a program package in the target runtime environment so as to use the program package for business logic development.

[0072] In this embodiment, based on the aforementioned target syntax, a program package is generated according to the target runtime environment to facilitate business logic development. Specifically, by importing the output program package source code into the software engineering, business logic development based on a domain-specific language can be achieved. The business logic can be directly translated into domain-specific language scripts, allowing domain experts and developers to develop and test the business logic on the same language platform.

[0073] In this embodiment, generating a program package in the target runtime environment based on the target syntax may include: obtaining software runtime environment requirements; determining the target runtime environment based on the software runtime environment requirements; and using the specified environment code generation module of the language workbench to generate source code in the target runtime environment based on the target syntax to obtain the program package. That is, after determining the target syntax and verifying its correctness, the runtime environment is determined according to user needs, and an output program package is selected based on the target syntax and the software runtime environment; for example, Java source code is output for a Java environment. Therefore, in this embodiment, through the syntactic feature analysis of a domain-specific language, a domain-specific language is defined and constructed using regular expressions. Then, syntactic test cases are written to parse and test the edited specific language syntax, verifying its correctness. Finally, the edited specific language is generated into a program package that can run in a specified target environment, realizing domain-specific languages ​​for various specific domains under different business logics and different runtime environments.

[0074] As can be seen from the above, in this embodiment, the syntax rules corresponding to the target domain are determined based on the business logic of the target domain; the syntax rules are written according to regular expressions to obtain the target syntax described by regular expressions; and a program package in the target runtime environment is generated based on the target syntax to facilitate business logic development using the program package. It is evident that by using regular expressions to write syntax rules and describing syntax based on regular expressions, the limitations of predefined syntax in rule engines are eliminated. Syntax rules can be customized for any business domain. Furthermore, by describing domain-specific syntax based on regular expressions, requirements and developers only need to understand the regular expression syntax to complete the definition of the domain-specific language, without needing to understand the implementation details, thus reducing the design threshold and development cost. Simultaneously, by specifying the target runtime environment output, a program that can run in any environment can be output, allowing the generated program package to run in any specified environment, improving the flexibility of domain-specific language design.

[0075] Accordingly, embodiments of this application also disclose a domain-specific language design device, see [link to relevant documentation]. Figure 5 As shown, the device includes:

[0076] The syntax rule determination module 11 is used to determine the syntax rules corresponding to the target domain based on the business logic of the target domain.

[0077] The target syntax generation module 12 is used to write the syntax rules based on the regular expression to obtain the target syntax described by the regular expression.

[0078] The package generation module 13 is used to generate a package in the target runtime environment based on the target syntax and the target runtime environment, so as to use the package for business logic development.

[0079] As can be seen from the above, in this embodiment, the syntax rules corresponding to the target domain are determined based on the business logic of the target domain; the syntax rules are written according to regular expressions to obtain the target syntax described by regular expressions; and a program package in the target runtime environment is generated based on the target syntax to facilitate business logic development using the program package. It is evident that by using regular expressions to write syntax rules and describing syntax based on regular expressions, the limitations of predefined syntax in rule engines are eliminated. Syntax rules can be customized for any business domain. Furthermore, by describing domain-specific syntax based on regular expressions, requirements and developers only need to understand the regular expression syntax to complete the definition of the domain-specific language, without needing to understand the implementation details, thus reducing the design threshold and development cost. Simultaneously, by specifying the target runtime environment output, a program that can run in any environment can be output, allowing the generated program package to run in any specified environment, improving the flexibility of domain-specific language design.

[0080] In some specific embodiments, the domain-specific language design apparatus may specifically include:

[0081] A logic detection unit is used to perform logic detection on the target syntax to detect whether the logic and syntax of the target syntax are correct.

[0082] The scenario detection unit is used to perform scenario detection on the target syntax if the logic and syntax are correct, so as to detect whether the logic of the target syntax is correct in the target business scenario.

[0083] The package generation execution unit is used to execute the step of generating a package in the target runtime environment based on the target syntax if the logic of the target syntax is correct in the target business scenario.

[0084] In some specific embodiments, the logic detection unit may specifically include:

[0085] The syntax tree generation unit is used to generate a corresponding syntax tree based on the target syntax using the syntax tree generator of the language workbench, so as to perform logical and grammatical checks on the target syntax according to the syntax tree;

[0086] In some specific embodiments, the scene detection unit can be used to utilize the simulation test environment module of the language workbench to run the target syntax based on the target business scenario and generate running results, so as to perform scene detection on the target syntax based on the running results.

[0087] In some specific embodiments, the syntax tree generation unit may specifically include:

[0088] The parser generation unit is used to recursively parse the target syntax in the direction of the byte stream using the syntax tree generator of the language workbench and perform regular expression rule matching according to the pre-built method library to determine the function corresponding to each regular expression in the target syntax, so as to generate the syntax tree according to the function.

[0089] In some specific embodiments, the target grammar generation module 12 can be used to use the grammar editor of the language workbench to express the grammar rules using regular expressions, obtain multiple regular grammars, and match a corresponding function for each regular grammar to generate a method library corresponding to the grammar rules.

[0090] In some specific embodiments, the domain-specific language design apparatus may specifically include:

[0091] The first revision unit is used to revise the syntax rules based on the detection results and the business logic if the logic and syntax of the target syntax are incorrect.

[0092] The second revision unit is used to revise the syntax rules based on the detection results and the business logic if the target syntax is not logically correct in the target business scenario.

[0093] In some specific embodiments, the package generation module 13 may specifically include:

[0094] The target runtime environment determination unit is used to acquire software runtime environment requirements and determine the target runtime environment based on the software runtime environment requirements.

[0095] The source code generation unit is used to generate source code in the target runtime environment based on the target syntax using the specified environment code generation module of the language workbench, so as to obtain the program package.

[0096] Furthermore, this application also discloses an electronic device, see [link to relevant documentation]. Figure 6As shown, the content in the figure should not be considered as any limitation on the scope of use of this application.

[0097] Figure 6 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the domain-specific language design method disclosed in any of the foregoing embodiments.

[0098] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0099] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored thereon include operating system 221, computer program 222 and data 223 including target syntax, etc., and the storage method can be temporary storage or permanent storage.

[0100] The operating system 221 manages and controls the various hardware devices and computer programs 222 on the electronic device 20 to enable the processor 21 to perform calculations and processing on the massive amounts of data 223 in the memory 22. The operating system 221 can be Windows Server, Netware, Unix, Linux, etc. In addition to including computer programs capable of performing the domain-specific language design methods executed by the electronic device 20 as disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs capable of performing other specific tasks.

[0101] Furthermore, this application also discloses a computer storage medium storing computer-executable instructions. When the computer-executable instructions are loaded and executed by a processor, they implement the domain-specific language design method steps disclosed in any of the foregoing embodiments.

[0102] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0103] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0104] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0105] The foregoing has provided a detailed description of a domain-specific language design method, apparatus, device, and medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A domain-specific language design method, characterized in that, include: Based on the business logic of the target domain, determine the corresponding syntax rules for the target domain; The syntax rules are written based on the regular expressions to obtain the target syntax described by the regular expressions; Based on the target syntax, a program package is generated according to the target runtime environment so that the program package can be used for business logic development; The step of generating the program package under the target runtime environment based on the target syntax includes: Obtain the software runtime environment requirements, and determine the target runtime environment based on the software runtime environment requirements; Using the specified environment code generation module of the language workbench, source code in the target runtime environment is generated based on the target syntax to obtain the program package; The step of writing the syntax rules based on the regular expression to obtain the target syntax described by the regular expression includes: The syntax rules are expressed using regular expressions in the syntax editor of the language workbench, resulting in multiple regular expression syntaxes. Each regular expression syntax is matched with a corresponding function to generate a method library corresponding to the syntax rules.

2. The domain-specific language design method according to claim 1, characterized in that, After writing the syntax rules based on the regular expression to obtain the target syntax described by the regular expression, the method further includes: The target grammar is subjected to logical checks to determine whether its logic and syntax are correct. If the logic and syntax are correct, then scenario detection is performed on the target syntax to detect whether the logic of the target syntax is correct in the target business scenario. If the target syntax is logically correct in the target business scenario, then the step of generating the program package in the target runtime environment based on the target syntax and the target runtime environment is executed.

3. The domain-specific language design method according to claim 2, characterized in that, The logical detection of the target syntax includes: The syntax tree generator of the language workbench generates a corresponding syntax tree based on the target syntax, and performs logical and grammatical checks on the target syntax based on the syntax tree; The scene detection of the target grammar includes: Using the simulation test environment module of the language workbench, the target syntax is run based on the target business scenario to generate running results, so as to perform scenario detection on the target syntax based on the running results.

4. The domain-specific language design method according to claim 3, characterized in that, The step of generating a corresponding syntax tree based on the target syntax using the syntax tree generator of the language workbench includes: Using the syntax tree generator of the language workbench, the target syntax is recursively parsed in the direction of the byte stream and regular expression matching is performed according to the pre-built method library to determine the function corresponding to each regular expression in the target syntax, so as to generate the syntax tree according to the function.

5. The domain-specific language design method according to claim 2, characterized in that, After detecting whether the logic and syntax of the target grammar are correct, the method further includes: If the logic and syntax of the target syntax are incorrect, the syntax rules shall be revised according to the detection results and the business logic. After detecting whether the logic of the target syntax is correct in the target business scenario, the method further includes: If the target syntax is logically incorrect in the target business scenario, the syntax rules will be revised based on the detection results and the business logic.

6. A domain-specific language design device, characterized in that, include: The syntax rule determination module is used to determine the syntax rules corresponding to the target domain based on the business logic of the target domain; The target syntax generation module is used to write the syntax rules based on the regular expression to obtain the target syntax described by the regular expression. The package generation module is used to generate a package in the target runtime environment based on the target syntax and the target runtime environment, so as to use the package for business logic development; The package generation module includes: The target runtime environment determination unit is used to acquire software runtime environment requirements and determine the target runtime environment based on the software runtime environment requirements. The source code generation unit is used to generate source code in the target runtime environment based on the target syntax using the specified environment code generation module of the language workbench, so as to obtain the program package; The process of obtaining the target grammar through the target grammar generation module includes: using the grammar editor of the language workbench to express the grammar rules using regular expressions to obtain multiple regular grammars, and matching a corresponding function for each regular grammar to generate a method library corresponding to the grammar rules.

7. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the domain-specific language design method as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein the computer programs, when executed by a processor, implement the domain-specific language design method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method, medium, device and computing device for establishing DSL sentence model

    CN109298857A

  • User-defined function operation method and system based on domain-specific language

    CN112748988A