CN114968260A - Hybrid pre-compiling method and device, electronic equipment and storage medium - Google Patents

Hybrid pre-compiling method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114968260A
CN114968260A CN202210662650.7A CN202210662650A CN114968260A CN 114968260 A CN114968260 A CN 114968260A CN 202210662650 A CN202210662650 A CN 202210662650A CN 114968260 A CN114968260 A CN 114968260A
Authority
CN
China
Prior art keywords
program
compiled
program file
file
compiler
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210662650.7A
Other languages
Chinese (zh)
Inventor
林奕健
戴正国
朱海波
田宾
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Inovance Technology Co Ltd
Original Assignee
Shenzhen Inovance Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Inovance Technology Co Ltd filed Critical Shenzhen Inovance Technology Co Ltd
Priority to CN202210662650.7A priority Critical patent/CN114968260A/en
Publication of CN114968260A publication Critical patent/CN114968260A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application discloses a hybrid precompilation method, a device, an electronic device and a storage medium, wherein the hybrid precompilation method comprises the following steps: acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords; classifying program keywords to obtain a keyword classification result; dividing the program file to be pre-compiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result; generating an interpreted pre-compiling program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, wherein the interpreted pre-compiling program file is used for being input into an interpreted compiler to be compiled; and generating a complied pre-complied program file corresponding to the program file to be pre-complied according to the content of the complied program file, wherein the complied pre-complied program file is used for being input into a complied compiler for compiling. The method and the device solve the technical problem of low precompilation efficiency of the computer program.

Description

