Intermediate representation generation method and device based on domestic modeling language X language
By preprocessing, lexical analysis, syntax analysis, semantic analysis and integration processing of the domestic modeling language X code, the X language intermediate representation information is generated, which solves the problem that X language is difficult to convert quickly and efficiently into intermediate representation in the existing technology, and improves the executability and engineering degree of the X language model.
Patent Information
- Application Number
- CN202411590740.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-02-28
AI Technical Summary
The existing technology lacks an effective intermediate representation generation method, which makes it difficult for the domestic modeling language X to quickly and efficiently convert into intermediate representations that can be interpreted by programs, which in turn affects the executability and engineering degree of the X language model.
A method of intermediate representation generation based on the domestic modeling language X language is proposed. By obtaining X language code information, preprocessing, lexical analysis, syntax analysis, semantic analysis and integration processing are performed to generate X language intermediate representation information.
It realizes the rapid and efficient conversion of X language into an intermediate representation that can be interpreted by programs, which promotes the improvement of the executability and engineering degree of X language model.
Smart Images

Figure CN119536731A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of complex system modeling, simulation and compilation, and in particular to a method and device for generating an intermediate representation based on a domestic modeling language X. Background Art
[0002] X language is a new generation of integrated modeling and simulation language for complex systems supporting MBSE. As a newly designed modeling language, it has completed the theoretical foundation and methodology, and needs a supporting tool set to move from theory to practice, among which the compiler is the most core component. The main function of the compiler is to compile the model code developed in X language into a runnable program. During the compilation process, the first half is the lexical analysis, syntax analysis, and semantic analysis of the X language code, and the intermediate representation IR is generated by reorganization and association. At present, the engineering-level compilation technology for X language is a blank module. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a method and device for generating an intermediate representation based on a domestic modeling language X, which can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by a program, which is an important step in converting the X language model into an executable program and an important link in the engineering of the X language.
[0004] In order to solve the above technical problems, the first aspect of the embodiment of the present invention discloses a method for generating an intermediate representation based on a domestic modeling language X, the method comprising:
[0005] S1, obtain X language code information;
[0006] S2, preprocessing the X language code information to obtain X language information; the X language information includes N lines of code information; N is a positive integer;
[0007] S3, processing the X language information to obtain X language intermediate representation information.
[0008] As an optional implementation manner, in the first aspect of the embodiment of the present invention, the preprocessing of the X language code information to obtain the X language information includes:
[0009] S21, performing macro definition expansion processing on the X language code information to obtain first code information;
[0010] S22, deleting comments from the first code information to obtain second code information;
[0011] S23, processing the second code information to obtain third code information;
[0012] S24, performing format processing on the third code information to obtain X language information.
[0013] As an optional implementation manner, in the first aspect of the embodiment of the present invention, the processing the second code information to obtain the third code information includes:
[0014] S231, performing invalid code elimination processing on the second code information to obtain fourth code information;
[0015] S232, performing inline expansion processing on the fourth code information to obtain fifth code information;
[0016] S233: Perform path optimization processing on the fifth code information to obtain third code information.
[0017] As an optional implementation manner, in the first aspect of the embodiment of the present invention, the processing the X language information to obtain the X language intermediate representation information includes:
[0018] S31, performing lexical analysis on the X language information to obtain X language lexical information; the X language lexical information includes a plurality of X language vocabulary unit information;
[0019] S32, performing syntax analysis on the X language lexical information to obtain X language syntax tree information;
[0020] S33, performing inclusion relationship parsing processing on the X language syntax tree information to obtain updated X language syntax tree information, and determining that the updated X language syntax tree information is the X language syntax tree information;
[0021] S34, performing semantic analysis on the X language syntax tree information to obtain X language semantic information;
[0022] S35, integrating the X language lexical information, the X language syntax tree information and the X language semantic information to obtain X language intermediate representation information.
[0023] As an optional implementation manner, in the first aspect of the embodiment of the present invention, performing lexical analysis on the X language information to obtain the X language lexical information includes:
[0024] S311, preset s=1;
[0025] S312, performing word segmentation processing on the code information in the sth line of the X language information to obtain vocabulary information to be processed; the vocabulary information to be processed includes a plurality of vocabulary to be processed;
[0026] S313, processing any of the to-be-processed words in the to-be-processed word information to obtain word matching result information corresponding to the to-be-processed word;
[0027] When the word matching result information is yes, the word to be processed is processed to obtain the X language word unit information corresponding to the word to be processed;
[0028] When the word matching result information is negative, execute S314;
[0029] S314, analyzing and processing the vocabulary to be processed to obtain the X language vocabulary unit information corresponding to the vocabulary to be processed;
[0030] S315, determining whether s is equal to N, and obtaining a first determination result;
[0031] When the first judgment result is no, increase the s by 1 and execute S312;
[0032] When the first judgment result is yes, execute S32.
[0033] As an optional implementation manner, in the first aspect of the embodiment of the present invention, the analyzing and processing the vocabulary to be processed to obtain the X language vocabulary unit information corresponding to the vocabulary to be processed includes:
[0034] S3141, obtaining X language keyword information; the X language keyword information includes a plurality of X language keywords;
[0035] S3142, respectively performing vectorization processing on the to-be-processed vocabulary and the X language keyword information to obtain a to-be-processed vocabulary vector and an X language keyword vector information set corresponding to the to-be-processed vocabulary; the X language keyword vector information set includes a plurality of X language keyword vector information;
[0036] S3143: Analyze and process the to-be-processed vocabulary vector and the X language keyword vector information set corresponding to the to-be-processed vocabulary to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary.
[0037] As an optional implementation manner, in the first aspect of the embodiment of the present invention, the analyzing and processing the to-be-processed vocabulary vector and the X language keyword vector information set corresponding to the to-be-processed vocabulary to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary includes:
[0038] S31431, using a vocabulary matching calculation model, calculating and processing the to-be-processed vocabulary vector corresponding to the to-be-processed vocabulary and the X language keyword vector information set to obtain vocabulary matching value information; the vocabulary matching value information includes a plurality of vocabulary matching values;
[0039] Wherein, the vocabulary matching calculation model is:
[0040]
[0041] Wherein, XSD is the vocabulary matching value information, XSD i is the i-th vocabulary matching value in the vocabulary matching value information, CH1 is the vocabulary vector to be processed, CH2 i is the i-th X language keyword vector information in the X language keyword vector information set, · represents the dot product, × represents the product, ‖·‖ represents the modulus of the vector, δ1 represents the sensitivity adjustment coefficient, δ2 represents the modulus length weight coefficient, and M represents the number of the X language keyword vector information in the X language keyword vector information set;
[0042] S31432, determining a target matching value based on the vocabulary matching value information; the target matching value is the vocabulary matching value with the largest value in the vocabulary matching value information;
[0043] S31433, determining whether the target matching value is greater than or equal to a preset matching threshold, and obtaining a second determination result;
[0044] When the second judgment result is yes, it is determined that the X language keyword corresponding to the target matching value is the word to be processed, and S31434 is executed;
[0045] When the second judgment result is no, execute S31435;
[0046] S31434, analyzing and processing the vocabulary to be processed to obtain the X language vocabulary unit information corresponding to the vocabulary to be processed;
[0047] S31435, update the vocabulary to be processed to obtain an updated vocabulary to be processed, and determine that the updated vocabulary to be processed is the vocabulary to be processed, and execute S312.
[0048] A second aspect of an embodiment of the present invention discloses an intermediate representation generation device based on a domestic modeling language X, the device comprising:
[0049] The acquisition module is used to obtain the X language code information;
[0050] A preprocessing module, used for preprocessing the X language code information to obtain X language information; the X language information includes N lines of code information; N is a positive integer;
[0051] The analysis and calculation module is used to process the X language information to obtain X language intermediate representation information.
[0052] The third aspect of the embodiment of the present invention discloses a storage data structure, which is used for temporarily storing and describing data of the intermediate representation information of the language X in the intermediate representation generation method based on the domestic modeling language X disclosed in the first aspect of the embodiment of the present invention.
[0053] A fourth aspect of an embodiment of the present invention discloses a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions. When the computer instructions are called, they are used to execute part or all of the steps of the intermediate representation generation method based on the domestic modeling language X language disclosed in the first aspect of the embodiment of the present invention.
[0054] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0055] In the embodiment of the present invention, X language code information is obtained; the X language code information is preprocessed to obtain X language information; the X language information includes N lines of code information; N is a positive integer; the X language information is processed to obtain X language intermediate representation information. It can be seen that the present application can quickly and efficiently transform the domestic modeling language X language into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link in the X language's move towards engineering. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0057] Figure 1 A schematic diagram of a flow chart of a method for generating an intermediate representation based on a domestic modeling language X disclosed in an embodiment of the present invention;
[0058] Figure 2 A schematic diagram of the structure of an intermediate representation generation device based on a domestic modeling language X disclosed in an embodiment of the present invention;
[0059] Figure 3 It is a schematic diagram of the structure of another intermediate representation generation device based on the domestic modeling language X disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0060] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme 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 only part of the embodiments of the present invention, not all of the embodiments. 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.
[0061] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or equipment that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or equipment.
[0062] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0063] X language is a modeling and simulation language. It is a new generation of modeling and simulation language that supports MBSE (model-based system engineering), and can realize the integrated modeling and simulation of system-level modeling of complex systems and their functional performance simulation verification.
[0064] MBSE is the abbreviation of "Model-Based Systems Engineering". It is a modern system engineering methodology that aims to support the entire life cycle of the system by using modeling technology, including various stages from conceptual design, requirements analysis, system design to verification and validation.
[0065] "Intermediate Representation" (IR) refers to an abstract representation in the process of converting source code to machine code.
[0066] The present invention discloses a method and device for generating an intermediate representation based on a domestic modeling language X, which can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by a program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering. The following are detailed descriptions.
[0067] Embodiment 1
[0068] See also Figure 1 , Figure 1 It is a flow chart of a method for generating an intermediate representation based on a domestic modeling language X disclosed in an embodiment of the present invention. Figure 1 The described method for generating an intermediate representation based on the domestic modeling language X is applied to an intermediate representation generating device based on the domestic modeling language X, such as a local server or cloud server for optimizing and managing the generation of an intermediate representation based on the domestic modeling language X, which is not limited in the embodiments of the present invention. Figure 1 As shown, the intermediate representation generation method based on the domestic modeling language X language may include the following operations:
[0069] S1, obtain X language code information;
[0070] S2, preprocessing the X language code information to obtain X language information; the X language information includes N lines of code information; N is a positive integer;
[0071] S3, processing the X language information to obtain the X language intermediate representation information.
[0072] It should be noted that the X language intermediate representation information is the intermediate representation corresponding to the X language.
[0073] It can be seen that the implementation of the intermediate representation generation method based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0074] In an optional embodiment, preprocessing the X language code information to obtain the X language information includes:
[0075] S21, performing macro definition expansion processing on the X language code information to obtain first code information;
[0076] It should be noted that the above macro definition expansion process is to expand the macro definition in the X language code information and replace the macro with a specific code fragment or value to avoid repeated parsing.
[0077] S22, deleting comments from the first code information to obtain second code information;
[0078] It should be noted that the above comment deletion process is to delete all the comment contents in the first code information, thereby increasing the parsing speed of the compiler and being beneficial to improving the compilation efficiency of the X language.
[0079] S23, processing the second code information to obtain third code information;
[0080] S24, performing format processing on the third code information to obtain X language information.
[0081] It should be noted that the above-mentioned format processing is to unify the third code information into a unified code format, ensure the consistency of the code structure, improve the readability of the code and the accuracy of subsequent analysis, such as unifying into json or yaml format, which is not limited in detail in the embodiments of the present invention.
[0082] It can be seen that the implementation of the intermediate representation generation method based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0083] In an optional embodiment, the second code information is processed to obtain the third code information, including:
[0084] S231, performing invalid code elimination processing on the second code information to obtain fourth code information;
[0085] It should be noted that the above-mentioned invalid code elimination process is to eliminate the code segments that cannot be executed from the second code information, such as conditional branches that will never be triggered (such as branches of if (false)), to reduce the compilation amount and improve compilation efficiency.
[0086] S232, performing inline expansion processing on the fourth code information to obtain fifth code information;
[0087] It should be noted that the above-mentioned inline expansion processing is to expand small functions directly to the call point to avoid the overhead of function calls, which can effectively improve the operating efficiency of small functions that are frequently called.
[0088] It should be noted that the above-mentioned small function is a function with a code line number range of less than 100 lines, and the embodiment of the present invention does not make any specific limitation.
[0089] S233, performing path optimization processing on the fifth code information to obtain third code information.
[0090] It should be noted that the above path optimization processing is to perform path parsing, optimization and shortening in advance in the path-related code. For example, the path information of "a / b / .. / c" in the code is directly processed into the format of "a / c" to reduce the burden of path parsing at runtime, which is conducive to improving the running efficiency of the X language code.
[0091] It can be seen that the implementation of the intermediate representation generation method based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0092] In another optional embodiment, processing the X language information to obtain the X language intermediate representation information includes:
[0093] S31, performing lexical analysis on the X language information to obtain the X language lexical information; the X language lexical information includes a plurality of X language vocabulary unit information;
[0094] It should be noted that the lexical analysis process is performed according to the lexical rules of the X language, and the specific details are not limited in the embodiment of the present invention.
[0095] The lexical rules of language X are as follows:
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103] Lexical parsing first reads all source code information and matches lexical rules sentence by sentence. During lexical parsing, a line of source code is split into tokens (lexical units) separated by spaces. For example, the first sentence "discreteShiftLogic" is split into two parts: discrete and ShiftLogic. Lexical matching is performed to determine whether there are lexical rules to determine whether it matches the lexical design. Discrete matches the class_prefixes in the grammar rules.
[0104] :('partial')? ('class'|'continuous'|'discrete'|'couple'|'connector'|'enum'|'record'|'function'|'agent'); rule, we can see that discrete is a type declaration keyword, ShiftLogic matches the class_specifier rule, it is a type name, and complies with the grammar rules. These tokens are stored for grammar parsing.
[0105] S32, performing grammar analysis on the X language lexical information to obtain the X language grammar tree information;
[0106] It should be noted that the above-mentioned syntax analysis process is performed according to the syntax rules of the X language, and the specific details are not limited in the embodiment of the present invention.
[0107] For example, after lexical analysis, a series of matching grammar rules and tokens are generated. The main function of grammar analysis is to build an abstract syntax tree of the source code file, that is, to parse each source code sentence and find out which grammar rule is matched automatically, and then recursively call the parsing function of each grammar to parse the meaning of the code. For example, the source code is as follows:
[0108]
[0109] The grammar rule first calls the visitport_prefix function for parsing. It can be seen that it matches the grammar rule of "|'event" input'#event_input" in the above code. The subsequent tokens real down_th match the next-level grammar rule event_input. Then the grammar parsing function of event_input is called. It can be seen that real is the type keyword and down_th is the variable name. Through the above grammar parsing, it can be seen that the source code indicates that an event input port variable is declared, the type is real, and the variable name is down_th.
[0110] S33, performing inclusion relationship parsing processing on the X language syntax tree information to obtain updated X language syntax tree information, and determining that the updated X language syntax tree information is the X language syntax tree information;
[0111] It should be noted that the above-mentioned inclusion relationship resolution process is a grammatical analysis, and each class or function obtains a metadata object that describes its information. After that, it will check whether the reference relationship between these classes or functions is correct. The main check content includes whether the introduced module or function exists, whether the calling method of the introduced module or function is correct, etc. After the inclusion relationship resolution is passed, the referenced information is saved in the information of the referencer. The specific details are not limited in the embodiments of the present invention. For example:
[0112]
[0113]
[0114] In the above source code, types of other files are referenced. The import Engine code indicates that all types in the Engine.xl file are referenced. In this example, the Engine type is used, and the Ne port of this type is used. Therefore, it is necessary to detect whether the Engine type exists and whether the Engine type has the Ne output port during compilation. The way to find it is to first check whether the syntax parsing of the Engine source code file has been completed. If the parsing is completed, query from the parsing results. If the parsing is not completed, the parsing of the Engine source code file is completed first.
[0115] S34, performing semantic analysis on the syntax tree information of language X to obtain semantic information of language X;
[0116] It should be noted that the above semantic analysis is processed according to the semantic analysis rules of the X language. Specifically, the class and function meta-objects in the grammatical information of the X language are traversed, and the information is associated and parsed one by one to analyze whether the semantics are correct. For example, whether the variables used in the code have been declared in advance, whether the called function has passed in the correct parameters, whether the other referenced types have established index information, etc. The specific embodiment of the present invention does not limit this.
[0117] The specific semantic analysis rules of the X language may be set by the user or acquired according to historical setting information, which is not limited in the embodiment of the present invention.
[0118] For example, semantic analysis is to parse the context structure of the code to see if there are any semantic errors, such as:
[0119]
[0120] The connect(vl.Nout,ts.Nout) code complies with the syntax design rules, but cannot pass the semantic analysis phase because the variable name vl used cannot be found in the Controller type definition, which is a semantic error. The interfaces and types used in connect(pm.Throttle,pr.Throttle) can all be found, and the relevant information can be extracted and stored in the intermediate representation of the Controller type.
[0121] S35, integrating the X language lexical information, the X language syntax tree information and the X language semantic information to obtain the X language intermediate representation information.
[0122] It should be noted that the X language lexical information, the X language syntax tree information and the X language semantic information are integrated to obtain the X language intermediate representation information, which is to store all the information of the X language lexical information, the X language syntax tree information and the X language semantic information in a corresponding metadata structure according to different types and structures, that is, the intermediate representation of the X language code. Specifically, the integration process is set by a user, or is obtained by integrating the process according to the rule of generating the intermediate representation of the X language, which is not limited in the embodiment of the present invention.
[0123] For example, the final generated X language intermediate representation information is as follows:
[0124]
[0125]
[0126]
[0127] It should be noted that the above-mentioned lexical parsing, grammatical parsing, inclusion relationship parsing and semantic analysis can also be performed by acquiring lexical rule information, grammatical rule information, inclusion relationship rule information and semantic rule information of the X language, and using the ANTLR tool to generate a lexical parser and a grammatical parser through the lexical rule information and the grammatical rule information, and using the LLVM tool to generate an inclusion relationship parser and a semantic parser through the inclusion relationship rule information and the semantic rule information, and finally using the lexical parser to perform lexical parsing processing on the X language information to obtain the X language lexical information, using the grammatical parser to perform grammatical parsing processing on the X language lexical information to obtain the X language syntax tree information, using the inclusion relationship parser to perform inclusion relationship parsing processing on the X language syntax tree information to obtain the updated X language syntax tree information, and using the semantic parser to perform semantic analysis processing on the X language syntax tree information to obtain the X language semantic information, and the specific embodiment of the present invention is not limited.
[0128] It can be seen that the implementation of the intermediate representation generation method based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0129] In yet another optional embodiment, performing lexical analysis on the X language information to obtain the X language lexical information includes:
[0130] S311, preset s=1;
[0131] S312, performing word segmentation processing on the s-th line of code information in the X language information to obtain vocabulary information to be processed; the vocabulary information to be processed includes a plurality of vocabulary to be processed;
[0132] It should be noted that the above word segmentation process can be processed by using ANTLR or Flex, and the specific embodiment of the present invention does not limit this.
[0133] S313, processing any word to be processed in the word information to be processed, and obtaining word matching result information corresponding to the word to be processed;
[0134] It should be noted that the above processing of any word to be processed in the word information to be processed is to completely match any word to be processed with all the keywords in the X language. If a keyword in the X language is matched, the matching is completed and the word matching result information is set to yes. If the matching with all the keywords in the X language fails, the word matching result information is set to no.
[0135] When the word matching result information is yes, the word to be processed is processed to obtain the X language word unit information corresponding to the word to be processed;
[0136] It should be noted that the X language vocabulary unit information includes a vocabulary unit, a type, a row number and a column number. The to-be-processed vocabulary is processed to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary, which is to set the vocabulary unit in the X language vocabulary unit information to the to-be-processed vocabulary, set the type to the type information of the to-be-processed vocabulary, such as a keyword, an identifier, an assignment operator, a constant, etc., and set the row number and the column number to the specific row number and column number of the to-be-processed vocabulary in the X language information, respectively.
[0137] When the word matching result information is negative, execute S314;
[0138] S314, analyzing and processing the vocabulary to be processed to obtain X language vocabulary unit information corresponding to the vocabulary to be processed;
[0139] It should be noted that, by analyzing and processing the vocabulary to be processed to obtain the X language vocabulary unit information corresponding to the vocabulary to be processed, the lexical error tolerance rate of the generated intermediate representation of the X language can be improved. When there are erroneous code words in the X language code, an efficient error tolerance mechanism can be implemented through this step, thereby improving the efficiency of the generated intermediate representation of the X language code.
[0140] S315, determining whether s is equal to N, and obtaining a first determination result;
[0141] When the first judgment result is no, s is increased by 1 and S312 is executed;
[0142] When the first judgment result is yes, S32 is executed.
[0143] It can be seen that the implementation of the intermediate representation generation method based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0144] In an optional embodiment, the to-be-processed vocabulary is analyzed and processed to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary, including:
[0145] S3141, obtaining X language keyword information; the X language keyword information includes a plurality of X language keywords;
[0146] It should be noted that the X language keyword information includes all keywords defined in the X language, such as discrete, parameter, port, and state, etc., which are not specifically limited in the embodiment of the present invention.
[0147] S3142, respectively performing vectorization processing on the vocabulary to be processed and the X language keyword information to obtain a vocabulary vector to be processed and an X language keyword vector information set corresponding to the vocabulary to be processed; the X language keyword vector information set includes a plurality of X language keyword vector information;
[0148] It should be noted that the above-mentioned vectorization processing can be performed using Word2Vec, FastText, etc., and the specific embodiment of the present invention does not limit it.
[0149] S3143: Analyze and process the to-be-processed vocabulary vector and the X language keyword vector information set corresponding to the to-be-processed vocabulary to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary.
[0150] It can be seen that the implementation of the intermediate representation generation method based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0151] In an optional embodiment, the to-be-processed vocabulary vector and the X language keyword vector information set corresponding to the to-be-processed vocabulary are analyzed and processed to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary, including:
[0152] S31431, using a vocabulary matching calculation model, calculating and processing the to-be-processed vocabulary vector corresponding to the to-be-processed vocabulary and the X language keyword vector information set to obtain vocabulary matching value information; the vocabulary matching value information includes a plurality of vocabulary matching values;
[0153] Among them, the vocabulary matching calculation model is:
[0154]
[0155] In the formula, XSD is the vocabulary matching value information, XSD i is the i-th vocabulary matching value in the vocabulary matching value information, CH1 is the vocabulary vector to be processed, CH2 i is the i-th X language keyword vector information in the X language keyword vector information set, · represents the dot product, × represents the product, ‖·‖ represents the modulus of the vector, δ1 represents the sensitive adjustment coefficient, δ2 represents the modulus length weight coefficient, and M represents the number of X language keyword vector information in the X language keyword vector information set;
[0156] It should be noted that the value ranges of δ1 and δ2 are both in [0.9, 1.1]. Specifically, they may be set by the user or obtained based on historical data, which is not limited in the embodiment of the present invention.
[0157] It should be noted that δ1 is used to control the weight of the inner product term (typical value is 1, increasing δ1 will increase the similarity score of similar vectors), and δ2 is used to control the influence of the feature vector modulus on the similarity (default value is 1). By setting the values of δ1 and δ2, the vocabulary matching calculation is more flexible. By selecting appropriate values of δ1 and δ2, the similarity measurement of specific characters or features can be optimized, which is conducive to improving the quality and efficiency of the intermediate generation representation of the X language.
[0158] S31432, based on the vocabulary matching value information, determining a target matching value; the target matching value is a vocabulary matching value with the largest value in the vocabulary matching value information;
[0159] S31433, determining whether the target matching value is greater than or equal to a preset matching threshold, and obtaining a second determination result;
[0160] It should be noted that the preset matching threshold value has a value range of [0.8, 1), and is not specifically limited in the embodiment of the present invention.
[0161] When the second judgment result is yes, it is determined that the X language keyword corresponding to the target matching value is the word to be processed, and S31434 is executed;
[0162] When the second judgment result is no, execute S31435;
[0163] S31434, analyzing and processing the vocabulary to be processed to obtain X language vocabulary unit information corresponding to the vocabulary to be processed;
[0164] It should be noted that the analysis and processing of the to-be-processed vocabulary to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary is to set the vocabulary unit in the X language vocabulary unit information to the to-be-processed vocabulary, set the type to the type information of the to-be-processed vocabulary, such as a keyword, an identifier, an assignment operator, a constant, etc., and set the row number and column number to the specific row number and column number of the to-be-processed vocabulary in the X language information, respectively.
[0165] S31435, update the vocabulary to be processed to obtain an updated vocabulary to be processed, and determine that the updated vocabulary to be processed is the vocabulary to be processed, and execute S312.
[0166] It should be noted that the above-mentioned update processing can be performed by the user, or by using an automated processing tool, or by executing the following embodiments, which is not limited in detail in the embodiments of the present invention.
[0167] It should be noted that the above update process is to obtain the correct word by updating the word to be processed because the word to be processed is not in the lexical rule of language X, so as to compile the language X information later, and it does not end here. For example, for the keyword discrete, it is written as discreted by mistake, and then the correct discrete is obtained through updating.
[0168] It can be seen that the implementation of the intermediate representation generation method based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0169] In an optional embodiment, updating the vocabulary to be processed to obtain an updated vocabulary to be processed includes:
[0170] S314351, according to the vocabulary to be processed, mark the s-th line of code information to obtain marked code information;
[0171] It should be noted that the above annotations are made clear using special symbols or placeholders (such as <mask>) The problematic words in the s-th line of code information (i.e., the words to be processed) are marked so that they can be focused on during prediction.
[0172] For example, the code information of line s is: code_snippet = "def calculate_area(radius):\nreturnπ*radius**2", where π is the word to be processed. The code information after annotation is: input_text = "defcalculate_area(radius):\n return <mask>*radius**2".
[0173] S314352, using the X language prediction model, calculating and processing the annotated code information to obtain predicted vocabulary information; the predicted vocabulary information includes a plurality of predicted words and vocabulary weight values corresponding to the plurality of predicted words;
[0174] It should be noted that the X language prediction model is obtained by training the GPT or BERT model through a large number of X language training samples, and the specific details are not limited in this embodiment of the present invention.
[0175] It should be noted that the use of the X language prediction model to calculate and process the annotated code information to obtain the predicted vocabulary information is to use the annotated code information as the input of the X language prediction model, perform calculations through the X language prediction model, and output the predicted vocabulary information.
[0176] S314353, calculating and processing the predicted vocabulary information to obtain predicted vocabulary context similarity information; the predicted vocabulary context similarity information includes a plurality of predicted vocabulary context similarity values;
[0177] It should be noted that the predicted vocabulary information is calculated and processed to obtain the predicted vocabulary context similarity information, which is obtained by calculating the cosine similarity between the predicted vocabulary information and the context through BERT, Word2Vec or GPT word embedding, etc., and the specific embodiment of the present invention is not limited thereto.
[0178] S314354, using the X language fusion calculation model, calculating and processing the predicted vocabulary information and the predicted vocabulary context similarity information to obtain weight prediction information; the weight prediction information includes a plurality of weight prediction values;
[0179] Among them, the X language fusion calculation model is:
[0180]
[0181] In the formula, YC is the weight prediction information, YC j is the jth weight prediction value in the weight prediction information, MX j is the vocabulary weight value corresponding to the jth predicted vocabulary in the predicted vocabulary information, XSS j is the j-th predicted word context similarity value in the predicted word context similarity information, θ1, θ2, θ3 and θ4 are respectively the first weight coefficient, the second weight coefficient, the third weight coefficient and the fourth weight coefficient, and L is the number of predicted words in the predicted word information;
[0182] It should be noted that the first weight coefficient, the second weight coefficient, the third weight coefficient and the fourth weight coefficient may be set by a user or may be obtained based on historical data, and the embodiment of the present invention does not limit this.
[0183] It should be noted that the first weight coefficient reflects the basic confidence of the predicted word selected by the model, and the first weight coefficient is used to control its influence; the second weight coefficient enhances the relevance of the predicted word to the context through the weight of the context information; θ3·(MX j XSS j ) considers the product of model prediction and context consistency, that is, the dual consistency of the predicted vocabulary in terms of confidence and adaptability, and adjusts its impact on adaptability through the third weight coefficient; Nonlinear features are introduced, and the interaction value is squared to smooth high confidence and adaptability items, which is suitable for suppressing excessively high or low interaction values. The fourth weight coefficient is used to suppress excessively high or low interaction values.
[0184] It should be noted that, through the X language fusion calculation model, the prediction confidence and the context adaptability weight can be more finely combined to obtain more accurate prediction vocabulary.
[0185] S314355, based on the weight prediction information, determine the updated vocabulary to be processed; the updated vocabulary to be processed is the predicted vocabulary corresponding to the weight prediction value with the largest value in the weight prediction information.
[0186] Embodiment 2
[0187] See also Figure 2 , Figure 2 1 is a schematic diagram of the structure of an intermediate representation generation device based on a domestic modeling language X disclosed in an embodiment of the present invention. Figure 2 The described intermediate representation generation device based on the domestic modeling language X is applied to the intermediate representation generation optimization system based on the domestic modeling language X, such as a local server or cloud server for generating the intermediate representation based on the domestic modeling language X, which is not limited in the embodiment of the present invention. Figure 2 As shown, the intermediate representation generation device based on the domestic modeling language X language includes:
[0188] The acquisition module 201 is used to acquire the X language code information;
[0189] The preprocessing module 202 is used to preprocess the X language code information to obtain the X language information; the X language information includes N lines of code information; N is a positive integer;
[0190] The analysis and calculation module 203 is used to process the X language information to obtain the X language intermediate representation information.
[0191] It can be seen that the implementation of the intermediate representation generation device based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0192] Embodiment 3
[0193] See also Figure 3 , Figure 3 1 is a schematic diagram of the structure of an intermediate representation generation device based on a domestic modeling language X disclosed in an embodiment of the present invention. Figure 3 The described intermediate representation generation device based on the domestic modeling language X is applied to the intermediate representation generation optimization system based on the domestic modeling language X, such as a local server or cloud server for generating the intermediate representation based on the domestic modeling language X, which is not limited in the embodiment of the present invention. Figure 3 As shown, the intermediate representation generation device based on the domestic modeling language X language includes:
[0194] Processor 301;
[0195] A memory 302 coupled to the processor 301 and storing executable program codes;
[0196] The processor 301 calls the executable program code stored in the memory 302 to execute part or all of the steps of the method for generating an intermediate representation based on the domestic modeling language X in the first embodiment.
[0197] It can be seen that the implementation of the intermediate representation generation device based on the domestic modeling language X described in the embodiment of the present invention can quickly and efficiently transform the domestic modeling language X into an intermediate representation that can be interpreted by the program, which is an important step in converting the X language model into an executable program and an important link for the X language to move towards engineering.
[0198] Embodiment 4
[0199] The embodiment of the present invention discloses a storage data structure, which is used for temporarily storing and describing data of the intermediate representation information of the language X in the intermediate representation generation method based on the domestic modeling language X in the first embodiment.
[0200] Embodiment 5
[0201] The embodiment of the present invention discloses a computer-readable storage medium, which stores computer instructions. When the computer instructions are called, they are used to execute part or all of the steps of the intermediate representation generation method based on the domestic modeling language X in the first embodiment.
[0202] Embodiment 6
[0203] The embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute part or all of the steps in the method for generating an intermediate representation based on the domestic modeling language X described in the first embodiment.
[0204] The system embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative labor.
[0205] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or partly contributed to the prior art in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0206] Finally, it should be noted that the method and device for generating an intermediate representation based on the domestic modeling language X disclosed in the embodiment of the present invention disclose only the preferred embodiments of the present invention, and are only used to illustrate the technical solution of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features thereof can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.< / mask> < / mask>
Claims
1. A method for generating an intermediate representation based on a domestic modeling language X, characterized in that: The method comprises: S1, obtain X language code information; S2, preprocessing the X language code information to obtain X language information; the X language information includes N lines of code information; N is a positive integer; S3, processing the X language information to obtain X language intermediate representation information.
2. The method for generating an intermediate representation based on the domestic modeling language X according to claim 1, characterized in that: The preprocessing of the X language code information to obtain the X language information includes: S21, performing macro definition expansion processing on the X language code information to obtain first code information; S22, deleting comments from the first code information to obtain second code information; S23, processing the second code information to obtain third code information; S24, performing format processing on the third code information to obtain X language information.
3. The method for generating an intermediate representation based on the domestic modeling language X according to claim 2, characterized in that: The processing of the second code information to obtain third code information includes: S231, performing invalid code elimination processing on the second code information to obtain fourth code information; S232, performing inline expansion processing on the fourth code information to obtain fifth code information; S233: Perform path optimization processing on the fifth code information to obtain third code information.
4. The method for generating an intermediate representation based on the domestic modeling language X according to claim 1, characterized in that: The processing of the X language information to obtain the X language intermediate representation information includes: S31, performing lexical analysis on the X language information to obtain X language lexical information; the X language lexical information includes a plurality of X language vocabulary unit information; S32, performing syntax analysis on the X language lexical information to obtain X language syntax tree information; S33, performing inclusion relationship parsing processing on the X language syntax tree information to obtain updated X language syntax tree information, and determining that the updated X language syntax tree information is the X language syntax tree information; S34, performing semantic analysis on the X language syntax tree information to obtain X language semantic information; S35, integrating the X language lexical information, the X language syntax tree information and the X language semantic information to obtain X language intermediate representation information.
5. The method for generating an intermediate representation based on the domestic modeling language X according to claim 4, characterized in that: The performing lexical analysis on the X language information to obtain the X language lexical information includes: S311, preset s=1; S312, performing word segmentation processing on the code information in the sth line of the X language information to obtain vocabulary information to be processed; the vocabulary information to be processed includes a plurality of vocabulary to be processed; S313, processing any of the to-be-processed words in the to-be-processed word information to obtain word matching result information corresponding to the to-be-processed word; When the word matching result information is yes, the word to be processed is processed to obtain the X language word unit information corresponding to the word to be processed; When the word matching result information is negative, execute S314; S314, analyzing and processing the vocabulary to be processed to obtain the X language vocabulary unit information corresponding to the vocabulary to be processed; S315, determining whether s is equal to N, and obtaining a first determination result; When the first judgment result is no, increase the s by 1 and execute S312; When the first judgment result is yes, execute S32.
6. The method for generating an intermediate representation based on the domestic modeling language X according to claim 5, characterized in that: The step of analyzing and processing the vocabulary to be processed to obtain the X language vocabulary unit information corresponding to the vocabulary to be processed includes: S3141, obtaining X language keyword information; the X language keyword information includes a plurality of X language keywords; S3142, respectively performing vectorization processing on the to-be-processed vocabulary and the X language keyword information to obtain a to-be-processed vocabulary vector and an X language keyword vector information set corresponding to the to-be-processed vocabulary; the X language keyword vector information set includes a plurality of X language keyword vector information; S3143: Analyze and process the word vector to be processed and the X language keyword vector information set corresponding to the word to be processed to obtain the X language word unit information corresponding to the word to be processed.
7. The method for generating an intermediate representation based on the domestic modeling language X according to claim 6, characterized in that: The analyzing and processing the to-be-processed vocabulary vector and the X language keyword vector information set corresponding to the to-be-processed vocabulary to obtain the X language vocabulary unit information corresponding to the to-be-processed vocabulary includes: S31431, using a vocabulary matching calculation model, calculating and processing the to-be-processed vocabulary vector corresponding to the to-be-processed vocabulary and the X language keyword vector information set to obtain vocabulary matching value information; the vocabulary matching value information includes a plurality of vocabulary matching values; Wherein, the vocabulary matching calculation model is: Wherein, XSD is the vocabulary matching value information, XSD i is the i-th vocabulary matching value in the vocabulary matching value information, CH1 is the vocabulary vector to be processed, CH2 i is the i-th X language keyword vector information in the X language keyword vector information set, · represents the dot product, × represents the product, ‖·‖ represents the modulus of the vector, δ1 represents the sensitivity adjustment coefficient, δ2 represents the modulus length weight coefficient, and M represents the number of the X language keyword vector information in the X language keyword vector information set; S31432, determining a target matching value based on the vocabulary matching value information; the target matching value is the vocabulary matching value with the largest value in the vocabulary matching value information; S31433, determining whether the target matching value is greater than or equal to a preset matching threshold, and obtaining a second determination result; When the second judgment result is yes, it is determined that the X language keyword corresponding to the target matching value is the word to be processed, and S31434 is executed; When the second judgment result is no, executing S31435; S31434, analyzing and processing the vocabulary to be processed to obtain the X language vocabulary unit information corresponding to the vocabulary to be processed; S31435, update the vocabulary to be processed to obtain an updated vocabulary to be processed, and determine that the updated vocabulary to be processed is the vocabulary to be processed, and execute S312.
8. An intermediate representation generation device based on a domestic modeling language X, characterized in that: The device comprises: The acquisition module is used to obtain the X language code information; A preprocessing module, used for preprocessing the X language code information to obtain X language information; the X language information includes N lines of code information; N is a positive integer; The analysis and calculation module is used to process the X language information to obtain X language intermediate representation information.
9. A storage data structure, characterized in that: The storage data structure is used for temporarily storing and describing data of the intermediate representation information of language X in the intermediate representation generation method based on the domestic modeling language X as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the intermediate representation generation method based on the domestic modeling language X according to any one of claims 1 to 7.
Citation Information
Patent Citations
Code generation method and device based on syntax tree, electronic equipment and storage medium
CN115016793A
Speech sensitive word recognition method and device, electronic equipment and storage medium
CN115512697A
Keyword matching method and device for cross-language environment and electronic equipment
CN115906817A
Special control flow jump program verification method based on semantic interpretation and legal stack constraint
CN116561005A
Multi-data source adaptation method and system suitable for low-code platform
CN117555920A
Cited By
Multi-level hybrid model flattening compiling method and system for X language
CN120560666A
Compilation processing method and device for computer modeling language information
CN120994171A