Domain-specific language compiling method, device and equipment based on multiple computing frameworks
By constructing grammatical rules and lexical rules for domain-specific languages and using parser tools to convert executable code in cross-platform programming languages, the problem of inability to effectively schedule diversified computing frameworks in the existing technology is solved, and the processing efficiency of complex computing intentions is improved.
Patent Information
- Application Number
- CN202411240876.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2025-02-28
AI Technical Summary
The prior art cannot effectively schedule a diversified computing framework, which leads to inefficient efficiency when dealing with complex computing intentions and is difficult to meet the needs of complex computing scenarios.
By constructing grammatical rules and lexical rules for domain-specific languages based on computational intent, syntax files are generated, and parsed using parser tools to convert them into executable code in cross-platform programming languages to achieve unified identification and scheduling of different computing frameworks.
It improves the efficiency of handling complex computing intentions, and can quickly identify and schedule different computing frameworks required for complex computing intentions, meeting the needs of complex computing scenarios.
Smart Images

Figure CN119536736A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data computing technology, and in particular to a method, device and equipment for compiling domain-specific languages based on multiple computing frameworks. Background Art
[0002] During data calculation, data can come from multiple data sources, including but not limited to MySQL database, HDFS (Hadoop Distributed File System), remote service API (Application Programming Interface) requests, local CSV (Comma-Separated Values) files, etc. Different data sources require different computing frameworks to process. For example, some need to call SQL statements for single-node calculations, some need to call Spark SQL for asynchronous distributed calculations, and some need to perform server Restful request scheduling. Some small data texts need to call custom Jar packages for calculation.
[0003] In actual computing scenarios, we often face a large number of complex computing requirements. A complex computing intent can be decomposed into a series of smaller computing steps, and then each computing step is processed separately using a different computing framework. This processing method requires the system to be able to flexibly schedule multiple computing frameworks to achieve hybrid computing.
[0004] However, there is currently no universal computer programming language that can fully identify and effectively schedule these diverse computing frameworks to cope with complex computing intents. This limitation leads to the system being inefficient in processing complex computing intents and making it difficult to meet the needs of complex computing scenarios. Summary of the invention
[0005] The purpose of the present invention includes, for example, providing a method, device and equipment for compiling domain-specific languages based on multiple computing frameworks, which can convert the domain-specific language corresponding to the computing intent into a specified programming language, and use this specified programming language to achieve the purpose of uniformly identifying and scheduling different computing frameworks, thereby improving the efficiency of processing complex computing intents and meeting the needs of complex computing scenarios. The embodiments of the present invention can be implemented as follows:
[0006] In a first aspect, the present invention provides a domain-specific language compilation method based on multiple computing frameworks, the method comprising: constructing grammar rules and lexical rules based on the domain-specific language corresponding to the computing intent; wherein the grammar rules are composed of grammatical elements of the domain-specific language; the grammatical elements include function names, parameter lists and return values; different function names correspond to different computing frameworks; generating a grammar file corresponding to the domain-specific language according to the grammar rules and lexical rules; inputting the grammar file into a parser tool for grammatical parsing to generate executable code of a cross-platform programming language corresponding to the domain-specific language.
[0007] In a second aspect, the present invention provides a domain-specific language compilation device based on multiple computing frameworks, including: a construction module, used to construct grammar rules and lexical rules based on the domain-specific language corresponding to the computing intent; wherein the grammar rules are composed of grammar elements of the domain-specific language; the grammar elements include function names, parameter lists and return values; different function names correspond to different computing frameworks; a generation module, used to generate a grammar file corresponding to the domain-specific language according to the grammar rules and lexical rules; a compilation module, used to input the grammar file into a parser tool for grammar parsing, and generate executable code of a cross-platform programming language corresponding to the domain-specific language.
[0008] In a third aspect, the present invention provides a domain-specific language compilation device based on multiple computing frameworks, comprising a processor and a memory, wherein the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the domain-specific language compilation method based on multiple computing frameworks described in the aforementioned embodiment.
[0009] The present invention provides a method, device and equipment for compiling domain-specific languages based on multiple computing frameworks, which has the following advantages: by constructing grammatical rules and lexical rules of domain-specific languages based on computing intent, standardized expression of computing tasks is achieved, and then a grammar file is constructed based on the lexical rules and grammar rules, and the grammar file is parsed by a parser tool to convert the domain-specific language into executable code of a cross-platform programming language. The embodiment of the present invention constructs grammar rules through grammatical elements such as function names, parameter lists and return values in domain-specific languages. These grammatical elements include function names corresponding to computing frameworks. When using the parser tool for grammatical parsing, the parsed grammatical elements can be converted into a specified cross-platform programming language, which provides a basis for subsequent unified identification and scheduling of different computing frameworks. Through the cross-platform programming language, domain-specific languages can be run and parsed on different platforms, and different computing frameworks required for complex computing intents can be quickly identified and scheduled, thereby improving the execution efficiency of computing tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0011] Figure 1 A DSL sample of a computing intent provided for an embodiment of the present invention;
[0012] Figure 2 A schematic flow chart of a domain-specific language compilation method based on multiple computing frameworks provided in an embodiment of the present invention;
[0013] Figure 3 is a grammatical rule of the xplan language provided in an embodiment of the present invention;
[0014] Figure 4 is the lexical rule of the xplan grammar provided in the embodiment of the present invention;
[0015] Figure 5 An example diagram of converting a domain-specific semantic xplan language into a specified cross-platform programming language provided by an embodiment of the present invention;
[0016] Figure 6 A functional module diagram of a domain-specific language compilation device based on multiple computing frameworks provided by an embodiment of the present invention;
[0017] Figure 7 A structural block diagram of a domain-specific language compilation device based on multiple computing frameworks provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0019] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0020] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0021] In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear to indicate an orientation or position relationship, they are based on the orientation or position relationship shown in the accompanying drawings, or are the orientation or position relationship in which the product of the invention is usually placed when used. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0022] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.
[0023] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.
[0024] In one embodiment of the present invention, a DSL (Domain Specific Language) for computing intent is designed, called the xplan language, which can borrow some grammatical elements from the syntax of Shell scripts to form this DSL. Figure 1 , Figure 1 A DSL sample of a computational intent provided in an embodiment of the present invention. Figure 1 A method of decomposing a computational intent is shown in FIG. The intent can be decomposed into four basic computational steps, namely step 1 to step 4, each of which corresponds to a DSL example. It should be understood that Figure 1 The computational intent structure presented is only an example and should not be construed as any limitation on the number of computational steps contained in the computational intent. Optionally, a computational intent can contain any number of computational steps according to specific needs. Figure 1 The four steps are for demonstration purposes only.
[0025] exist Figure 1From the DSL samples of steps 1 to 4, we can find that they have a common function format, which can be expressed as: $${return value} = function_name("Execute statement", param1, param2, ...). "Execute statement" is the execution statement of the function, such as SQL, wrapped in double quotes; function_name is the function name, corresponding to different computing frameworks; param1 and param2 are parameters, separated by commas, and each function ends with a semicolon.
[0026] For example, in step 1, "find_travelers_amount_by_county_001" is the return value of the function, "sparksql" is the function name; "select user_id, data_date as date_dt, o_province asprovince, o_city as city, o_zone as zone from od where data_date in(${time_period})and o_province in(${address_province})and o_city in(${address_city})and o_zone_id in(${address_county})" is the execution statement.
[0027] In one embodiment of the present invention, the return value and function name of the function need to use standard characters, including uppercase and lowercase English characters, Arabic numerals, and underscores. The return value can be in the form of a combination of an intent name, an underscore, and a presentation name. The intent name is English, and the presentation name is any combination of English and Arabic numerals without an underscore, and the two are connected by an underscore. The purpose is to make the name of the return value globally unique, so that the various return results can be reused in the process of data mixing calls.
[0028] In one embodiment of the present invention, the parameter can use standard characters to avoid unpredictable problems. If it cannot be avoided, it can be wrapped in English double quotes, such as "12.5", where 12.5 is a constant parameter.
[0029] In addition, the parameters in the embodiment of the present invention include constants and dynamic parameters. Constants can be directly represented, such as the table name od. Dynamic parameters are marked by the slot identifier "${}" provided in the embodiment of the present invention, for example, ${time_period} indicates that time_period is a dynamic parameter.
[0030] In one embodiment of the present invention, a dynamic parameter can be the return value of a certain step. That is, if the return value of the previous step needs to be referenced in a certain step, the referenced return value is a dynamic parameter in the step, marked with the slot identifier "${}". That is, the same piece of data, if used as a return value, is marked with "$${}", and if used as a dynamic parameter, it is marked with "${}", so that the return value of the previous step can be passed as a variable to the subsequent step for calculation.
[0031] For example, in Figure 1 In step 4, ${find_travelers_amount_by_county_join} indicates that a dynamic parameter required in step 4 is "find_travelers_amount_by_county_join". This dynamic parameter is the return value of step 3. By using "${}" to mark it, the return value of step 3 can be passed to step 4 to execute the calculation process.
[0032] It can be seen that Figure 1 It is shown that the realization of a complex computing intent requires the collaboration of multiple different computing frameworks, such as MySQL and Spark data processing. In order to achieve unified recognition and scheduling of different computing frameworks, the embodiment of the present invention designs a compilation method for the xplan language, which can convert the xplan language into a cross-platform programming language. The cross-platform programming language can be used to quickly parse the xplan language, identify different computing frameworks that need to be scheduled, and improve the processing efficiency of complex computing intents.
[0033] See also Figure 2 , Figure 2 A schematic flow chart of a domain-specific language compilation method based on multiple computing frameworks provided in an embodiment of the present invention, the method may include the following processes:
[0034] S201, constructing grammatical rules and lexical rules based on the domain-specific language corresponding to the computing intent; wherein the grammatical rules are composed of grammatical elements of the domain-specific language; the grammatical elements include function names, parameter lists, and return values; different function names correspond to different computing frameworks;
[0035] S202, generating a grammar file corresponding to a domain specific language according to grammar rules and lexical rules;
[0036] S203, inputting the grammar file into a parser tool for grammar parsing, and generating executable code of a cross-platform programming language corresponding to the domain specific language;
[0037] In the embodiment of the present invention, the cross-platform programming language may be Java, Python, Go, etc. The preferred programming language of the embodiment of the present invention is Java, and the parser tool applied is Antlr4 (Another Tool for Language Recognition, an open source grammar analyzer generation tool developed based on Java).
[0038] It is worth noting that the selection of Antlr4 does not mean that the present invention is limited to the use of Java language or Antlr4 tool. When implementing the present invention, developers can flexibly select the most suitable programming language and programming tool according to specific needs. Therefore, the protection scope of the present invention should not be understood as being limited to the specific programming language or tool mentioned above.
[0039] In an embodiment of the present invention, the executable code of the cross-platform programming language obtained can identify different computing frameworks that need to be used and schedule them based on the domain-specific language code of the computing intent.
[0040] In the above steps S201 to S203, by constructing the grammatical rules and lexical rules of the domain-specific language based on the computing intent, the standardized expression of the computing task is realized, and then the grammar file is constructed based on the lexical rules and grammar rules, and the grammar file is parsed by the parser tool to convert the DSL into executable code of the cross-platform programming language. The embodiment of the present invention constructs grammar rules through grammatical elements such as function names, parameter lists and return values in the domain-specific language. These grammatical elements include function names corresponding to the computing framework. Then, when the parser tool is used for grammatical parsing, the parsed grammatical elements can be converted into a specified cross-platform programming language, which provides a basis for the subsequent unified identification and scheduling of different computing frameworks. Through the cross-platform programming language, the domain-specific language can be run and parsed on different platforms, and the different computing frameworks required for complex computing intents can be quickly identified and scheduled, thereby improving the execution efficiency of computing tasks.
[0041] In the following embodiments of the present invention, Java is used as the designated cross-platform programming language and Antlr4 is used as the parsing tool to describe the above compilation process in detail. It should be understood that the implementation of the present invention is not limited to the Java language or the Antlr4 tool, and the method can be analogized to other types of programming languages and programming tools, which will not be described in detail here.
[0042] In step S201, by observing Figure 1From the DSL examples shown, we can see that the xplan language mainly includes syntax elements such as return value, called function name, and parameter list corresponding to the function. Based on these syntax elements, we can build standardized syntax rules and lexical rules for the xplan language and generate Antlr4 grammar. Figure 3 and Figure 4 , Figure 3 is a grammatical rule of the xplan language provided in an embodiment of the present invention; Figure 4 It is the lexical rule of the xplan grammar provided by the embodiment of the present invention.
[0043] exist Figure 3 The syntax rules of the xplan language are defined in detail, including the syntax rules of xplan, action, return_val, parameters, parameter and function. The interpretation of each syntax rule is as follows:
[0044] xplan: defines the structure of the entire input, which consists of one or more actions and ends with the end-of-file symbol EOF.
[0045] action: defines the structure of an action, including the return value return_val, the equal sign "=", the function function, the parameter list parameters and a semicolon as the end.
[0046] return_val: defines a return value, using the GLOBAL_BRACE_ID rule.
[0047] parameters: defines the parameter list, which can be empty or consist of multiple parameters, separated by commas.
[0048] parameter: defines a parameter, which can be a strict parameter identifier STRICT_PARA_ID, an escape string ESCAPED_STRING, or a number number.
[0049] function: defines a function name, using the ID rule.
[0050] exist Figure 4 The lexical rules are defined in , such as WS (whitespace character), ID (identifier), GLOBAL_BRACE_ID (global curly brace identifier), STRICT_PARA_ID (strict parameter identifier), ESCAPED_STRING (escape string) and number (number). The interpretation of each lexical rule is as follows:
[0051] WS: defines whitespace characters such as newline, tab, carriage return, space, etc., and uses "-->skip" to ignore them.
[0052] ID: defines an identifier that can be composed of letters, underscores, and numbers, with letters or underscores as the beginning and numbers or underscores as the following content.
[0053] GLOBAL_BRACE_ID: defines a global identifier for the return value definition. It starts with "$${", followed by letters, numbers or underscores, and ends with "}".
[0054] STRICT_PARA_ID: defines a parameter identifier with curly braces, which is used to define parameters. It starts with "${", followed by letters, numbers or underscores, and ends with "}".
[0055] ESCAPED_STRING: Defines a quoted string that can contain double quote escapes (""), backslash followed by double quotes (\\"), or non-double quote characters.
[0056] INT: defines a natural number that can start with 0 or a non-zero number followed by any number of Arabic numerals.
[0057] number: defines a number, which can be Integer or Float.
[0058] Integer: defines an integer, which can be a negative number or a natural number.
[0059] Float: defines a floating point number, which can be negative or positive and contains a decimal point.
[0060] Dot: defines a decimal point.
[0061] By defining the above-mentioned lexical rules and grammatical rules, the standard Antlr4 grammar definition can be determined and then a grammar file can be generated. Then, for step S202, a grammar rule file can be generated by combining the lexical rules and grammatical rules, recorded as XPlan.g4 file. This file can be recognized by the Antlr4 parsing tool and converted into Java executable code.
[0062] In step S203, the embodiment of the present invention generates Java executable code by calling the antlr4-runtime library of the Antlr4 tool and selecting the observer mode to parse the XPlan.g4 file. The specific process is as follows:
[0063] Step a1: Map various rules in the grammar file into nodes and build a grammar tree based on the nodes;
[0064] In the embodiment of the present invention, when parsing the grammar file, each rule in the xplan language is parsed and a parse tree is generated. The parse tree is a hierarchical structure including multiple nodes, each node corresponding to a grammar rule in the grammar file, such as the return value, function name and parameter in the xplan statement.
[0065] In an optional implementation, the process of constructing a syntax tree may be: generating a lexical analyzer and a grammatical parser; decomposing the text read from the grammatical file into word sequences by the lexical analyzer; and using the grammatical parser to construct the syntax tree using word sequences according to various rules.
[0066] In the above implementation, the Antlr4 tool can be used to generate a lexical analyzer and a syntax analyzer to quickly complete the construction of a syntax tree.
[0067] Step a2: Generate a listener interface for grammar rules;
[0068] In one embodiment of the present invention, the listener interface is used to define a callback method corresponding to the grammar rule, and the callback method can monitor the node corresponding to the grammar rule.
[0069] It is understandable that the ParseTreeListener interface provided by the Antlr4 tool defines callback methods for entering a node (enterXXXX()) and exiting a node (exitXXXX()). When entering and leaving a node during the parsing process, the corresponding callback method in the listener will be automatically triggered. Through these callback methods, the context information of the current node can be obtained, so as to parse the grammatical meaning. Therefore, for the xplan statement, the Antlr4 tool can first automatically generate a listener interface for the node that inherits the ParseTreeListener class through the listener node listening method, that is, the XPlanListener interface, and the callback methods for entering and leaving the nodes corresponding to the xplan grammar rules are provided in the XPlanListener interface.
[0070] Step a3: In response to the implementation operation on the listener interface and the overwriting operation on the callback method, the insertion of the custom business logic for the grammar rule is completed;
[0071] In the embodiment of the present invention, developers can define a Java class, implement the XPlanListener interface, and override the callback method in the interface to achieve the purpose of inserting custom business logic into a certain grammar rule.
[0072] For example, in Figure 3In the example, for the syntax rule return_val, override the enterReturn_val and exitReturn_val methods to capture the return value of each action. For the syntax rule function, override the enterFunction and exitFunction methods to identify the function name to be called. For the syntax rule parameter, override the enterParameter and exitParameter methods to capture a single parameter. If the parameter is a variable or slot, you also need to override the relevant entry and exit methods, such as enterStrict_para_id and exitStrict_para_id, to identify and handle these special parameters.
[0073] By overriding these callback methods, you can access and process each grammar rule encountered during the parsing process of the Antlr4 tool. For example, when the grammar rule return_val is recognized by the parsing, the name of the return value can be extracted in the corresponding callback method. It should be understood that the specific overriding method depends on the specific needs of the developer and the specific definition of the DSL code, which is not limited here.
[0074] Step a4: semantically parse the syntax tree, and convert the semantically parsed syntax tree into executable code of a cross-platform programming language.
[0075] In the embodiment of the present invention, generating a syntax tree is essentially parsing the input text at the lexical and grammatical levels, but the syntax tree itself only represents the structure of the text, without semantic information. Therefore, on the basis of steps a1 to a3, it is also necessary to perform semantic checking and parsing on the syntax tree to obtain an intermediate executable code, and convert the intermediate executable code into an executable code of a specified cross-platform programming language.
[0076] Through the above implementation method, the xPlan language customized by the developer for the computing intent is converted into the executable code of the cross-platform programming language. Subsequently, based on the reflection mechanism of the cross-platform programming language, the scheduler of the computing framework needed to execute the computing intent can be triggered directly, so as to quickly complete the calculation and improve the efficiency of executing the DSL executable code.
[0077] From the above, it can be seen that in the process of converting the domain-specific language corresponding to the computing intent into the executable code of the cross-platform programming language, the embodiment of the present invention needs to first construct the syntax file of the domain-specific programming language, and then parse the syntax file with a parsing tool. In the parsing process, the lexical analyzer and syntax analyzer generated by the parsing tool are used to create a syntax tree model, and finally the executable code is obtained by semantically parsing the syntax tree model. Figure 5 As shown, Figure 5An example diagram of converting domain-specific semantic xplan language into a specified cross-platform programming language is provided for an embodiment of the present invention. By calling the antlr4-runtime library of the Antlr4 tool to parse the xPlan syntax file, an executable code of the specified cross-platform programming language is finally obtained. This executable code can be used to quickly identify and schedule different computing frameworks required for a computing intent, thereby improving the computing efficiency of complex computing intents.
[0078] Next, the embodiment of the present invention will introduce how to process a complex computing intent based on an executable code of a cross-platform programming language. In one embodiment of the present invention, for a complex computing intent that can split the execution logic into multiple computing steps, the following steps can be performed using the executable code obtained above:
[0079] Step b1: determining the domain-specific language codes corresponding to the multiple computing steps of the computing intention to be processed; wherein the computing steps have an execution sequence;
[0080] Step b2: Input each domain-specific language code into the executable code for parsing, and obtain the target function name, target parameter string, and target return value that need to be called for each calculation step;
[0081] Step b3: Based on the target function name, target parameter string and target return value, the reflection mechanism of the cross-platform programming language is used to implement the sequential serial execution of multiple calculation steps to obtain the calculation result of the calculation intention to be processed.
[0082] In order to facilitate the understanding of the above process, Figure 1 The DSL code corresponding to step 1 is "$${find_travelers_amount_by_county_001}=sparksql("select user_id,data_date asdate_dt,o_province as province,o_city as city,o_zone as zone from od wheredata_date in(${time_period})and o_province in(${address_province})and o_cityin(${address_city})and o_zone_id in(${address_county})")".
[0083] Enter the above DSL code into the converted Java executable code to start running the executable code. When the syntax tree generated after parsing this statement is monitored, the following callback will be triggered:
[0084] Enter the action rule to get this calculation step; enter the return_val rule to parse out the return value of this step as find_travelers_amount_by_county_001; enter the function rule to parse out the function name as sparksql; enter the parameters rule to parse out the function parameter as a SQL statement string, in which dynamic parameters are identified by ${}, which need to be dynamically replaced through external transmission. Then, the executable code can dynamically load the function class named sparksql through the reflection mechanism, and perform reflective call based on the parsed parameters. After the call is completed, the result can be obtained through the return value.
[0085] By analogy, the subsequent statements can be executed serially. Figure 1 The calculation process from step 1 to step 4 is repeated, and the results of each step are obtained. The final result find_travelers_amount_by_county_result can be obtained in the last step.
[0086] Combined with the above example, it can be seen that the implementation process of step b2 is: run the executable code, generate a syntax tree of the domain-specific language code during the parsing process; monitor the syntax tree, and when a node corresponding to the syntax rule that matches the target function name, target parameter string and target return value is parsed, the callback method corresponding to the node is triggered to parse out the target function name, target parameter string and target return value.
[0087] For example, in Figure 1 In step 1, the parsed target function name is sparksql, the target parameter string is select user_id,data_date as date_dt,o_province as province,o_city as city,o_zone as zone from od where data_date in(${time_period})and o_province in(${address_province})and o_city in(${address_city})and o_zone_id in(${address_county}), and the target return value is find_travelers_amount_by_county_001.
[0088] From the above process, we can see that the parsed target parameter string contains constants and dynamic parameters. The dynamic parameters are marked with slots ${}, such as ${address_province}, ${time_period}, etc. Figure 1 ${find_travelers_amount_by_county_join} in step 4 means that the dynamic parameters need to be replaced first when executing the scheduling task. Therefore, after obtaining the target parameter string in step b1, you can also perform the following steps:
[0089] Step c1: when it is determined that the target parameter string of the calculation step contains a slot identifier;
[0090] Step c2: after obtaining the target parameter character string, replace the parameter marked by the slot identifier with the target parameter; wherein the target parameter is the parameter value input by the user or the return value of the previous calculation step of the calculation step.
[0091] It can be seen that the embodiment of the present invention can quickly identify the dynamic parameters that need to be replaced during the calculation process by designing slot identification, thereby ensuring the smooth progress of the calculation process, and by setting the dynamic parameters, the return values of different calculation steps can be called.
[0092] It can be seen that the embodiments of the present invention can efficiently identify the parameters that need to be dynamically replaced during the calculation process by introducing slot identification, ensure the smooth execution of the calculation process, and significantly improve the flexibility of the calculation process. Furthermore, the present invention realizes the flexible call of the return values of different calculation steps by setting a dynamic parameter mechanism. This mechanism allows the system to dynamically adjust the calculation logic according to real-time data or condition changes during execution, thereby making the entire calculation process more automated.
[0093] Based on Figure 2 With the same inventive concept, the present invention also provides a domain-specific language compilation device based on multiple computing frameworks. Figure 6 , Figure 6 Functional module diagram of a domain specific language compiling device based on multiple computing frameworks provided by an embodiment of the present invention. The domain specific language compiling device based on multiple computing frameworks 60 may include: a construction module 601 , a generation module 602 and a compiling module 603 .
[0094] A construction module 601 is used to construct grammar rules and lexical rules based on the domain specific language corresponding to the computing intent; wherein the grammar rules are composed of grammar elements of the domain specific language; the grammar elements include function names, parameter lists and return values; different function names correspond to different computing frameworks;
[0095] A generating module 602, for generating a grammar file corresponding to a domain specific language according to grammar rules and lexical rules;
[0096] The compiling module 603 is used to input the grammar file into a parser tool for grammar parsing, and generate executable code of a cross-platform programming language corresponding to the domain specific language.
[0097] It is understandable that the construction module 601, the generation module 602 and the compilation module 603 can be executed in coordination. Figure 2 Each step in the process is performed to achieve the corresponding technical effect.
[0098] In an optional implementation, the compilation module 603 is specifically used to map various rules in the grammar file into nodes and build a grammar tree based on the nodes; generate a listener interface for the grammar rules; wherein the listener interface is used to define the callback method corresponding to the grammar rule; the callback method is used to listen to the nodes corresponding to the grammar rule; respond to the implementation operation of the listener interface and the overwrite operation of the callback method to complete the insertion of the custom business logic for the grammar rule; perform semantic parsing on the grammar tree, and convert the semantically parsed grammar tree into executable code in a cross-platform programming language.
[0099] In an optional implementation, the compilation module 603 is specifically used to generate a lexical analyzer and a grammar parser; decompose the text read from the grammar file into a word sequence through the lexical analyzer; use the lexical analyzer to construct a grammar tree according to various rules using the word sequence obtained by the lexical analyzer.
[0100] In an optional implementation, in a domain-specific language, a parameter list includes a slot identifier; the slot identifier is used to mark a dynamic parameter; the return value is one of the dynamic parameters; and the names of all return values are globally unique.
[0101] In an optional embodiment, the domain-specific language compilation device 30 based on multiple computing frameworks may also include a computing module for determining the domain-specific language codes corresponding to each of the multiple computing steps of the computing intention to be processed; wherein the computing steps have an execution sequence; each of the domain-specific language codes is input into the executable code for parsing to obtain the target function name, target parameter string and target return value to be called for each of the computing steps; based on the target function name, target parameter string and target return value, the reflection mechanism of the cross-platform programming language is used to implement the sequential serial execution of the multiple computing steps to obtain the computing result of the computing intention to be processed.
[0102] In an optional embodiment, the calculation module is also used to determine that the target parameter string of the calculation step contains a slot identifier; after obtaining the target parameter string, replace the parameter marked by the slot identifier with the target parameter; wherein the target parameter is the parameter value input by the user or the return value of the previous calculation step of the calculation step.
[0103] In an optional implementation: a computing module is specifically used to run the executable code and generate a syntax tree of the domain-specific language code during the parsing process; the syntax tree is monitored, and when a node corresponding to a syntax rule that matches the target function name, target parameter string and target return value is parsed, a callback method corresponding to the node is triggered to parse out the target function name, target parameter string and target return value.
[0104] It should be noted that the division of modules in the above embodiments of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. In addition, each functional unit in each embodiment of the present application may be integrated into a processing unit, or may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.
[0105] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable an electronic device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program executable code.
[0106] The embodiment of the present invention also provides a domain-specific language compilation device based on multiple computing frameworks, see Figure 7 , Figure 7The structural block diagram of the domain-specific language compilation device based on multiple computing frameworks provided in an embodiment of the present invention includes: a memory 701, a processor 702, and a communication interface 703. The memory 701, the processor 702, and the communication interface 703 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.
[0107] Optionally, bus 704 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0108] In the embodiment of the present invention, the processor 702 may be a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiment of the present invention. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiment of the present invention may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor. The software module may be located in the memory 701, and the processor 702 reads the program instructions in the memory 701 and completes the steps of the above method in combination with its hardware.
[0109] In the embodiment of the present invention, the memory 701 may be a non-volatile memory, such as a hard disk (HDD) or a solid-state drive (SSD), etc., or a volatile memory (VolatileMemory), such as RAM. The memory may also be any other medium that can be used to carry or store the desired program executable code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory in the embodiment of the present invention may also be a circuit or any other device that can realize a storage function, for storing instructions and / or data.
[0110] The memory 701 can be used to store software programs and modules, such as the instructions / modules of the domain-specific language compiler device 60 based on multiple computing frameworks provided in the embodiment of the present invention, which can be stored in the memory 701 in the form of software or firmware (Firmware) or in the operating system (OS) of the fixed computer device 700. The processor 702 executes various functional applications and data processing by executing the software programs and modules stored in the memory 701. The communication interface 703 can be used to communicate signaling or data with other node devices.
[0111] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0112] Understandably, Figure 7 The structure shown is for illustration only. The data computing device 70 based on authority control may also include Figure 7 More or fewer components as shown, or with Figure 7 Different configurations are shown. Figure 7 The components shown may be implemented in hardware, software or a combination thereof.
[0113] The data computing device 70 based on authority control may also include network devices and / or user devices. The network devices include, but are not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers based on cloud computing.
[0114] Based on the above embodiments, the present application also provides a storage medium, in which a computer program is stored. When the computer program is executed by a computer, the computer executes the domain-specific language compilation method based on multiple computing frameworks provided in the above embodiments.
[0115] Based on the above embodiments, an embodiment of the present invention further provides a computer program. When the computer program runs on a computer, the computer executes the domain-specific language compilation method based on multiple computing frameworks provided in the above embodiments.
[0116] Based on the above embodiments, an embodiment of the present invention further provides a chip, which is used to read a computer program stored in a memory and to execute the domain-specific language compilation method based on multiple computing frameworks provided in the above embodiments.
[0117] A computer program product is also provided in an embodiment of the present invention, including instructions, which, when executed on a computer, enable the computer to execute the domain-specific language compilation method based on multiple computing frameworks provided in the above embodiment.
[0118] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by instructions. These instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0119] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0120] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0121] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A domain-specific language compilation method based on multiple computing frameworks, characterized in that: The method comprises: Based on the domain-specific language corresponding to the computing intent, construct grammatical rules and lexical rules; wherein the grammatical rules are composed of grammatical elements of the domain-specific language; the grammatical elements include function names, parameter lists and return values; different function names correspond to different computing frameworks; Generate a grammar file corresponding to the domain specific language according to the grammar rules and lexical rules; The grammar file is input into a parser tool for grammar parsing to generate executable code of a cross-platform programming language corresponding to the domain specific language.
2. The domain-specific language compilation method based on multiple computing frameworks according to claim 1, characterized in that: Inputting the grammar file into a parser tool for grammar parsing to generate executable code of a cross-platform programming language corresponding to the domain specific language, including: Mapping various rules in the grammar file into nodes and constructing a grammar tree based on the nodes; Generate a listener interface for the grammar rule; wherein the listener interface is used to define a callback method corresponding to the grammar rule; the callback method is used to monitor the node corresponding to the grammar rule; In response to the implementation operation on the listener interface and the overwriting operation on the callback method, the insertion of the custom business logic for the grammar rule is completed; The syntax tree is semantically parsed, and the semantically parsed syntax tree is converted into executable code of the cross-platform programming language.
3. The domain-specific language compilation method based on multiple computing frameworks according to claim 2, characterized in that: Mapping various rules in the grammar file into nodes and constructing a grammar tree based on the nodes, including: Generate lexical analyzer and parser; Decomposing the text read from the grammar file into a sequence of tokens by the lexical analyzer; The syntax tree is constructed by using the syntax parser and the word sequence according to various rules.
4. The domain-specific language compilation method based on multiple computing frameworks according to any one of claims 1 to 3, characterized in that: In the domain specific language, the parameter list includes a slot identifier; the slot identifier is used to mark a dynamic parameter; the return value is one of the dynamic parameters; and the names of all the return values are globally unique.
5. The domain-specific language compilation method based on multiple computing frameworks according to claim 1, characterized in that: The method further comprises: Determine domain-specific language codes corresponding to multiple computing steps of the computing intent to be processed; wherein the computing steps have an execution order; Input each of the domain-specific language codes into the executable code for parsing, and obtain the target function name, target parameter string, and target return value to be called for each of the calculation steps; Based on the target function name, target parameter string and target return value, the reflection mechanism of the cross-platform programming language is used to implement sequential serial execution of multiple calculation steps to obtain the calculation result of the calculation intention to be processed.
6. The domain-specific language compilation method based on multiple computing frameworks according to claim 5, characterized in that: The method further comprises: When it is determined that the target parameter string of the calculation step includes a slot identifier; After the target parameter character string is obtained, the parameter marked by the slot identification is replaced with the target parameter; wherein the target parameter is a parameter value input by a user or a return value of a previous calculation step of the calculation step.
7. The domain-specific language compilation method based on multiple computing frameworks according to claim 5, characterized in that: Input each of the domain-specific language codes into the executable code for parsing, and obtain the target function name, target parameter string, and target return value to be called for each of the calculation steps, including: Running the executable code to generate a syntax tree of the domain specific language code during parsing; The syntax tree is monitored, and when a node corresponding to a syntax rule matching a target function name, a target parameter string, and a target return value is parsed, a callback method corresponding to the node is triggered to parse out the target function name, the target parameter string, and the target return value.
8. A domain-specific language compilation device based on multiple computing frameworks, characterized in that: include: A construction module, used to construct grammatical rules and lexical rules based on a domain-specific language corresponding to a computing intent; wherein the grammatical rules are composed of grammatical elements of the domain-specific language; the grammatical elements include a function name, a parameter list, and a return value; different function names correspond to different computing frameworks; A generation module, used to generate a grammar file corresponding to the domain specific language according to the grammar rules and lexical rules; The compiling module is used to input the grammar file into a parser tool for grammar parsing, and generate executable code of a cross-platform programming language corresponding to the domain specific language.
9. The domain-specific language compilation device based on multiple computing frameworks according to claim 8, characterized in that: The compilation module is specifically used for: Mapping various rules in the grammar file into nodes and constructing a grammar tree based on the nodes; Generate a listener interface for the grammar rule; wherein the listener interface is used to define a callback method corresponding to the grammar rule; the callback method is used to monitor the node corresponding to the grammar rule; In response to the implementation operation on the listener interface and the overwriting operation on the callback method, the insertion of the custom business logic for the grammar rule is completed; The syntax tree is semantically parsed, and the semantically parsed syntax tree is converted into executable code of the cross-platform programming language.
10. A domain-specific language compilation device based on multiple computing frameworks, characterized in that: The invention comprises a processor and a memory, wherein the memory stores a computer program executable by the processor, and the processor can execute the computer program to implement the domain-specific language compilation method based on multiple computing frameworks as described in any one of claims 1 to 7.
Citation Information
Cited By
Prompt word compiling and generating method and system for large language model
CN120848895A