Hybrid pre-compiling method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a hybrid precompilation method and apparatus, an electronic device, and a storage medium.
Background
With the continuous development of computer technology, the application of computer technology is more and more extensive, when computer programs are developed, a text language is usually compiled by using a compiler or an interpreter compiler, and the text language is precompiled before the text language is compiled. However, in the conventional pre-compiling process of the text language, usually only a single compiler program or a single interpreter program can be pre-compiled, which affects the efficiency of the pre-compiling of the computer program.
Disclosure of Invention
The present application mainly aims to provide a hybrid precompilation method, apparatus, electronic device and storage medium, and aims to solve the technical problem of low precompilation efficiency of a computer program.
To achieve the above object, the present application provides a hybrid precompilation method, including:
acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords;
classifying each program keyword to obtain a keyword classification result;
dividing the program file to be pre-compiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result;
generating an interpreted pre-compiling program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, wherein the interpreted pre-compiling program file is used for being input into an interpreted compiler for compiling; and generating a compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file, wherein the compiled pre-compiled program file is used for being input into a compiled compiler for compiling.
Optionally, the content of the compiler file comprises at least one compiler instruction,
the step of generating the compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file comprises the following steps:
determining a first pre-compiling program instruction corresponding to the compiling program instruction according to a first preset program instruction mapping relation;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction.
Optionally, the contents of the compiler file include at least one compiler function,
the step of generating the compiled pre-compiler file according to the first pre-compiler instruction includes:
searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
expanding the source program file to a function calling position corresponding to the compiling function to perform mixed pre-compiling to obtain a second pre-compiling program instruction;
and generating the compiled pre-compiled program file according to the first pre-compiled program instruction and the second pre-compiled program instruction.
Optionally, the contents of the compiled program file include at least one program variable,
the step of generating the compiled pre-compiler file according to the first pre-compiler instruction and the second pre-compiler instruction includes:
according to the variable type corresponding to the program variable, carrying out corresponding custom variable processing on the program variable to obtain a processed program variable;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable.
Optionally, the step of generating the compiled pre-compiled program file according to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable includes:
integrating the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable into a main program file according to the original semantics of the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable in the program file to be pre-compiled;
performing semantic check on the main program file to obtain a semantic check result;
and if the semantic checking result is correct, taking the main program file as the compiled pre-compiled program file.
Optionally, the content of the interpreted program file includes at least one interpreted program instruction,
the step of generating the interpreted pre-compiler program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file comprises the following steps:
determining a third pre-compiling program instruction corresponding to the interpretation type program instruction according to a second preset program instruction mapping relation;
and generating the interpreted pre-compiler program file by expanding the third pre-compiler program instruction into an interpreted pre-compiler program generated by the main program of the program file to be pre-compiled.
Optionally, before the step of determining the content of the interpreted program file and the content of the compiled program file in the program file to be precompiled according to the keyword classification result, the hybrid precompilation method further includes:
according to the keyword classification result, determining annotation content in the program file to be precompiled;
and deleting the annotation content in the program file to be precompiled.
To achieve the above object, the present application also provides a hybrid precompilation apparatus, including:
the lexical analysis module is used for acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords;
the classification module is used for classifying the program keywords to obtain a keyword classification result;
the content dividing module is used for dividing the program file to be precompiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result;
a program file generation module, configured to generate an interpreted pre-compilation program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, where the interpreted pre-compilation program file is used for being input into an interpreted compiler for compilation; and the program file generation module is used for generating a compiled type pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled type program file, wherein the compiled type pre-compiled program file is used for being input into a compiled type compiler for compiling.
Optionally, the content of the compiled program file at least includes a compiled program instruction, and the program file generating module is further configured to:
determining a first pre-compiling program instruction corresponding to the compiling type program instruction according to a first preset program instruction mapping relation;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction.
Optionally, the content of the compiled program file at least includes a compiled function, and the program file generating module is further configured to:
searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
expanding the source program file to a function calling position corresponding to the compiling function to perform mixed pre-compiling to obtain a second pre-compiling program instruction;
and generating the compiled pre-compiled program file according to the first pre-compiled program instruction and the second pre-compiled program instruction.
Optionally, the content of the compiled program file at least includes a program variable, and the program file generating module is further configured to:
according to the variable type corresponding to the program variable, carrying out corresponding custom variable processing on the program variable to obtain a processed program variable;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable.
Optionally, the program file generating module is further configured to:
integrating the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable into a main program file according to the original semantics of the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable in the program file to be pre-compiled;
performing semantic check on the main program file to obtain a semantic check result;
and if the semantic checking result is correct, taking the main program file as the compiled pre-compiled program file.
Optionally, the content of the interpreted program file at least includes an interpreted program instruction, and the program file generating module is further configured to:
determining a third pre-compiling program instruction corresponding to the interpretation type program instruction according to a second preset program instruction mapping relation;
and generating the interpreted pre-compiler program file by expanding the third pre-compiler program instruction into an interpreted pre-compiler program generated by the main program of the program file to be pre-compiled.
Optionally, the hybrid pre-compiling apparatus is further configured to:
according to the keyword classification result, determining annotation content in the program file to be precompiled;
and deleting the annotation content in the program file to be precompiled.
The present application further provides an electronic device, the electronic device is an entity device, the electronic device includes: a memory, a processor and a program of the hybrid precompilation method stored on the memory and executable on the processor, which when executed by the processor, may implement the steps of the hybrid precompilation method as described above.
The present application also provides a computer-readable storage medium having stored thereon a program for implementing a hybrid precompilation method, which when executed by a processor implements the steps of the hybrid precompilation method as described above.
The application provides a hybrid pre-compiling method, a device, electronic equipment and a storage medium, namely, a program file to be pre-compiled is obtained at first, lexical analysis is carried out on the program file to be pre-compiled to obtain program keywords, and therefore the program keywords are classified to obtain a keyword classification result; determining the content of an interpreted program file and the content of a compiled program file in the program file to be precompiled according to the keyword classification result, namely determining which part of the program file to be precompiled belongs to an interpreted program and which part inputs the compiled program, and generating the 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 for being input into an interpreted compiler for compiling; according to the content of the compiler type program file, a compiler type pre-compiler program file corresponding to the program file to be pre-compiled is generated, wherein the compiler type pre-compiler program file is used for inputting into a compiler type compiler for compiling, so that the program pre-compilation for the interpreter type compiler and the program pre-compilation for the compiler type compiler can be simultaneously carried out in one pre-compilation process, namely the hybrid compilation of the compiler type program and the interpreter type program is realized, the technical defect that the efficiency of the pre-compilation of the computer program is influenced because only a single compiler type program or a single interpreter type program can be pre-compiled in the pre-compilation process of the traditional text language is overcome, and the efficiency of the pre-compilation of the computer program is improved.
Drawings
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 application.
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly described below, and it is obvious for those skilled in the art to obtain other drawings without inventive exercise.
FIG. 1 is a flowchart illustrating a hybrid precompilation method according to a first embodiment of the present application;
FIG. 2 is a flowchart illustrating a hybrid precompilation method according to a second embodiment of the present application;
FIG. 3 is a schematic flow chart illustrating hybrid precompilation performed in the hybrid precompilation method of the present application;
fig. 4 is a schematic device structure diagram of a hardware operating environment related to a hybrid pre-compilation method in the embodiment of the present application.
The objectives, features, and advantages of the present application will be further described with reference to the accompanying drawings.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, embodiments of the present application are described in detail below with reference to the accompanying drawings. It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Example one
Referring to fig. 1, an embodiment of the present application provides a hybrid precompilation method, and in a first embodiment of the hybrid precompilation method, the hybrid precompilation method includes:
step S10, acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords;
step S20, classifying each program keyword to obtain a keyword classification result;
step S30, dividing the program file to be pre-compiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result;
step S40, generating an interpreted pre-compiling program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, wherein the interpreted pre-compiling program file is used for inputting into an interpreted compiler for compiling; and generating a compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file, wherein the compiled pre-compiled program file is used for being input into a compiled compiler for compiling.
In this embodiment, it should be noted that, when compiling a computer program, usually a text language compiling is required by using a compiler or an interpreter, and before the text language compiling, usually a text language precompiling is required, but only a single compiler or a single interpreter can be precompiled currently, and if the interpreter and the interpreter exist in the computer program at the same time, the precompiling efficiency of the computer program is affected.
The content of the interpreted program file at least includes an interpreted program instruction, for example, the interpreted program instruction may be a program instruction such as MC _ Power or MC _ Stop; the compiled program file content includes at least one of a compiled program instruction, a compiled function, and a program variable, such as a compiled program instruction of I F, and the compiled function may be a compiled function of FC, such as a program variable of BOOL.
As one example, steps S10 to S40 include: extracting a program file to be precompiled from a program file set to be precompiled; extracting each program key word in the program file to be precompiled by performing lexical analysis on the program file to be precompiled; classifying the program keywords according to the parts of speech and the context corresponding to the program keywords to obtain a keyword classification result; according to the keyword classification result, deleting the annotation content in the program file to be precompiled, and determining the content of an interpretation type program file and the content of a compilation type program file in the program file to be precompiled after the annotation content is deleted; pre-compiling the content of the interpreted program file, converting all program instructions in the content of the interpreted program file into corresponding interpreted pre-compiled program instructions, and integrating all the interpreted pre-compiled program instructions into an interpreted pre-compiled program file, wherein the interpreted pre-compiled program file is used for being input into an interpreted compiler for compiling; and pre-compiling the content of the compiled program file, converting all program instructions in the content of the compiled program file into corresponding compiled pre-compiled program instructions, and integrating all the compiled pre-compiled program instructions into a compiled pre-compiled program file, wherein the compiled pre-compiled program file is used for being input into a compiled compiler for compiling.
The step of generating the interpreted pre-compiled program file corresponding to the program file to be pre-compiled according to the interpreted program file content comprises:
step S41, determining a third pre-compiled program instruction corresponding to the interpretation type program instruction according to a second preset program instruction mapping relation;
step S42, generating the interpreted precompiled program file by expanding the third precompiled program instruction into the interpreted precompiled program generated by the main program of the to-be-precompiled program file.
In this embodiment, it should be noted that the second predetermined program instruction mapping relationship is a mapping relationship between an interpreter program instruction and an interpreter precompiled program instruction, where the interpreter precompiled program instruction is a program instruction that has the same semantics as a corresponding interpreter program instruction after being precompiled, and the precompiling process is to convert the interpreter program instruction into a corresponding interpreter precompiled program instruction.
As one example, steps S41 to S42 include: inquiring the interpreted pre-compiling program instruction corresponding to each interpreted program instruction as a third pre-compiling program instruction according to the second preset program instruction mapping relation; and according to the semantic sequence corresponding to the original semantic of the interpreted program instruction corresponding to each third pre-compiled program instruction, unfolding each third pre-compiled program instruction into the interpreted pre-compiled program generated by the main program of the program file to be pre-compiled to obtain the interpreted pre-compiled program file.
As an example, it should be noted that different operating systems usually have different precompilation requirements for each interpreter instruction, for example, some operating systems may not need to precompile some specific interpreter instructions, and at this time, these specific interpreter instructions need to be deleted, while some operating systems need to add some additional interpreter instructions on the basis of the original interpreter instructions for precompilation together.
The step of querying the interpreted precompiled program instruction corresponding to each interpreted program instruction as a third precompiled program instruction according to the second preset program instruction mapping relationship includes:
according to the type of the current operating system and the type of the current operating system, adding and deleting the interpretation type program instructions to obtain the added and deleted interpretation type program instructions; and inquiring the interpreted pre-compiling program instruction corresponding to each added and deleted interpreted program instruction as a third pre-compiling program instruction according to the second preset program instruction mapping relation. To meet the pre-compilation requirements for interpreted program instructions in different operating systems.
Before the step of determining the content of the interpreted program file and the content of the compiled program file in the program file to be precompiled according to the keyword classification result, the hybrid precompilation method further includes:
step A10, determining annotation content in the program file to be precompiled according to the keyword classification result;
and step A20, deleting the annotation content in the program file to be precompiled.
As an example, the steps a10 to a20 include: determining annotation keywords in the program keywords according to the keyword classification result; determining annotation content in the program file to be precompiled according to the annotation key; and deleting the annotation content in the program file to be precompiled.
The embodiment of the application provides a hybrid pre-compiling method, namely, firstly, a program file to be pre-compiled is obtained, lexical analysis is carried out on the program file to be pre-compiled to obtain program keywords, and therefore the program keywords are classified to obtain a keyword classification result; determining the content of an interpreted program file and the content of a compiled program file in the program file to be precompiled according to the keyword classification result, namely determining which part of the program file to be precompiled belongs to an interpreted program and which part inputs the compiled program, and generating the 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 for being input into an interpreted compiler for compiling; according to the content of the complied program file, generating a complied pre-compiled program file corresponding to the program file to be pre-compiled, wherein the complied pre-compiled program file is used for being input into a complied compiler for compiling, so that the program pre-compiling for an interpreted compiler and the program pre-compiling for the complied compiler can be simultaneously carried out in one pre-compiling process, namely the hybrid compiling of the complied program and the interpreted program is realized, the technical defect that the efficiency of the pre-compiling of the computer program is influenced because only a single complied program or a single interpreted program can be pre-compiled in the traditional pre-compiling process of a text language is overcome, and the efficiency of the pre-compiling of the computer program is improved.
Example two
Further, referring to fig. 2, in another embodiment of the present application, the same or similar contents as those in the above embodiment may refer to the above description, and are not repeated herein. On this basis, the content of the complied program file at least comprises a complied program instruction, and the step of generating the complied pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the complied program file comprises the following steps:
step B10, determining a first pre-compiled program instruction corresponding to the compiled program instruction according to a first preset program instruction mapping relation;
and step B20, generating the compiled type pre-compiled program file according to the first pre-compiled program instruction.
In this embodiment, it should be noted that the first predetermined program instruction mapping relationship is a mapping relationship between a compiler type program instruction and a compiler type pre-compiler program instruction, where the compiler type pre-compiler program instruction is a program instruction that has the same semantic as a corresponding compiler type program instruction after being pre-compiled, and the pre-compiling process is to convert the compiler type program instruction into the corresponding compiler type pre-compiler program instruction.
As an example, the steps B10 to B20 include: inquiring a compiled pre-compiled program instruction corresponding to each compiled program instruction as a first pre-compiled program instruction according to the first preset program instruction mapping relation; and according to the semantic sequence corresponding to the original semantic of the compiler program instruction corresponding to each first pre-compiler program instruction, unfolding each first pre-compiler program instruction into a compiler pre-compiler program generated by the main program of the program file to be pre-compiled to obtain the compiler pre-compiler program file.
Wherein the content of the compiled program file at least comprises a compiled function, and the step of generating the compiled pre-compiled program file according to the first pre-compiled program instruction comprises:
step B21, searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
step B22, expanding the source program file to a function calling position corresponding to the compiled function for mixed pre-compiling to obtain a second pre-compiling program instruction;
and step B23, generating the compiled type pre-compiled program file according to the first pre-compiled program instruction and the second pre-compiled program instruction.
In this embodiment, it should be noted that, in the present invention, when performing pre-compilation, since a single compiler-type program or a single interpreter-type program is pre-compiled, therefore, once the compiler type function has interpreted program files, the precompilation can not be continued, so that the precompilation can be normally carried out, at present, before the precompilation is usually carried out, a user needs to declare the inclusion relationship among all the program files to be precompiled in a program file set in advance, then after each program file to be precompiled is respectively completed, according to the declared inclusion relation, integrating the result of each program file to be precompiled to obtain the final precompiled result, therefore, the existing precompilation method needs to declare the inclusion relationship among the program files to be precompiled, and greatly influences the precompilation efficiency of the computer program.
As an example, the steps B21 to B23 include: searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled; expanding the source program file to a function calling position of the compiling function on the program file to be precompiled to obtain an expanded program file to be precompiled; performing mixed pre-compiling on the expanded program file to be pre-compiled to obtain a second pre-compiled program instruction; according to the semantic sequence of the original semantics of the compiler type program instructions corresponding to the first pre-compiler program instructions and the semantic sequence of the original semantics of the compiler type program instructions corresponding to the second pre-compiler program instructions, expanding the first pre-compiler program instructions and the second pre-compiler program instructions into a compiler type pre-compiler program generated by a main program of the program file to be pre-compiled, and obtaining the compiler type pre-compiler program file. The specific implementation process of performing hybrid pre-compilation on the expanded program file to be pre-compiled to obtain the second pre-compiled program instruction may refer to the specific implementation contents in steps S10 to S40, which are not described herein again. Therefore, the embodiment of the application realizes automatic analysis of the inclusion relationship between different program files to be precompiled, and directly and automatically integrates and compiles the program files to be precompiled with the inclusion relationship in the compiling process in a mixed precompilation mode, so that the inclusion relationship between the different program files to be precompiled is not required to be declared in advance before precompilation, and the precompilation efficiency of the computer program is improved.
As an example, the contents of the compiler file at least include a compiler function, and step S40 includes:
searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled; expanding the source program file to a function calling position corresponding to the compiled function for mixed pre-compiling to obtain a pre-compiled program instruction; and generating the compiled type pre-compiled program file according to the pre-compiled program instruction. When the contents of the complied program file at least include a complied function, the specific implementation process of step S40 can refer to the specific implementation contents of steps B21 to B23, which are not described herein again.
Wherein the content of the compiled program file at least includes a program variable, and the step of generating the compiled pre-compiled program file according to the first pre-compiled program instruction and the second pre-compiled program instruction includes:
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;
and step C20, generating the compiled type pre-compiled program file according to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable.
In this embodiment, it should be noted that some variable processes may be customized during hybrid precompilation, so that corresponding customized variable processes may be performed on program variables obtained through analysis, where the customized variable processes may be variable type conversion, for example, the variable types may be converted from integer to long integer.
As an example, the steps B10 to B20 include: determining a corresponding user-defined variable processing mode according to the variable type corresponding to the program variable; according to the determined custom variable processing mode, carrying out corresponding custom variable processing on the program variable to obtain a processed program variable; and integrating the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable into a compiled pre-compiled program file according to the original semantic sequence of the program instruction to be pre-compiled in the program file to be pre-compiled, which corresponds to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable respectively.
Wherein the step of generating the compiled pre-compiled program file according to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable includes:
step D10, integrating the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable into a main program file according to the original semantics of the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable in the program file to be pre-compiled;
step D20, carrying out semantic check on the main program file to obtain a semantic check result;
and D30, if the semantic checking result is correct, using the main program file as the compiled pre-compiled program file.
As an example, the steps D10 to D30 include: sequentially unfolding the first pre-compiling program instruction, the second pre-compiling program instruction and the processed program variable into a compiling type pre-compiling program generated by a main program of the program file to be pre-compiled according to the original semantic sequence of the program instruction to be pre-compiled in the program file to be pre-compiled, which respectively corresponds to the first pre-compiling program instruction, the second pre-compiling program instruction and the processed program variable, so as to obtain a main program file; performing semantic check on the main program file to obtain a semantic check result; if the semantic checking result is correct, taking the main program file as the compiled pre-compiled program file; and if the semantic inspection result is wrong, alarming. The semantic checking mode at least comprises one of compiled instruction syntax checking, function call format checking, type matching checking of assignment operation, paired statement quantity checking, function loop call checking, structural body loop inclusion checking and array subscript overrun checking, wherein the compiled instruction syntax checking is used for checking whether a main program file conforms to preset text language syntax, for example, whether the main program file conforms to C language syntax and the like; the function call format check is used for checking whether the function call format is legal, such as whether redundant commas exist in a function call program instruction; the type matching check of the assignment operation is used for checking whether the assigned variables are consistent with the data types of the corresponding specific assignments or not; the function loop call check is used for checking whether function loop calls have dead loops; the structure circulation comprises checking whether the structure circulation is reasonable; the array index overrun check is used to check whether the number of values in the read array exceeds the index number of values.
Referring to fig. 3, fig. 3 is a schematic flow chart illustrating hybrid precompilation performed in the embodiment of the present application, wherein, the method comprises the steps that a program file to be processed is the program file to be precompiled, lexical analysis and analysis are carried out to obtain the process of each program keyword, the analysis result is classified into the process of classifying each program keyword, the instructions comprise a compiling program instruction and an explaining program instruction, the variables are program variables, the functions are functions of the compiling functions and are annotated as annotation contents needing to be deleted in the program file to be precompiled, and the process of syntactic analysis and analysis is a process of integrating the first precompiling program instruction, the second precompiling program instruction and the processed program variables into a main program file according to the original semantics of the first precompiling program instruction, the second precompiling program instruction and the processed program variables in the program file to be precompiled.
The embodiment of the application provides a hybrid pre-compiling method, namely determining a first pre-compiling program instruction corresponding to a compiling program instruction according to a first preset program instruction mapping relation; searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled; expanding the source program file to a function calling position corresponding to the compiled function for mixed pre-compiling to obtain a second pre-compiling program instruction; and generating the compiled pre-compiled program file according to the first pre-compiled program instruction and the second pre-compiled program instruction. The method can automatically analyze the inclusion relationship between different program files to be precompiled, and directly and automatically integrate and compile the program files to be precompiled with the inclusion relationship in the compiling process in a mixed precompilation mode, so that the inclusion relationship between the different program files to be precompiled is not required to be declared in advance before precompilation.
EXAMPLE III
The present application further provides a hybrid pre-compilation apparatus, which includes:
the lexical analysis module is used for acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords;
the classification module is used for classifying the program keywords to obtain a keyword classification result;
the content dividing module is used for dividing the program file to be pre-compiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result;
a program file generation module, configured to generate an interpreted pre-compilation program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, where the interpreted pre-compilation program file is used for being input into an interpreted compiler for compilation; and generating a compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file, wherein the compiled pre-compiled program file is used for being input into a compiled compiler for compiling.
Optionally, the content of the compiled program file at least includes a compiled program instruction, and the program file generating module is further configured to:
determining a first pre-compiling program instruction corresponding to the compiling program instruction according to a first preset program instruction mapping relation;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction.
Optionally, the content of the compiled program file at least includes a compiled function, and the program file generating module is further configured to:
searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
expanding the source program file to a function calling position corresponding to the compiled function for mixed pre-compiling to obtain a second pre-compiling program instruction;
and generating the compiled pre-compiled program file according to the first pre-compiled program instruction and the second pre-compiled program instruction.
Optionally, the content of the compiled program file at least includes a program variable, and the program file generating module is further configured to:
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;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable.
Optionally, the program file generating module is further configured to:
integrating the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable into a main program file according to the original semantics of the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable in the program file to be pre-compiled;
performing semantic check on the main program file to obtain a semantic check result;
and if the semantic checking result is correct, taking the main program file as the compiled pre-compiled program file.
Optionally, the content of the interpreted program file at least includes an interpreted program instruction, and the program file generating module is further configured to:
determining a third pre-compiling program instruction corresponding to the interpretation type program instruction according to a second preset program instruction mapping relation;
and generating the interpreted pre-compiler program file by expanding the third pre-compiler program instruction into an interpreted pre-compiler program generated by the main program of the program file to be pre-compiled.
Optionally, the hybrid pre-compiling apparatus is further configured to:
according to the keyword classification result, determining annotation content in the program file to be precompiled;
and deleting the annotation content in the program file to be precompiled.
The hybrid pre-compiling device provided by the application adopts the hybrid pre-compiling method in the embodiment, so that the technical problem of low pre-compiling efficiency of a computer program is solved. Compared with the prior art, the beneficial effects of the hybrid pre-compiling apparatus provided by the embodiment of the present application are the same as the beneficial effects of the hybrid pre-compiling method provided by the above embodiment, and other technical features of the hybrid pre-compiling apparatus are the same as those disclosed by the above embodiment method, which are not described herein again.
Example four
An embodiment of the present application provides an electronic device, and the electronic device includes: at least one processor; and a memory communicatively coupled to the at least one processor; the memory stores instructions executable 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 execute the hybrid precompilation method in the first embodiment.
Referring now to FIG. 4, shown is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. The electronic devices in the embodiments of the present disclosure may include, but are 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), in-vehicle terminals (e.g., car navigation terminals), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. The electronic device shown in fig. 4 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 4, the electronic device may include a processing means (e.g., a central processing unit, a graphic processor, etc.) that 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 means into a Random Access Memory (RAM). In the RAM, various programs and data necessary for the operation of the electronic apparatus are also stored. The processing device, the ROM, and the RAM are connected to each other by a bus. An input/output (I/O) interface is also connected to the bus.
Generally, the following systems may be connected to the I/O interface: input devices including, for example, touch screens, touch pads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, and the like; output devices including, for example, Liquid Crystal Displays (LCDs), speakers, vibrators, and the like; storage devices including, for example, magnetic tape, hard disk, etc.; and a communication device. The communication means may allow the electronic device to communicate wirelessly or by wire with other devices to exchange data. While the figures illustrate an electronic device with various systems, it is to be understood that not all illustrated systems are required to be implemented or provided. More or fewer systems may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means, or installed from a storage means, or installed from a ROM. The computer program, when executed by a processing device, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
The electronic device provided by the application adopts the hybrid pre-compiling method in the embodiment, so that the technical problem of low pre-compiling efficiency of the computer program is solved. 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 pre-compiling method provided by the first embodiment, and other technical features of the electronic device are the same as those disclosed in the method of the first embodiment, which are not described herein again.
It should be understood that portions of the present disclosure may be implemented in hardware, software, firmware, or a combination thereof. In the foregoing description of embodiments, the particular features, structures, materials, or characteristics may be combined in any suitable manner in any one or more embodiments or examples.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
EXAMPLE five
The present embodiment provides a computer-readable storage medium having computer-readable program instructions stored thereon for performing the hybrid precompilation method of the first embodiment.
The computer readable storage medium provided by the embodiments of the present application may be, for example, a usb disk, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, or device, or a combination of any of the above. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present embodiment, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, or device. Program code embodied on a computer readable storage medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer-readable storage medium may be embodied in an electronic device; or may be present alone without being incorporated into the electronic device.
The computer readable storage medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords; classifying each program keyword to obtain a keyword classification result; dividing the program file to be pre-compiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result; generating an interpreted pre-compiling program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, wherein the interpreted pre-compiling program file is used for being input into an interpreted compiler for compiling; and generating a compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file, wherein the compiled pre-compiled program file is used for being input into a compiled compiler for compiling.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of 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 the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present disclosure may be implemented by software or hardware. Wherein the names of the modules do not in some cases constitute a limitation of the unit itself.
The computer readable storage medium provided by the application stores computer readable program instructions for executing the hybrid precompilation method, and solves the technical problem of low precompilation efficiency of the computer program. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the embodiment of the present application are the same as the beneficial effects of the hybrid pre-compilation method provided by the above embodiment, and are not described herein again.
The above description is only a preferred embodiment of the present application, and not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings, or which are directly or indirectly applied to other related technical fields, are included in the scope of the present application.

