Hybrid precompilation method, device, electronic device and storage medium
By lexical analysis and keyword classification of precompiled program files, it is divided into interpreted and compiled program files, and corresponding precompiled program files are generated, the hybrid compilation of compiled and interpreted programs is achieved, solving the problem of low traditional precompilation efficiency and improving precompilation efficiency.
Patent Information
- Application Number
- CN202210662650.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-13
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2042-06-13
AI Technical Summary
In the precompilation process of traditional text languages, only a single compiled program or a single interpreted program can be precompiled, resulting in low precompilation efficiency of computer programs.
By obtaining the precompiled program files, performing lexical analysis and keyword classification, it is divided into interpreted program file contents and compiled program file contents, and generating interpreted and compiled precompiled program files respectively to realize mixed compilation of compiled programs and interpreted programs.
The program precompilation for interpreted compilers and compiled compilers is performed simultaneously during a precompilation process, which improves the efficiency of precompilation of computer programs and overcomes the problem of inefficiency in traditional methods.
Smart Images

Figure CN114968260B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a hybrid pre-compilation method, device, electronic device and storage medium. Background Art
[0002] With the continuous development of computer technology, the application of computer technology is becoming more and more extensive. When developing computer programs, it is usually necessary to use a compiled compiler or an interpreted compiler to compile a text language, and the text language needs to be precompiled before compiling the text language. However, in the traditional text language precompilation process, usually only a single compiled program or a single interpreted program can be precompiled, which affects the efficiency of computer program precompilation. Summary of the invention
[0003] The main purpose of the present application is to provide a hybrid precompilation method, device, electronic device and storage medium, aiming to solve the technical problem of low efficiency of computer program precompilation.
[0004] To achieve the above object, the present application provides a hybrid pre-compilation method, the hybrid pre-compilation method comprising:
[0005] Obtaining a program file to be precompiled, performing lexical analysis on the program file to be precompiled, and obtaining keywords of each program;
[0006] Classifying each of the program keywords to obtain keyword classification results;
[0007] According to the keyword classification result, the program file to be precompiled is divided into interpreted program file content and compiled program file content;
[0008] Based on the contents of the interpreted program file, an interpreted precompiled program file corresponding to the program file to be precompiled is generated, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; and based on the contents of the compiled program file, a compiled precompiled program file corresponding to the program file to be precompiled is generated, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation.
[0009] Optionally, the compiled program file content includes at least one compiled program instruction.
[0010] The step of generating a compiled precompiled program file corresponding to the program file to be precompiled according to the content of the compiled program file comprises:
[0011] Determining a first pre-compiled program instruction corresponding to the compiled program instruction according to a first preset program instruction mapping relationship;
[0012] The compiled precompiled program file is generated according to the first precompiled program instruction.
[0013] Optionally, the compiled program file content includes at least one compiled function,
[0014] The step of generating the compiled precompiled program file according to the first precompiled program instruction comprises:
[0015] Searching for a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
[0016] Expand the source program file to the function call corresponding to the compiled function to perform mixed pre-compilation to obtain a second pre-compiled program instruction;
[0017] The compiled precompiled program file is generated according to the first precompiled program instruction and the second precompiled program instruction.
[0018] Optionally, the content of the compiled program file includes at least one program variable.
[0019] The step of generating the compiled precompiled program file according to the first precompiled program instruction and the second precompiled program instruction comprises:
[0020] According to the variable type corresponding to the program variable, performing corresponding custom variable processing on the program variable to obtain a processed program variable;
[0021] The compiled precompiled program file is generated according to the first precompiled program instruction, the second precompiled program instruction and the processed program variable.
[0022] Optionally, the step of generating the compiled precompiled program file according to the first precompiled program instruction, the second precompiled program instruction and the processed program variable comprises:
[0023] According to the original semantics of the first precompiled program instruction, the second precompiled program instruction and the processed program variable in the program file to be precompiled, the first precompiled program instruction, the second precompiled program instruction and the processed program variable are integrated into a main program file;
[0024] Performing a semantic check on the main program file to obtain a semantic check result;
[0025] If the semantic check result is correct, the main program file is used as the compiled pre-compiled program file.
[0026] Optionally, the interpreted program file content includes at least one interpreted program instruction.
[0027] The step of generating an interpreted precompiled program file corresponding to the program file to be precompiled according to the content of the interpreted program file comprises:
[0028] Determine, according to the second preset program instruction mapping relationship, a third pre-compiled program instruction corresponding to the interpreted program instruction;
[0029] The interpreted precompiled program file is generated by expanding the third precompiled program instruction into an interpreted precompiled program generated by a main program of the program file to be precompiled.
[0030] Optionally, before the step of determining the contents of the interpreted program files and the compiled program files in the program files to be precompiled according to the keyword classification results, the hybrid precompilation method further includes:
[0031] Determining the comment content in the program file to be precompiled according to the keyword classification result;
[0032] Delete the comment content in the program file to be precompiled.
[0033] To achieve the above object, the present application also provides a hybrid pre-compilation device, the hybrid pre-compilation device comprising:
[0034] A lexical analysis module is used to obtain a program file to be precompiled, perform lexical analysis on the program file to be precompiled, and obtain each program keyword;
[0035] A classification module, used to classify each of the program keywords to obtain keyword classification results;
[0036] A content division module, used for dividing the program file to be precompiled into interpreted program file content and compiled program file content according to the keyword classification result;
[0037] a program file generating module, for generating, based on the contents of the interpreted program file, an interpreted precompiled program file corresponding to the program file to be precompiled, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; and a program file generating module, for generating, based on the contents of the compiled program file, a compiled precompiled program file corresponding to the program file to be precompiled, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation.
[0038] Optionally, the content of the compiled program file includes at least one compiled program instruction, and the program file generation module is further used to:
[0039] Determining a first pre-compiled program instruction corresponding to the compiled program instruction according to a first preset program instruction mapping relationship;
[0040] The compiled precompiled program file is generated according to the first precompiled program instruction.
[0041] Optionally, the compiled program file content includes at least one compiled function, and the program file generation module is further used to:
[0042] Searching for a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
[0043] Expand the source program file to the function call corresponding to the compiled function to perform mixed pre-compilation to obtain a second pre-compiled program instruction;
[0044] The compiled precompiled program file is generated according to the first precompiled program instruction and the second precompiled program instruction.
[0045] Optionally, the content of the compiled program file includes at least one program variable, and the program file generation module is further used to:
[0046] According to the variable type corresponding to the program variable, performing corresponding custom variable processing on the program variable to obtain a processed program variable;
[0047] The compiled precompiled program file is generated according to the first precompiled program instruction, the second precompiled program instruction and the processed program variable.
[0048] Optionally, the program file generation module is further used for:
[0049] According to the original semantics of the first precompiled program instruction, the second precompiled program instruction and the processed program variable in the program file to be precompiled, the first precompiled program instruction, the second precompiled program instruction and the processed program variable are integrated into a main program file;
[0050] Performing a semantic check on the main program file to obtain a semantic check result;
[0051] If the semantic check result is correct, the main program file is used as the compiled pre-compiled program file.
[0052] Optionally, the interpreted program file content includes at least one interpreted program instruction, and the program file generation module is further used to:
[0053] Determine, according to the second preset program instruction mapping relationship, a third pre-compiled program instruction corresponding to the interpreted program instruction;
[0054] The interpreted precompiled program file is generated by expanding the third precompiled program instruction into an interpreted precompiled program generated by a main program of the program file to be precompiled.
[0055] Optionally, the hybrid pre-compilation device is further used for:
[0056] Determining the comment content in the program file to be precompiled according to the keyword classification result;
[0057] Delete the comment content in the program file to be precompiled.
[0058] The present application also provides an electronic device, which is a physical device, and includes: a memory, a processor, and a program of the hybrid precompilation method stored in the memory and executable on the processor. When the program of the hybrid precompilation method is executed by the processor, the steps of the hybrid precompilation method as described above can be implemented.
[0059] The present application also provides a computer-readable storage medium, on which is stored a program for implementing the hybrid precompilation method. When the program of the hybrid precompilation method is executed by a processor, the steps of the hybrid precompilation method as described above are implemented.
[0060] The present application provides a hybrid precompilation method, device, electronic device and storage medium, that is, first obtaining a program file to be precompiled, performing lexical analysis on the program file to be precompiled to obtain each program keyword, thereby classifying each program keyword to obtain a keyword classification result; according to the keyword classification result, determining the interpreted program file content and the compiled program file content in the program file to be precompiled, that is, determining which part of the program file to be precompiled belongs to the interpreted program and which part is input into the compiled program, thereby generating an interpreted precompiled program file corresponding to the program file to be precompiled according to the interpreted program file content, wherein the interpreted precompiled program file is used The precompiled program file is input into an interpretive compiler for compilation; and a compiled precompiled program file corresponding to the program file to be precompiled is generated according to the content of the compiled program file, wherein the compiled precompiled program file is used to be input into the compiled compiler for compilation, so that program precompilation for an interpretive compiler and program precompilation for a compiled compiler can be performed simultaneously in one precompilation process, that is, mixed compilation of compiled programs and interpreted programs is realized, overcoming the technical defect that in the traditional text language precompilation process, usually only a single compiled program or a single interpreted program can be precompiled, which affects the efficiency of computer program precompilation, thereby improving the efficiency of computer program precompilation. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0062] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0063] Figure 1 This is a flow chart of the first embodiment of the hybrid pre-compilation method of the present application;
[0064] Figure 2 This is a flow chart of the second embodiment of the hybrid pre-compilation method of the present application;
[0065] Figure 3 A schematic diagram of the process of hybrid pre-compilation in the hybrid pre-compilation method of the present application;
[0066] Figure 4 Schematic diagram of the device structure of the hardware operating environment involved in the hybrid pre-compilation method in the embodiment of the present application.
[0067] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0068] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work belong to the scope of protection of this application.
[0069] Embodiment 1
[0070] Reference Figure 1 The embodiment of the present application provides a hybrid pre-compilation method. In the first embodiment of the hybrid pre-compilation method of the present application, the hybrid pre-compilation method includes:
[0071] Step S10, obtaining a program file to be precompiled, performing lexical analysis on the program file to be precompiled, and obtaining keywords of each program;
[0072] Step S20, classifying each of the program keywords to obtain a keyword classification result;
[0073] Step S30, dividing the program file to be precompiled into interpreted program file content and compiled program file content according to the keyword classification result;
[0074] Step S40, generating an interpreted precompiled program file corresponding to the program file to be precompiled according to the content of the interpreted program file, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; and generating a compiled precompiled program file corresponding to the program file to be precompiled according to the content of the compiled program file, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation.
[0075] In this embodiment, it should be noted that when compiling a computer program, it is usually necessary to use a compiled compiler or an interpreted compiler to compile the text language, and before compiling the text language, it is usually necessary to pre-compile the text language. Currently, only a single compiled program or a single interpreted program can be pre-compiled. If both interpreted programs and compiled programs exist in the computer program, the pre-compilation efficiency of the computer program will be affected.
[0076] Among them, the content of the interpreted program file includes at least one interpreted program instruction, for example, the interpreted program instruction can be a program instruction such as MC_Power or MC_Stop; the content of the compiled program file includes at least one of a compiled program instruction, a compiled function and a program variable, such as a compiled program instruction such as IF, the compiled function can be a compiled function such as FC, and program variables such as BOOL variables.
[0077] As an example, step S10 to step S40 include: extracting a program file to be precompiled from a set of program files to be precompiled; extracting each program keyword in the program file to be precompiled by performing lexical analysis on the program file to be precompiled; classifying each program keyword according to the part of speech and context content corresponding to each program keyword to obtain a keyword classification result; deleting the comment content in the program file to be precompiled according to the keyword classification result, and determining the interpreted program file content and the compiled program file content in the program file to be precompiled after the comment content is deleted; The content of the compiled program file is precompiled, all program instructions in the content of the compiled program file are converted into corresponding compiled precompiled program instructions, and all the compiled precompiled program instructions are integrated into an interpreted precompiled program file, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; the content of the compiled program file is precompiled, all program instructions in the content of the compiled program file are converted into corresponding compiled precompiled program instructions, and all the compiled precompiled program instructions are integrated into a compiled precompiled program file, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation.
[0078] The content of the interpreted program file includes at least one interpreted program instruction, and the step of generating an interpreted precompiled program file corresponding to the program file to be precompiled according to the content of the interpreted program file includes:
[0079] Step S41, determining a third pre-compiled program instruction corresponding to the interpreted program instruction according to a second preset program instruction mapping relationship;
[0080] Step S42, generating the interpreted precompiled program file by expanding the third precompiled program instruction into an interpreted precompiled program generated by a main program of the program file to be precompiled.
[0081] In this embodiment, it should be noted that the second preset program instruction mapping relationship is a mapping relationship between interpreted program instructions and interpreted precompiled program instructions, wherein the interpreted precompiled program instructions are program instructions that have the same semantics as the corresponding interpreted program instructions after precompilation, and the precompilation process is to convert the interpreted program instructions into corresponding interpreted precompiled program instructions.
[0082] As an example, step S41 to step S42 include: according to the second preset program instruction mapping relationship, querying the interpreted precompiled program instructions corresponding to each interpreted program instruction as the third precompiled program instruction; according to the semantic order corresponding to the original semantics of the interpreted program instructions corresponding to each of the third precompiled program instructions, expanding each of the third precompiled program instructions into the interpreted precompiled program generated by the main program of the program file to be precompiled, so as to obtain the interpreted precompiled program file.
[0083] As an example, it should be noted that different operating systems usually have different pre-compilation requirements for various interpreted program instructions. For example, some operating systems may not need to pre-compile some specific interpreted program instructions, and these specific interpreted program instructions need to be deleted. However, some operating systems need to add some additional interpreted program instructions on the basis of the original interpreted program instructions for pre-compilation.
[0084] The step of searching for interpreted pre-compiled program instructions corresponding to each interpreted program instruction as a third pre-compiled program instruction according to the second preset program instruction mapping relationship comprises:
[0085] According to the type of the current operating system, the interpreted program instructions are added or deleted to obtain the added or deleted interpreted program instructions; according to the second preset program instruction mapping relationship, the interpreted pre-compiled program instructions corresponding to the added or deleted interpreted program instructions are queried as the third pre-compiled program instructions. This satisfies the pre-compilation requirements for interpreted program instructions in different operating systems.
[0086] Wherein, before the step of determining the contents of the interpreted program files and the compiled program files in the program files to be precompiled according to the keyword classification results, the hybrid precompilation method further includes:
[0087] Step A10, determining the comment content in the program file to be precompiled according to the keyword classification result;
[0088] Step A20, deleting the comment content in the program file to be precompiled.
[0089] As an example, step A10 to step A20 include: determining comment keywords in each program keyword according to the keyword classification result; determining the comment content in the program file to be precompiled according to the comment keywords; and deleting the comment content in the program file to be precompiled.
[0090] The embodiment of the present application provides a hybrid precompilation method, that is, first obtaining a program file to be precompiled, performing lexical analysis on the program file to be precompiled to obtain each program keyword, thereby classifying each program keyword to obtain a keyword classification result; according to the keyword classification result, determining the interpreted program file content and the compiled program file content in the program file to be precompiled, that is, determining which part of the program file to be precompiled belongs to the interpreted program and which part is input into the compiled program, thereby generating an interpreted precompiled program file corresponding to the program file to be precompiled according to the interpreted program file content, wherein the interpreted precompiled program file is used to input the interpreted program file. The method comprises the steps of: compiling the program file in a compiler; and generating a compiled precompiled program file corresponding to the program file to be precompiled according to the content of the compiled program file, wherein the compiled precompiled program file is used to be input into the compiled compiler for compilation, so that program precompilation for an interpretive compiler and program precompilation for a compiled compiler can be performed simultaneously in one precompilation process, that is, mixed compilation of compiled programs and interpreted programs is realized, and the technical defect that only a single compiled program or a single interpreted program can be precompiled in the traditional text language precompilation process, which affects the efficiency of computer program precompilation, is overcome, and the efficiency of computer program precompilation is improved.
[0091] Embodiment 2
[0092] Further, refer to Figure 2 In another embodiment of the present application, the same or similar contents as those in the above embodiment can be referred to the above description and will not be described in detail later. On this basis, the content of the compiled program file includes at least one compiled program instruction, and the step of generating a compiled precompiled program file corresponding to the program file to be precompiled according to the content of the compiled program file includes:
[0093] Step B10, determining a first pre-compiled program instruction corresponding to the compiled program instruction according to a first preset program instruction mapping relationship;
[0094] Step B20: generating the compiled precompiled program file according to the first precompiled program instruction.
[0095] In this embodiment, it should be noted that the first preset program instruction mapping relationship is a mapping relationship between compiled program instructions and compiled pre-compiled program instructions, wherein the compiled pre-compiled program instructions are program instructions that have the same semantics as the corresponding compiled program instructions after pre-compilation, and the pre-compilation process is to convert the compiled program instructions into corresponding compiled pre-compiled program instructions.
[0096] As an example, step B10 to step B20 include: according to a first preset program instruction mapping relationship, querying the compiled pre-compiled program instructions corresponding to each compiled program instruction as the first pre-compiled program instruction; according to the semantic order corresponding to the original semantics of the compiled program instructions corresponding to each of the first pre-compiled program instructions, expanding each of the first pre-compiled program instructions into the compiled pre-compiled program generated by the main program of the program file to be pre-compiled, to obtain the compiled pre-compiled program file.
[0097] The content of the compiled program file includes at least one compiled function, and the step of generating the compiled precompiled program file according to the first precompiled program instruction includes:
[0098] Step B21, searching for the source program file called by the compiled function in the program file set corresponding to the program file to be precompiled;
[0099] Step B22, expanding the source program file to the function call corresponding to the compiled function to perform mixed pre-compilation to obtain a second pre-compiled program instruction;
[0100] Step B23: Generate the compiled precompiled program file according to the first precompiled program instruction and the second precompiled program instruction.
[0101] In the present embodiment, it should be noted that, currently, during precompilation, since a single compiled program or a single interpreted program is precompiled, once the compiled program contains an interpreted program file, precompilation cannot continue. Therefore, in order to ensure that the precompilation can proceed normally, it is currently usually necessary for the user to declare in advance the inclusion relationship between all the program files to be precompiled in the program file set before precompilation. Then, after precompilation of each program file to be precompiled is completed separately, the results of each program file to be precompiled are integrated according to the declared inclusion relationship to obtain the final precompilation result. Therefore, the current precompilation method has a great impact on the efficiency of computer program precompilation due to the need to declare the inclusion relationship between each program file to be precompiled.
[0102] As an example, steps B21 to B23 include: searching for the source program file called by the compiled function in the program file set corresponding to the program file to be precompiled; expanding the source program file to the function call of the compiled function in the program file to be precompiled to obtain the expanded program file to be precompiled; performing mixed precompilation on the expanded program file to be precompiled to obtain a second precompiled program instruction; according to the semantic order of the original semantics of the compiled program instruction corresponding to the first precompiled program instruction and the semantic order of the original semantics of the compiled program instruction corresponding to the second precompiled program instruction, the first precompiled program instruction and the second precompiled program instruction are expanded to the compiled precompiled program generated by the main program of the program file to be precompiled to obtain the compiled precompiled program file. The specific implementation process of performing mixed precompilation on the expanded program file to be precompiled to obtain the second precompiled program instruction can refer to the specific implementation content in steps S10 to S40, which will not be repeated here. Therefore, the embodiment of the present application realizes automatic parsing of the inclusion relationship between different program files to be precompiled, and through mixed precompilation, the program files to be precompiled with the inclusion relationship are automatically integrated and compiled directly during the compilation process. Therefore, there is no need to declare the inclusion relationship between different program files to be precompiled before precompilation, thereby improving the efficiency of computer program precompilation.
[0103] As an example, the content of the compiled program file includes at least one compiled function, and step S40 includes:
[0104] Searching for the source program file called by the compiled function in the program file set corresponding to the program file to be precompiled; expanding the source program file to the function call corresponding to the compiled function for mixed precompilation to obtain precompiled program instructions; generating the compiled precompiled program file according to the precompiled program instructions. Wherein, when the content of the compiled program file includes at least one compiled function, the specific implementation process of step S40 can refer to the specific implementation content in steps B21 to B23, which will not be repeated here.
[0105] The content of the compiled program file includes at least one program variable, and the step of generating the compiled precompiled program file according to the first precompiled program instruction and the second precompiled program instruction includes:
[0106] Step C10, performing corresponding custom variable processing on the program variable according to the variable type corresponding to the program variable to obtain a processed program variable;
[0107] Step C20, generating the compiled precompiled program file according to the first precompiled program instruction, the second precompiled program instruction and the processed program variables.
[0108] In this embodiment, it should be noted that some variable processing can be customized when performing mixed pre-compilation, so that corresponding customized variable processing can be performed on the parsed program variables, wherein the customized variable processing can be variable type conversion, for example, the variable type can be converted from integer to long integer, etc.
[0109] As an example, step B10 to step B20 include: determining a corresponding custom variable processing method according to a variable type corresponding to the program variable; performing corresponding custom variable processing on the program variable according to the determined custom variable processing method to obtain a processed program variable; and integrating the first precompiled program instruction, the second precompiled program instruction and the processed program variable into a compiled precompiled program file according to the original semantic order of the to-be-precompiled program instructions corresponding to the first precompiled program instruction, the second precompiled program instruction and the processed program variable in the to-be-precompiled program file.
[0110] The step of generating the compiled precompiled program file according to the first precompiled program instruction, the second precompiled program instruction and the processed program variable comprises:
[0111] Step D10, integrating the first precompiled program instruction, the second precompiled program instruction and the processed program variable into a main program file according to the original semantics of the first precompiled program instruction, the second precompiled program instruction and the processed program variable in the program file to be precompiled;
[0112] Step D20, performing a semantic check on the main program file to obtain a semantic check result;
[0113] Step D30: If the semantic check result is correct, the main program file is used as the compiled pre-compiled program file.
[0114] As an example, step D10 to step D30 include: according to the original semantic order of the to-be-precompiled program instructions corresponding to the first precompiled program instruction, the second precompiled program instruction and the processed program variable in the to-be-precompiled program file, sequentially expanding the first precompiled program instruction, the second precompiled program instruction and the processed program variable into a compiled precompiled program generated by a main program of the to-be-precompiled program file to obtain a main program file; performing a semantic check on the main program file to obtain a semantic check result; if the semantic check result is correct, using the main program file as the compiled precompiled program file; if the semantic check result is incorrect, issuing an alarm. Among them, the semantic checking method at least includes one of compiled instruction syntax checking, function call format checking, assignment operation type matching checking, statement number checking in pairs, function loop call checking, structure loop inclusion checking and array subscript overlimit checking, wherein the compiled instruction syntax checking is used to check whether the main program file conforms to the preset text language syntax, such as whether it conforms to the C language syntax, etc.; the function call format checking is used to check whether the function call format is legal, such as whether there are extra commas in the function call program instructions, etc.; the assignment operation type matching checking is used to check whether the assigned variable is consistent with the corresponding specific assigned data type; the function loop call checking is used to check whether there is an infinite loop in the function loop call; the structure loop inclusion checking is used to check whether the structure loop is reasonable; the array subscript overlimit checking is used to check whether the number of values read in the array exceeds the number of subscript values.
[0115] Reference Figure 3 , Figure 3 The present invention is a flow chart of mixed precompilation in an embodiment of the present application, wherein the program file to be processed is the program file to be precompiled, the lexical analysis and parsing is the process of obtaining each program keyword through lexical analysis, and the parsing results are classified into the process of classifying each program keyword, the instructions include compiled program instructions and interpreted program instructions, the variables are the program variables, the functions are the functions of the compiled functions, the comments are the comment content that needs to be deleted in the program file to be precompiled, and the syntax analysis and parsing process is the process of integrating the first precompiled program instructions, the second precompiled program instructions and the processed program variables into the main program file according to the original semantics of the first precompiled program instructions, the second precompiled program instructions and the processed program variables in the program file to be precompiled.
[0116] The embodiment of the present application provides a method for hybrid precompilation, that is, according to the first preset program instruction mapping relationship, determine the first precompiled program instruction corresponding to the compiled program instruction; search the source program file called by the compiled function in the program file set corresponding to the program file to be precompiled; expand the source program file to the function call corresponding to the compiled function for hybrid precompilation to obtain the second precompiled program instruction; generate the compiled precompiled program file according to the first precompiled program instruction and the second precompiled program instruction. The inclusion relationship between different program files to be precompiled can be automatically parsed, and the program files to be precompiled with the inclusion relationship can be automatically integrated and compiled directly in the compilation process by hybrid precompilation, so there is no need to declare the inclusion relationship between different program files to be precompiled before precompilation. Compared with the technical means of precompilation of a single program file to be precompiled separately by predeclaring the inclusion relationship between different program files to be precompiled, there is no need to declare the inclusion relationship between different program files to be precompiled before precompilation, so the efficiency of computer program precompilation is improved.
[0117] Embodiment 3
[0118] The present application also provides a hybrid pre-compilation device, the hybrid pre-compilation device comprising:
[0119] A lexical analysis module is used to obtain a program file to be precompiled, perform lexical analysis on the program file to be precompiled, and obtain each program keyword;
[0120] A classification module, used to classify each of the program keywords to obtain keyword classification results;
[0121] A content division module, used for dividing the program file to be precompiled into interpreted program file content and compiled program file content according to the keyword classification result;
[0122] A program file generation module is used to generate an interpreted precompiled program file corresponding to the program file to be precompiled according to the content of the interpreted program file, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; and to generate a compiled precompiled program file corresponding to the program file to be precompiled according to the content of the compiled program file, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation.
[0123] Optionally, the content of the compiled program file includes at least one compiled program instruction, and the program file generation module is further used to:
[0124] Determining a first pre-compiled program instruction corresponding to the compiled program instruction according to a first preset program instruction mapping relationship;
[0125] The compiled precompiled program file is generated according to the first precompiled program instruction.
[0126] Optionally, the compiled program file content includes at least one compiled function, and the program file generation module is further used to:
[0127] Searching for a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
[0128] Expand the source program file to the function call corresponding to the compiled function to perform mixed pre-compilation to obtain a second pre-compiled program instruction;
[0129] The compiled precompiled program file is generated according to the first precompiled program instruction and the second precompiled program instruction.
[0130] Optionally, the content of the compiled program file includes at least one program variable, and the program file generation module is further used to:
[0131] According to the variable type corresponding to the program variable, performing corresponding custom variable processing on the program variable to obtain a processed program variable;
[0132] The compiled precompiled program file is generated according to the first precompiled program instruction, the second precompiled program instruction and the processed program variable.
[0133] Optionally, the program file generation module is further used for:
[0134] According to the original semantics of the first precompiled program instruction, the second precompiled program instruction and the processed program variable in the program file to be precompiled, the first precompiled program instruction, the second precompiled program instruction and the processed program variable are integrated into a main program file;
[0135] Performing a semantic check on the main program file to obtain a semantic check result;
[0136] If the semantic check result is correct, the main program file is used as the compiled pre-compiled program file.
[0137] Optionally, the interpreted program file content includes at least one interpreted program instruction, and the program file generation module is further used to:
[0138] Determine, according to the second preset program instruction mapping relationship, a third pre-compiled program instruction corresponding to the interpreted program instruction;
[0139] The interpreted precompiled program file is generated by expanding the third precompiled program instruction into an interpreted precompiled program generated by a main program of the program file to be precompiled.
[0140] Optionally, the hybrid pre-compilation device is further used for:
[0141] Determining the comment content in the program file to be precompiled according to the keyword classification result;
[0142] Delete the comment content in the program file to be precompiled.
[0143] The hybrid precompilation device provided by the present application adopts the hybrid precompilation method in the above embodiment to solve the technical problem of low precompilation efficiency of computer programs. Compared with the prior art, the beneficial effects of the hybrid precompilation device provided by the embodiment of the present application are the same as the beneficial effects of the hybrid precompilation method provided by the above embodiment, and other technical features in the hybrid precompilation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0144] Embodiment 4
[0145] An embodiment of the present application provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the hybrid precompilation method in the above-mentioned embodiment 1.
[0146] Reference below Figure 4 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0147] like Figure 4 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage device into a random access memory (RAM). In the RAM, various programs and data required for the operation of the electronic device are also stored. The processing device, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0148] Typically, the following systems can be connected to the I / O interface: input devices including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices including, for example, a magnetic tape, a hard disk, etc.; and communication devices. The communication device can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.
[0149] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0150] The electronic device provided by the present application adopts the hybrid precompilation method in the above embodiment to solve the technical problem of low efficiency of computer program precompilation. Compared with the prior art, the beneficial effects of the electronic device provided by the embodiment of the present application are the same as the beneficial effects of the hybrid precompilation method provided by the above embodiment 1, and other technical features in the electronic device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0151] It should be understood that the various parts of the present disclosure can be implemented with hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0152] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0153] Embodiment 5
[0154] This embodiment provides a computer-readable storage medium having computer-readable program instructions stored thereon, and the computer-readable program instructions are used to execute the hybrid pre-compilation method in the above-mentioned embodiment 1.
[0155] The computer-readable storage medium provided in the embodiment of the present application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, a system or a device or used in combination with it. The program code contained on the computer-readable storage medium can be transmitted with any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0156] The computer-readable storage medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0157] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by an electronic device, the electronic device: obtains a program file to be precompiled, performs lexical analysis on the program file to be precompiled, and obtains each program keyword; classifies each program keyword to obtain a keyword classification result; divides the program file to be precompiled into an interpreted program file content and a compiled program file content according to the keyword classification result; generates an interpreted precompiled program file corresponding to the program file to be precompiled according to the interpreted program file content, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; generates a compiled precompiled program file corresponding to the program file to be precompiled according to the compiled program file content, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation.
[0158] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0159] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0160] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of the module does not limit the unit itself in some cases.
[0161] The computer-readable storage medium provided by the present application stores computer-readable program instructions for executing the above-mentioned hybrid precompilation method, which solves the technical problem of low efficiency of computer program precompilation. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the embodiment of the present application are the same as the beneficial effects of the hybrid precompilation method provided in the above-mentioned embodiment, and will not be repeated here.
[0162] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent processing scope of the present application.
Claims
1. A hybrid pre-compilation method, characterized in that: The hybrid pre-compilation method comprises: Obtaining a program file to be precompiled, performing lexical analysis on the program file to be precompiled, and obtaining keywords of each program; Classifying each of the program keywords to obtain keyword classification results; According to the keyword classification result, the program file to be precompiled is divided into interpreted program file content and compiled program file content; generating, according to the contents of the interpreted program file, an interpreted precompiled program file corresponding to the program file to be precompiled, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; and generating, according to the contents of the compiled program file, a compiled precompiled program file corresponding to the program file to be precompiled, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation; The content of the compiled program file includes at least one compiled program instruction, and the step of generating a compiled precompiled program file corresponding to the program file to be precompiled according to the content of the compiled program file includes: Determining a first pre-compiled program instruction corresponding to the compiled program instruction according to a first preset program instruction mapping relationship; The compiled precompiled program file is generated according to the first precompiled program instruction.
2. The hybrid pre-compilation method according to claim 1, characterized in that: The compiled program file content includes at least one compiled function, The step of generating the compiled precompiled program file according to the first precompiled program instruction comprises: Searching for a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled; Expand the source program file to the function call corresponding to the compiled function to perform mixed pre-compilation to obtain a second pre-compiled program instruction; The compiled precompiled program file is generated according to the first precompiled program instruction and the second precompiled program instruction.
3. The hybrid pre-compilation method according to claim 2, characterized in that: The content of the compiled program file includes at least one program variable. The step of generating the compiled precompiled program file according to the first precompiled program instruction and the second precompiled program instruction comprises: According to the variable type corresponding to the program variable, performing corresponding custom variable processing on the program variable to obtain a processed program variable; The compiled precompiled program file is generated according to the first precompiled program instruction, the second precompiled program instruction and the processed program variable.
4. The hybrid pre-compilation method according to claim 3, characterized in that: The step of generating the compiled precompiled program file according to the first precompiled program instruction, the second precompiled program instruction and the processed program variable comprises: According to the original semantics of the first precompiled program instruction, the second precompiled program instruction and the processed program variable in the program file to be precompiled, the first precompiled program instruction, the second precompiled program instruction and the processed program variable are integrated into a main program file; The main program file is used as the compiled precompiled program file.
5. The hybrid pre-compilation method according to claim 1, characterized in that: The interpreted program file content includes at least one interpreted program instruction. The step of generating an interpreted precompiled program file corresponding to the program file to be precompiled according to the content of the interpreted program file comprises: Determine, according to the second preset program instruction mapping relationship, a third pre-compiled program instruction corresponding to the interpreted program instruction; The interpreted precompiled program file is generated by expanding the third precompiled program instruction into an interpreted precompiled program generated by a main program of the program file to be precompiled.
6. The hybrid pre-compilation method according to claim 1, characterized in that: Before the step of determining the contents of the interpreted program files and the compiled program files in the program files to be precompiled according to the keyword classification results, the hybrid precompilation method further includes: Determining the comment content in the program file to be precompiled according to the keyword classification result; Delete the comment content in the program file to be precompiled.
7. A hybrid pre-compilation device, characterized in that: The hybrid pre-compilation device comprises: A lexical analysis module is used to obtain a program file to be precompiled, perform lexical analysis on the program file to be precompiled, and obtain each program keyword; A classification module, used to classify each of the program keywords to obtain keyword classification results; A content division module, used for dividing the program file to be precompiled into interpreted program file content and compiled program file content according to the keyword classification result; a program file generating module, configured to generate an interpreted precompiled program file corresponding to the program file to be precompiled according to the contents of the interpreted program file, wherein the interpreted precompiled program file is used to be input into an interpreted compiler for compilation; and to generate a compiled precompiled program file corresponding to the program file to be precompiled according to the contents of the compiled program file, wherein the compiled precompiled program file is used to be input into a compiled compiler for compilation; The compiled program file content includes at least one compiled program instruction, and the program file generation module is further used to: determine a first pre-compiled program instruction corresponding to the compiled program instruction according to a first preset program instruction mapping relationship; and generate the compiled pre-compiled program file according to the first pre-compiled program instruction.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the steps of the hybrid pre-compilation method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program for implementing the hybrid pre-compilation method, and the program for implementing the hybrid pre-compilation method is executed by a processor to implement the steps of the hybrid pre-compilation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Hybrid compiling method of programmable logic controller, storage medium and program product
CN113485228A