Translator generation method and device, equipment and storage medium
Patent Information
- Application Number
- CN202380085841.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-13
- Publication Date
- 2025-08-12
AI Technical Summary
Existing translator generation methods are cumbersome and unable to meet the diverse needs of users, and cannot effectively generate highly applicable translators.
By obtaining the keywords and rules of the domain-specific language defined in the description file, a fractal tree structure is used to generate the translator and configuration file, which supports users to input text to be translated and generates a syntax tree, and allows the configuration file to be updated to adapt to different needs.
It simplifies the translator generation process, reduces time and space complexity, improves the applicability and ease of operation of the translator, and can meet the diverse needs of different users.
Smart Images

Figure CN120476380A_ABST
Abstract
Description
Translator generation method, device, equipment and storage medium Technical Field
[0001] The present application relates to the field of translators, and in particular to a translator generation method, apparatus, device and storage medium. Background Art
[0002] A translator is a tool that converts one computer language into another. Commonly used translators include compilers, assemblers, interpreters, etc.
[0003] At present, the commonly used translator generation method is relatively cumbersome, and the generated translator can no longer meet the user's usage needs, so there is an urgent need to develop a new translator.
[0004] Summary of the Invention
[0005] The present application provides a translator generation method, apparatus, device and storage medium. The translator generation method is relatively simple. The translator generated by the method described in the present application has strong applicability and can meet the different needs of users.
[0006] In a first aspect, the present application provides a translator generation method, comprising: obtaining a description file, the description file defining keywords involved in a first domain-specific language (DSL) and N rules for generating a translator, where N is greater than or equal to 1, the description file being obtained based on a configuration, the first rule of the N rules including multiple target strings and at least one wildcard, the first rule being any one of the N rules; and generating a translator and a configuration file corresponding to the first DSL based on the description file, the configuration file including the N rules.
[0007] As can be seen, in this application, a description file is generated based on user configuration. The description file defines keywords related to the first DSL and N rules for generating a translator. The first of these N rules includes multiple target strings and at least one wildcard. Based on the configured description file, a translator and configuration file corresponding to the first DSL are generated. Compared to using regular expressions to write description files, the description file representation method in this application is simpler and easier to use, and the generated translator can meet user requirements.
[0008] Based on the first aspect, in a possible implementation, generating a translator and a configuration file corresponding to the first DSL based on the description file includes: generating a fractal tree based on the N rules, where each of the N rules is a branch of the fractal tree, and at least one wildcard in the first rule is a virtual root node on the branch where the first rule is located, and the virtual root node is different from the root node of the fractal tree; and generating the translator and the configuration file based on the fractal tree.
[0009] As you can see, this application proposes a new fractal tree structure with a virtual root node. This allows N rules in a description file to be constructed into a single tree. Generating a translator only requires traversing a single tree. Compared to using a traditional fractal tree structure, which constructs multiple trees based on N rules and requires traversing multiple trees when generating a translator, the method described in this application has lower time and space complexity.
[0010] Based on the first aspect, in a possible implementation, the keyword includes one or more of the name of the description file, the import rule of the description file, the type of the translator, and the language used by the translator.
[0011] Based on the first aspect, in a possible implementation, the N rules include recognition rules of the second DSL, and the method further includes: obtaining text to be translated input by a user, where the text to be translated is written using the first DSL or the second DSL; and translating, by the translator, the text to be translated into a corresponding syntax tree.
[0012] It is understood that the text to be translated is input into the translator, and the corresponding syntax tree can be obtained through the translator. In addition, when the N rules include the recognition rules of the second DSL, the generated translator can be used to translate the first DSL or the second DSL.
[0013] Based on the first aspect, in a possible implementation, translating the text to be translated into a corresponding syntax tree by the translator includes: inputting the configuration file into the translator; and translating the text to be translated into a corresponding syntax tree by the translator.
[0014] It is understandable that after the text to be translated is input into the translator, the configuration file can also be input into the translator, and the corresponding syntax tree can be obtained through the translator.
[0015] Based on the first aspect, in a possible implementation, before inputting the configuration file into the translator, the method further includes: updating the N rules in the configuration file to M rules, at least one of the M rules does not belong to the N rules, or at least one of the N rules does not belong to the M rules.
[0016] As can be seen, the configuration file allows the user to modify N rules. That is, when using the translator, the user can modify the rules in the configuration file according to actual needs and input the modified configuration file into the translator, which then translates the input text to be translated. The translator provided in this application can meet the different needs of different users, is easy to operate, and has strong applicability.
[0017] Based on the first aspect, in a possible implementation, the second DSL includes any one of a DBC description language, a CMake script language, and a GCOV description language.
[0018] In a second aspect, the present application provides a translator generation device, characterized by comprising:
[0019] an acquisition module, configured to acquire a description file, wherein the description file defines keywords involved in the first DSL and N rules for generating a translator, where N is greater than or equal to 1, the description file being obtained based on a configuration, a first rule among the N rules including multiple target strings and at least one wildcard, and the first rule being any one of the N rules;
[0020] A generating module is configured to generate a translator and a configuration file corresponding to the first DSL based on the description file, wherein the configuration file includes the N rules.
[0021] Based on the second aspect, in a possible implementation, the generation module is used to: generate a fractal tree according to the N rules, each of the N rules is a branch of the fractal tree, and at least one wildcard in the first rule is a virtual root node on the branch where the first rule is located, and the virtual root node is different from the root node of the fractal tree; generate the translator and the configuration file according to the fractal tree.
[0022] Based on the second aspect, in a possible implementation, the keyword includes one or more of the name of the description file, the import rule of the description file, the type of the translator, and the language used by the translator.
[0023] Based on the second aspect, in a possible implementation, the N rules include recognition rules for the second DSL, the apparatus further includes a translation module, the acquisition module is further configured to acquire text to be translated input by a user, where the text to be translated is written using the first DSL or the second DSL; and the translation module is configured to translate the text to be translated into a corresponding syntax tree using the translator.
[0024] Based on the second aspect, in a possible implementation, the translation module is configured to: input the configuration file into the translator; and translate the text to be translated into a corresponding syntax tree through the translator.
[0025] Based on the second aspect, in a possible implementation, the device also includes: an update module, used to update the N rules in the configuration file to M rules, at least one of the M rules does not belong to the N rules, or at least one of the N rules does not belong to the M rules.
[0026] Based on the second aspect, in a possible implementation, the second DSL includes any one of a DBC description language, a CMake script language, and a GCOV description language.
[0027] Each functional module of the second aspect is used to implement the method described in the first aspect or any possible implementation of the first aspect.
[0028] In a third aspect, the present application provides a translator generation device, comprising a processor and a memory, wherein the memory is used to store instructions, and the processor is used to execute the instructions stored in the memory to execute the method described in the first aspect or any possible implementation of the first aspect.
[0029] Based on the third aspect, in a possible implementation, the device is an in-vehicle computing platform or a server, wherein the server is a local server or a cloud server.
[0030] In a fourth aspect, the present application provides a storage medium comprising program instructions, which, when executed by a processor, causes the processor to execute the method described in the first aspect or any possible implementation of the first aspect.
[0031] In a fifth aspect, the present application provides a computer program product comprising program instructions, which, when executed by a processor, causes the processor to execute the method described in the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] FIG1 is a flow chart of a translator generation method provided by the present application;
[0033] FIG2 is an example of a description file grammar rule provided by this application;
[0034] FIG3 is a partial flow diagram of a translator generation method provided by the present application;
[0035] FIG4 is a schematic diagram of the structure of a fractal tree provided by the present application;
[0036] FIG5 is an example diagram provided by this application;
[0037] FIG6 is a schematic structural diagram of a translator generation device provided by the present application;
[0038] FIG7 is a schematic structural diagram of a translator generation device provided in this application. DETAILED DESCRIPTION
[0039] This application provides a translator generation method. Before introducing the translator generation method provided by this application, we first introduce the application scenarios involved in the method described in this application. The translator generation method provided by this application can be applied in the automotive field, for example, in an on-board computing platform, which generates a translator according to the method described in this application and uses the translator to parse the domain language involved in the controller area network (CAN) bus. The method can also be applied to other fields, for example, in natural language processing, integrated development environment (IDE), information retrieval and other fields.
[0040] The method described in this application can be executed by an on-board computing platform or by a server. The server can be a local server, such as a local desktop computer, or a server located in the cloud, such as a central server or an edge server. The cloud can be a public cloud, a private cloud, or a hybrid cloud. The following describes a method for generating a translator provided by this application. See Figure 1, which is a flow chart of a method for generating a translator provided by this application. The method includes but is not limited to the following description.
[0041] S101. Obtain a description file, where the description file defines keywords involved in a first domain-specific language (DSL) and N rules for generating a translator. The description file is obtained based on a configuration, where a first rule among the N rules includes multiple target strings and at least one wildcard, and the first rule is any one of the N rules.
[0042] The first DSL is a language developed by the user. Optionally, in one implementation, the description file may also use an existing DSL, that is, the first DSL may also be an existing DSL.
[0043] Keywords involved in the first domain language refer to user-defined words with special meanings. They are identifiers with special meanings in the first DSL and are also called reserved words.
[0044] Keywords may include one or more of the following: the name of the description file, the import rules for the description file, the type of translator, and the language used by the translator. For example, "module" may be used to represent the name of the description file, such as "module A" indicating that the name of the description file is A; "import" may be used to represent the import rules for the description file, such as "import B" indicating that the description file B is imported; "generate" may be used to represent the type of the generated translator, such as "generatelexer" indicating that the generated translator is a lexical parser, and "generateparser" indicating that the generated translator is a syntax parser; and "language" may be used to represent the language used by the translator, such as "language=C++" indicating that the programming language used to generate the translator is C++, "language=Java" indicating that the programming language used to generate the translator is Java, and "language=Python" indicating that the programming language used to generate the translator is Python.
[0045] Optionally, keywords may also include optional configuration items. Optional configuration items are items that can be selectively configured by the user based on actual needs. For example, optional configuration items may include the language used by the translator. For example, optional configuration items can be represented by "options," and within "options," "language" can be used to represent the language used by the translator. Other keywords may also be defined in optional configuration items, but this application does not limit them. The keywords involved in the first DSL may also include other keywords, but this application does not limit them.
[0046] Based on the specific functions of the translator to be generated, N rules for generating the translator are defined, where N is an integer greater than or equal to 1. For example, in one example, the translator to be generated needs to have the functions of a lexical parser and a grammatical parser. The N rules may include lexical parsing rules and grammatical parsing rules. The lexical parser is used to segment the input character sequence, and the grammatical parser is used to determine the association between the individual segmented words based on the segmentation results.
[0047] The first rule among the N rules includes multiple target character strings and at least one wildcard. The first rule is any one of the N rules. In other words, at least one rule among the N rules includes multiple target character strings and at least one wildcard. A character string (or string for short) is a string of characters consisting of numbers, letters, and underscores. A character string is a data type that represents text in a programming language. A wildcard is a special statement used to fuzzy search files. When searching for a target file, if the actual characters of the target file are unknown or if you do not want to type the complete characters, you often use wildcards to replace one or more actual characters.
[0048] In the present application, two kinds of wildcards are defined in the description file. One is "*". The wildcard * represents any number of arbitrary characters, and the arbitrary number can be zero, one, or multiple. For example, a*b represents a character string that starts with character a, ends with character b, and contains any number of arbitrary characters in between. The other wildcard is "?". The wildcard ? represents any character. For example, a? b represents a character string that starts with character a, ends with character b, and contains any character in between. It can be understood that when the first rule includes a wildcard, the wildcard can be any one of the two wildcards; when the first rule includes multiple wildcards, the multiple wildcards can all be the same wildcard, for example, the multiple wildcards included in the first rule can all be "*" or "?"; the multiple wildcards in the first rule can also include both "*" and "?".
[0049] See Figure 2, which shows an example of a description file grammar rule provided by this application. In Figure 2, module, import, generate, options, and language are all keywords defined in the description file, where moduletest indicates that the name of the description file is test, importbase_rule indicates that the description file base_rule is imported into the description file test, generatelexer indicates that the type of the generated translator is a word segmentation parser lexer, options indicates an optional configuration item, and the language used by the translator configured in options is language xxx.
[0050] The description file is generated based on user configuration, which includes keywords and N rules for generating the translator. It should be noted that the description file does not include logic code, which refers to the code that performs logical operations, such as code guided by statements such as if, else, and when.
[0051] S102: Generate a translator and a configuration file corresponding to the first DSL based on the description file, where the configuration file includes N rules.
[0052] Based on the keywords defined in the description file and the N rules for generating the translator, a translator and configuration file corresponding to the first DSL are generated. The configuration file includes the N rules, and the N rules in the configuration file are user-modifiable. For example, when the user subsequently uses the translator, they can translate the input text to be translated based on the N rules, or they can modify the rules in the configuration file and translate the input text to be translated based on the modified rules.
[0053] The generated translator can be used to translate the first DSL. For example, a text to be translated, written in the first DSL, is input into the translator. The translator can then translate the text into a syntax tree corresponding to the first DSL. The generated syntax tree can be used in other applications.
[0054] The generated translator can also be used to translate into other languages. In one implementation, the N rules in the description file also include recognition rules for the second DSL. For example, if the generated translator has the functions of a lexical parser and a grammatical parser, the recognition rules for the second DSL include lexical parsing rules and grammatical parsing rules. In this case, the generated translator can also be used to translate the second DSL. For example, by inputting a text to be translated written in the second DSL into the generated translator, the translator can translate the text into a syntax tree corresponding to the second DSL. The generated syntax tree can then be used in other applications.
[0055] In one implementation, after the text to be translated is input into the translator, the translator may directly translate the text to be translated into a corresponding syntax tree, wherein the text to be translated may be written based on the first DSL or the second DSL.
[0056] In another implementation, after the text to be translated is input into the translator, a configuration file may also be input into the translator. The translator translates the text to be translated into a corresponding syntax tree based on the rules in the configuration file. The text to be translated may be written based on the first DSL or the second DSL.
[0057] Optionally, the N rules in the configuration file can be updated to M rules, specifically including any one or a combination of the following: adding a new rule based on the N rules; deleting at least one rule in the N rules; or modifying at least one rule in the N rules. That is, at least one rule in the M rules does not belong to the N rules, or at least one rule in the N rules does not belong to the M rules. In another implementation, after the N rules in the configuration file are updated to M rules, the configuration file is input into a translator, and the translator translates the text to be translated based on the updated rules to obtain the corresponding syntax tree.
[0058] Optionally, the above-mentioned second DSL can be any one of the DBC description language, CMake script language, and GCOV description language. Among them, DBC is database CAN, which means the CAN message database. DBC defines the relevant information of CAN communication. The DBC description language refers to the language used to describe CAN messages. CMake is a cross-platform installation (compilation) tool that can use simple statements to describe the installation (compilation) process of all platforms, where simple statements are scripts. The CMake script language refers to the language used by the CMake script. The CMake script language can be, for example, CMakeLists, CMakeCache or others. GCOV is GNU Coverage, which means GNU coverage report, where GNU is an open source organization for calculating code coverage. Code coverage is a metric in software testing that describes the proportion and degree of source code tested in a program. The GCOV description language refers to the language used to describe code coverage. The second DSL in this application can also be other languages, which is not limited in this application.
[0059] It can be seen that in the present application, the description file is obtained based on the configuration and does not include logic code. Compared with the use of regular expressions to represent the description file, the method of representing the description file in the present application is simpler; according to the method described in the present application, a translator and a configuration file are generated, wherein the configuration file can be used for users to modify the rules. When the user's needs change, the rules in the configuration file can be modified, and the modified configuration file can be input into the translator to translate the text to be translated. The translator generated by the method described in the present application can meet the different needs of different users, and the translator has strong applicability; when translating the text to be translated, the translator generated by the method of the present application can directly input the text to be translated into the translator for translation, which is simple to operate and easy to use; the translator generated by the present application can support translation of multiple languages.
[0060] Based on the description file, a translator and configuration file corresponding to the first DSL are generated. In one implementation, this can be achieved using a fractal tree. Referring to FIG3 , FIG3 is a partial flow diagram of a translator generation method provided in this application, which includes but is not limited to the following description.
[0061] S1021. Generate a fractal tree according to N rules defined in the description file, wherein each of the N rules is a branch of the fractal tree, and at least one wildcard in a first rule is a virtual root node on the branch where the first rule is located.
[0062] Each of the N rules represents a branch of the fractal tree, so the fractal tree has a total of N branches. The number of wildcards included in the first rule indicates the number of virtual root nodes on the branch where the first rule resides. For example, if the first rule includes one wildcard, the branch where the first rule resides will have one virtual root node; if the first rule includes two wildcards, the branch where the first rule resides will have two virtual root nodes, and so on.
[0063] A virtual root node is different from a root node. The root node is the node at the root of the entire fractal tree, and the entire fractal tree has only one root node. A virtual root node is the root node of the branch consisting of the target string after the wildcard. A branch can have zero, one, or more virtual root nodes, and the entire fractal tree can have one or more virtual root nodes.
[0064] Referring to FIG4 , FIG4 is a schematic diagram of the structure of a fractal tree provided by the present application. In the fractal tree shown in FIG4 , q0 is the root node of the fractal tree. The content of the root node can be one or more target strings or a null character. For ease of representation, “-1” is used to represent a virtual root node, and the content of the virtual root node is a wildcard. In addition to the root node and the virtual root node, the content of other nodes can be one or more target strings or a null character.
[0065] The fractal tree shown in Figure 4 includes eight branches, each corresponding to a rule. For example, the first branch corresponds to the rule "q0q1q3 first wildcard q10q14q19", where the wildcard on the first branch is called the first wildcard, which can be "*" or "?". For example, the second branch corresponds to the rule "q0q1q3 first wildcard q10q14q20q25", the third branch corresponds to the rule "q0q1q3 first wildcard q10q14q20q26", the fourth branch corresponds to the rule "q0q1q3 first wildcard q10q15q21", the fifth branch corresponds to the rule "q0q1q3 first wildcard q11q16q22", the sixth branch corresponds to the rule "q0q1q3q7q12q17q23", the seventh branch corresponds to the rule "q0q1q4q8", and the eighth branch corresponds to the rule "q0q2q5q9 second wildcard q18q24", among which the wildcard on the eighth branch is called the second wildcard, and the second wildcard can be "*" or "?". Here, for ease of understanding, the wildcard on the first branch (first wildcard) and the wildcard on the eighth branch (second wildcard) are distinguished by first and second. In actual applications, the first wildcard and the second wildcard can be the same or different.
[0066] In the schematic diagram of FIG4 , the first, second, third, fourth, fifth, and eighth branches each include only one wildcard, while the sixth and seventh branches do not include a wildcard. In actual applications, each branch of the fractal tree may include a greater or fewer number of wildcards, that is, each branch may include a greater or fewer number of virtual root nodes. FIG4 is for illustrative purposes only and does not constitute a limitation of the present application.
[0067] It can be understood that the virtual root node is the root node of the branch consisting of the target string after the wildcard. In the schematic diagram of Figure 4, the virtual root node where the first wildcard is located is the root node of the branch "first wildcard q10q14q19", the root node of the branch "first wildcard q10q14q20q25", the root node of the branch "first wildcard q10q14q20q26", the root node of the branch "first wildcard q10q15q21", and the root node of the branch "first wildcard q11q16q22". The virtual root node where the second wildcard is located is the root node of the branch "second wildcard q18q24".
[0068] S1022. Generate a translator and configuration file based on the fractal tree.
[0069] Based on the fractal tree, an AC automaton can be constructed, and based on the AC automaton, a translator and a configuration file can be generated. When constructing the AC automaton, a failure pointer needs to be set. In the fractal tree provided by this application, the failure pointer can point to the root node or to a virtual root node. In actual applications, the direction of the failure pointer can be set according to specific circumstances. For ease of understanding, refer to Figure 5, which is an example diagram provided by this application. From Figure 5, the failure pointers of some nodes are set to return to the root node, and the failure pointers of some nodes are set to return to the virtual root node. Figure 5 is only an example and does not constitute any limitation to this application. In actual applications, the return node of the failure pointer can be set according to specific circumstances.
[0070] As can be seen, this application provides a new fractal tree structure that sets a virtual root node in the fractal tree. By setting the virtual root node, N rules in the description file are constructed on a tree. When generating the translator, only the fractal tree needs to be traversed once. Compared with the traditional fractal tree structure that constructs N rules on multiple trees and traverses multiple trees when generating the translator, the method described in this application is lightweight in both time and space dimensions.
[0071] The above describes in detail the method of the embodiment of the present application. The following provides an apparatus of the embodiment of the present application.
[0072] Referring to FIG. 6 , FIG. 6 is a schematic diagram of the structure of a translator generation device 600 provided in this application. The device 600 can be configured as an in-vehicle computing platform, a local server such as a desktop computer, a cloud server such as a central server or edge server, or a virtual machine or container. The device 600 includes:
[0073] An acquisition module 610 is configured to acquire a description file, wherein the description file defines keywords involved in the first DSL and N rules for generating a translator, where N is greater than or equal to 1. The description file is obtained based on a configuration, wherein a first rule among the N rules includes multiple target strings and at least one wildcard, and the first rule is any one of the N rules.
[0074] The generating module 620 is configured to generate a translator and a configuration file corresponding to the first DSL based on the description file, where the configuration file includes N rules.
[0075] In a possible implementation, the generation module 620 is used to: generate a fractal tree based on N rules, each of the N rules is a branch of the fractal tree, and at least one wildcard in the first rule is a virtual root node on the branch where the first rule is located, and the virtual root node is different from the root node of the fractal tree; generate a translator and a configuration file based on the fractal tree.
[0076] In a possible implementation, the keyword includes one or more of the name of the description file, the import rule of the description file, the type of the translator, and the language used by the translator.
[0077] In a possible implementation, the N rules include recognition rules for the second DSL. The acquisition module 620 is further configured to acquire text to be translated input by a user, where the text to be translated is written using the first DSL or the second DSL. The apparatus 600 further includes a translation module 630 configured to translate the text to be translated into a corresponding syntax tree using a translator.
[0078] In a possible implementation, the translation module 630 is configured to: input the configuration file into a translator; and translate the text to be translated into a corresponding syntax tree through the translator.
[0079] In a possible implementation, the apparatus 600 further includes: an updating module 640, configured to update the N rules in the configuration file to M rules, wherein at least one rule in the M rules does not belong to the N rules.
[0080] In a possible implementation, the second DSL includes any one of the DBC description language, the CMake script language, and the GCOV description language.
[0081] The various functional modules in FIG6 are used to implement the methods described in the method embodiments of FIG1 to FIG5 . For details, please refer to the description of the specific contents of the method embodiments in FIG1 to FIG5 . For the sake of brevity of the specification, they will not be repeated here.
[0082] It can be understood that the division of the various functional modules in Figure 6 and the corresponding execution steps of each functional module are only an example. In other embodiments, the device 600 can also be divided into more or fewer functional modules according to specific execution steps.
[0083] Refer to Figure 7, which is a structural diagram of a translator generation device 700 provided in an embodiment of the present application. The translator generation device 700 can be a vehicle-mounted computing platform, or a local server or a cloud server, such as a desktop computer, an edge server, a central server, etc., or a virtual machine or a container.
[0084] The translator generating device 700 includes at least one processor 701 and a communication interface 703 , and optionally further includes a memory 702 . The processor 701 , the memory 702 and the communication interface 703 are interconnected via a bus 704 .
[0085] Memory 702 includes, but is not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), or compact disc read-only memory (CD-ROM). Memory 702 is used for storing computer programs and data. Communication interface 703 is used to receive and send data.
[0086] The processor 701 in the translator generating device 700 is configured to read the computer program code stored in the memory 702 and perform the following operations:
[0087] Obtain a description file, where the description file defines keywords involved in the first DSL and N rules for generating a translator, where N is greater than or equal to 1. The description file is obtained based on a configuration, where a first rule among the N rules includes multiple target strings and at least one wildcard, and the first rule is any one of the N rules. Generate a translator and a configuration file corresponding to the first DSL based on the description file, where the configuration file includes the N rules.
[0088] In a possible implementation, generating a translator and a configuration file corresponding to the first DSL based on the description file includes: generating a fractal tree based on N rules, where each of the N rules is a branch of the fractal tree, and at least one wildcard in a first rule is a virtual root node on the branch where the first rule is located, and the virtual root node is different from the root node of the fractal tree; and generating the translator and the configuration file based on the fractal tree.
[0089] In a possible implementation, the N rules include recognition rules of the second DSL, and the method further includes: obtaining text to be translated input by a user, where the text to be translated is written using the first DSL or the second DSL; and translating the text to be translated into a corresponding syntax tree using a translator.
[0090] In a possible implementation, translating the text to be translated into a corresponding syntax tree by a translator includes: inputting a configuration file into the translator; and translating the text to be translated into the corresponding syntax tree by the translator.
[0091] In a possible implementation, before inputting the configuration file into the translator, the method further includes: updating N rules in the configuration file to M rules, at least one of the M rules does not belong to the N rules, or at least one of the N rules does not belong to the M rules.
[0092] In a possible implementation, the second DSL includes any one of the DBC description language, the CMake script language, and the GCOV description language.
[0093] The implementation and beneficial effects of each operation can be referred to the corresponding description of the method embodiments in Figures 1 to 5.
[0094] It is understood that the processor 701 in the embodiment of the present application can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. The general-purpose processor can be a microprocessor or any conventional processor. When the processor 701 is a CPU, the CPU can be a single-core CPU or a multi-core CPU.
[0095] The present application also provides a storage medium comprising program instructions, which, when executed by a processor, causes the processor to execute the above-mentioned translator generation method.
[0096] The present application also provides a computer program product, which may be software or a program product containing instructions and capable of running on a computing device or stored in any available medium. When the computer program product runs on a processor, the processor executes the above-mentioned translator generation method.
[0097] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an erasable programmable read-only memory, an electrically erasable programmable read-only memory, a register, a hard disk, a mobile hard disk, a CD-ROM or any other form of storage medium well known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.
[0098] In the various embodiments of the present application, unless otherwise specified or there is a logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced by each other. The technical features in different embodiments can be combined to form new embodiments according to their inherent logical relationships.
[0099] In this application, the terms "comprise" or "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process / method comprising a series of steps, or a system / product / apparatus comprising a series of units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes / methods / products / apparatus.
Claims
1. A translator generation method, characterized in that: include: Obtaining a description file, wherein the description file defines keywords involved in a first domain-specific language (DSL) and N rules for generating a translator, where N is greater than or equal to 1, the description file being obtained based on a configuration, a first rule among the N rules including multiple target strings and at least one wildcard, and the first rule being any one of the N rules; Based on the description file, a translator and a configuration file corresponding to the first DSL are generated, where the configuration file includes the N rules.
2. The method according to claim 1, characterized in that The generating, based on the description file, a translator and a configuration file corresponding to the first domain-specific language DSL, includes: generating a fractal tree according to the N rules, wherein each of the N rules is a branch of the fractal tree, and at least one wildcard in the first rule is a virtual root node on the branch where the first rule is located, and the virtual root node is different from the root node of the fractal tree; The translator and the configuration file are generated according to the fractal tree.
3. The method according to claim 1 or 2, characterized in that The keywords include one or more of the name of the description file, the import rules of the description file, the type of the translator, and the language used by the translator.
4. The method according to any one of claims 1 to 3, characterized in that The N rules include an identification rule for the second DSL, and the method further includes: Acquire a text to be translated input by a user, where the text to be translated is written using the first DSL or the second DSL; The text to be translated is translated into a corresponding syntax tree by the translator.
5. The method according to claim 4, characterized in that The translator translating the text to be translated into a corresponding syntax tree includes: inputting the configuration file into the translator; The text to be translated is translated into a corresponding syntax tree by the translator.
6. The method according to claim 5, characterized in that Before inputting the configuration file into the translator, the method further includes: The N rules in the configuration file are updated to M rules, at least one of the M rules does not belong to the N rules, or at least one of the N rules does not belong to the M rules.
7. The method according to any one of claims 4 to 6, characterized in that The second DSL includes any one of a DBC description language, a CMake script language, and a GCOV description language.
8. A translator generating device, characterized in that: include: An acquisition module is configured to acquire a description file, wherein the description file defines keywords involved in a first domain-specific language (DSL) and N rules for generating a translator, where N is greater than or equal to 1. The description file is obtained based on a configuration, wherein a first rule among the N rules includes multiple target strings and at least one wildcard. The first rule is Any one; A generating module is configured to generate a translator and a configuration file corresponding to the first DSL based on the description file, wherein the configuration file includes the N rules.
9. The device according to claim 8, characterized in that The generation module is used to: generating a fractal tree according to the N rules, wherein each of the N rules is a branch of the fractal tree, and at least one wildcard in the first rule is a virtual root node on the branch where the first rule is located, and the virtual root node is different from the root node of the fractal tree; The translator and the configuration file are generated according to the fractal tree.
10. The device according to claim 8 or 9, characterized in that The keywords include one or more of the name of the description file, the import rules of the description file, the type of the translator, and the language used by the translator.
11. The device according to any one of claims 8 to 10, characterized in that The N rules include an identification rule for the second DSL, and the device further includes a translation module. The acquisition module is further configured to acquire a text to be translated input by a user, where the text to be translated is written using the first DSL or the second DSL; The translation module is configured to translate the text to be translated into a corresponding syntax tree through the translator.
12. The device according to claim 11, characterized in that The translation module is specifically used for: inputting the configuration file into the translator; The text to be translated is translated into a corresponding syntax tree by the translator.
13. The device according to claim 12, characterized in that The device further comprises: An updating module is used to update N rules in the configuration file to M rules, at least one of the M rules does not belong to the N rules, or at least one of the N rules does not belong to the M rules.
14. The device according to any one of claims 11 to 13, characterized in that The second DSL includes any one of a DBC description language, a CMake script language, and a GCOV description language.
15. A translator generating device, characterized in that: The system comprises a processor and a memory, wherein the memory is used to store instructions, and the processor is used to execute the instructions stored in the memory to perform the method according to any one of claims 1 to 7.
16. The device according to claim 15, characterized in that The device is an in-vehicle computing platform or server.
17. A storage medium, characterized in that: The method comprises program instructions, which, when executed by a processor, cause the processor to perform the method according to any one of claims 1 to 7.