Claims (10)

1. A hybrid precompilation method, comprising:
acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords;
classifying each program keyword to obtain a keyword classification result;
dividing the program file to be pre-compiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result;
generating an interpreted pre-compiling program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, wherein the interpreted pre-compiling program file is used for being input into an interpreted compiler for compiling; and generating a compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file, wherein the compiled pre-compiled program file is used for being input into a compiled compiler for compiling.
2. The hybrid precompilation method of claim 1, wherein the contents of the compiler file include at least one compiler instruction,
the step of generating the compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file comprises the following steps:
determining a first pre-compiling program instruction corresponding to the compiling program instruction according to a first preset program instruction mapping relation;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction.
3. The hybrid precompilation method of claim 2, wherein the contents of said compiler file include at least one compiler function,
the step of generating the compiled pre-compiler file according to the first pre-compiler instruction includes:
searching a source program file called by the compiled function in a program file set corresponding to the program file to be precompiled;
expanding the source program file to a function calling position corresponding to the compiled function for mixed pre-compiling to obtain a second pre-compiling program instruction;
and generating the compiled pre-compiled program file according to the first pre-compiled program instruction and the second pre-compiled program instruction.
4. The hybrid precompilation method of claim 3, wherein the contents of the compiled program file include at least one program variable,
the step of generating the compiled pre-compiler file according to the first pre-compiler instruction and the second pre-compiler instruction includes:
according to the variable type corresponding to the program variable, carrying out corresponding custom variable processing on the program variable to obtain a processed program variable;
and generating the compiled type pre-compiled program file according to the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable.
5. The hybrid precompilation method of claim 4, wherein the step of generating the compiled precompilation program file based on the first precompilation program instructions, the second precompilation program instructions and the processed program variables comprises:
integrating the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable into a main program file according to the original semantics of the first pre-compiled program instruction, the second pre-compiled program instruction and the processed program variable in the program file to be pre-compiled;
and taking the main program file as the compiling type pre-compiling program file.
6. The hybrid precompilation method of claim 1, wherein the contents of said interpreter program file include at least one interpreter program instruction,
the step of generating the interpreted pre-compiler program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file comprises the following steps:
determining a third pre-compiling program instruction corresponding to the interpretation type program instruction according to a second preset program instruction mapping relation;
and generating the interpreted pre-compiler program file by expanding the third pre-compiler program instruction into an interpreted pre-compiler program generated by the main program of the program file to be pre-compiled.
7. The hybrid precompilation method of claim 1, wherein before the step of determining the contents of the interpreter program file and the compiler program file in the program file to be precompiled according to the keyword classification result, the hybrid precompilation method further comprises:
according to the keyword classification result, determining annotation content in the program file to be precompiled;
and deleting the annotation content in the program file to be precompiled.
8. A hybrid pre-compilation apparatus, comprising:
the lexical analysis module is used for acquiring a program file to be precompiled, and performing lexical analysis on the program file to be precompiled to obtain program keywords;
the classification module is used for classifying the program keywords to obtain a keyword classification result;
the content dividing module is used for dividing the program file to be precompiled into an interpretation type program file content and a compilation type program file content according to the keyword classification result;
a program file generation module, configured to generate an interpreted pre-compilation program file corresponding to the program file to be pre-compiled according to the content of the interpreted program file, where the interpreted pre-compilation program file is used for being input into an interpreted compiler for compilation; and generating a compiled pre-compiled program file corresponding to the program file to be pre-compiled according to the content of the compiled program file, wherein the compiled pre-compiled program file is used for being input into a compiled compiler for compiling.
9. An electronic device, characterized in that the electronic device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the steps of the hybrid precompilation method of any of claims 1 to 7.
10. A computer-readable storage medium, having stored thereon a program for implementing a hybrid precompilation method, the program being executable by a processor for implementing the steps of the hybrid precompilation method according to any one of claims 1 to 7.
CN202210662650.7A 2022-06-13 2022-06-13 Hybrid pre-compiling method and device, electronic equipment and storage medium Pending CN114968260A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210662650.7A CN114968260A (en) 2022-06-13 2022-06-13 Hybrid pre-compiling method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210662650.7A CN114968260A (en) 2022-06-13 2022-06-13 Hybrid pre-compiling method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114968260A true CN114968260A (en) 2022-08-30

Family

ID=82961523

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210662650.7A Pending CN114968260A (en) 2022-06-13 2022-06-13 Hybrid pre-compiling method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114968260A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024109090A1 (en) * 2022-11-23 2024-05-30 深圳市汇川技术股份有限公司 Hybrid execution method and apparatus of programmable logic controller, device, and medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024109090A1 (en) * 2022-11-23 2024-05-30 深圳市汇川技术股份有限公司 Hybrid execution method and apparatus of programmable logic controller, device, and medium

Similar Documents

Publication Publication Date Title
CN112104709B (en) Intelligent contract processing method, device, medium and electronic equipment
KR20220002823A (en) Method, device and electronic equipment for deploying operators in deep learning framework
CN110489087B (en) Method, device, medium and electronic equipment for generating fractal structure
CN109726217B (en) Database operation method, device, equipment and storage medium
CN109062572B (en) Component calling method, device, equipment and storage medium
CN111240684A (en) Cutting method and device of JS code, medium and electronic equipment
CN109947431B (en) Code generation method, device, equipment and storage medium
CN111381817A (en) Method, device, medium and electronic equipment for realizing cross-platform multi-language development
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN114035805A (en) Code conversion method, apparatus, medium, and device for pre-compiler
CN111338944B (en) Remote Procedure Call (RPC) interface testing method, device, medium and equipment
CN114968260A (en) Hybrid pre-compiling method and device, electronic equipment and storage medium
CN114153473A (en) Module integration method, device, storage medium and electronic equipment
CN112527302B (en) Error detection method and device, terminal and storage medium
CN113377342B (en) Project construction method and device, electronic equipment and storage medium
CN111124541B (en) Configuration file generation method, device, equipment and medium
CN111796865B (en) Byte code file modification method, device, terminal equipment and medium
CN112394920B (en) Application software development method, platform and electronic equipment
CN111539200B (en) Method, device, medium and electronic equipment for generating rich text
CN111399902B (en) Client source file processing method and device, readable medium and electronic equipment
CN111459584B (en) Page rendering method and device and electronic equipment
CN109614104B (en) Method and device for adding new semantic structure based on template preprocessing and electronic equipment
CN112306584A (en) Application program operation control method, device, medium and equipment
CN111240693A (en) Real-time data processing method, device, equipment and storage medium
CN116009951A (en) Code processing method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination