Hybrid language programming translation method and device, electronic equipment, storage medium and product

By analyzing and identifying the common structure of IEC language and building an abstract syntax tree, the problem of repetitive code and implementation in multilingual hybrid programming is solved, the translation efficiency and accuracy are improved, and the code-level consistency is achieved.

CN119225706APending Publication Date: 2024-12-31HANGZHOU HOLLYSYS AUTOMATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411235857.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-04
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

Existing multilingual hybrid programming technology requires the development of intermediate language conversion code for each IEC language, resulting in high repetitive code and inconsistent implementation problems, affecting programming translation efficiency and accuracy.

Method used

By analyzing the common structure of IEC language that recognizes programming statements, an abstract syntax tree is built, and translation is based on the translation rules of the general structure and the target language, sharing the common structure of IEC language, reducing duplicate code and improving consistency.

Benefits of technology

It improves the programming translation efficiency and accuracy of mixed languages, reduces the differences between different languages, and achieves code-level implementation consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225706A_ABST
    Figure CN119225706A_ABST
Patent Text Reader

Abstract

The invention provides a mixed language programming translation method and device, electronic equipment, a storage medium and a product, and the method comprises the steps: carrying out the analysis and recognition of a to-be-translated programming statement, and obtaining an IEC language universal structure corresponding to the to-be-translated programming statement; based on an IEC language general structure, constructing an abstract syntax tree corresponding to a to-be-translated programming statement; the abstract syntax tree is a general syntax tree structure of an IEC language; and translating the abstract syntax tree corresponding to the to-be-translated programming statement into a target translation programming statement corresponding to the target language based on a translation rule between the IEC language general structure and the target language. According to the scheme, various IEC languages share the IEC language general structure, the abstract syntax tree conforming to the IEC language general syntax tree structure is constructed, each IEC language does not need to be independently converted into an intermediate language, repeated codes are reduced, the consistency between different languages is improved, and then the programming translation efficiency and the programming translation accuracy of the mixed language are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of programming translation, and in particular to a mixed language programming translation method, device, electronic device, storage medium and product. Background Art

[0002] The IEC 61131-3 standard supports multiple programming languages, including structured text (ST), ladder diagram (LD), function block diagram (FBD), sequential function chart (SFC) and instruction list (IL). These languages ​​have their own characteristics and are suitable for different programming scenarios and personnel needs. Modern control system programming software generally supports the IEC 61131-3 standard and provides multi-language mixed programming functions. Developers can create program modules in different languages ​​in the same project and connect them through data interfaces, function calls, etc. to form a complete control system.

[0003] Existing multi-language mixed programming usually converts the IEC language into an intermediate language (such as C language) and implements mixed calls between languages ​​through the intermediate language interface standard. However, each IEC language needs to develop a conversion code for the intermediate language, which has a high amount of duplicate code and may cause inconsistencies in the implementation of each language, resulting in differences in the calculation results of different languages, thus affecting the efficiency and accuracy of mixed language programming translation. Summary of the invention

[0004] Based on the above needs, the present application proposes a mixed language programming translation method, device, electronic device, storage medium and product, which can improve the efficiency and accuracy of mixed language programming translation.

[0005] To achieve the above objectives, this application proposes the following technical solutions:

[0006] According to a first aspect of an embodiment of the present application, a mixed language programming translation method is provided, comprising:

[0007] Parsing and identifying the programming statements to be translated to obtain the IEC language general structure corresponding to the programming statements to be translated; wherein the programming statements to be translated are composed of at least one IEC language, and the general structure includes: a lexical structure and a symbolic structure;

[0008] Based on the general structure of the IEC language, construct an abstract syntax tree corresponding to the programming statement to be translated; wherein the abstract syntax tree is a general syntax tree structure of the IEC language;

[0009] Based on the translation rules between the IEC language general structure and the target language, the abstract syntax tree corresponding to the programming statement to be translated is translated into a target translation programming statement corresponding to the target language.

[0010] Optionally, parsing and identifying the programming statement to be translated to obtain the IEC language general structure corresponding to the programming statement to be translated includes:

[0011] Performing lexical recognition on the programming statement to be translated to obtain the lexical structure contained in the programming statement to be translated;

[0012] Based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol structure contained in the programming statement to be translated;

[0013] The lexical structure contained in the programming statement to be translated and the symbolic structure contained in the programming statement to be translated are used as the IEC language general structure corresponding to the programming statement to be translated.

[0014] Optionally, based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol structure contained in the programming statement to be translated, including:

[0015] Based on the lexical structure contained in the programming statement to be translated, the programming statement to be translated is subjected to symbol recognition to obtain the symbol contained in the programming statement to be translated and the type information corresponding to the symbol;

[0016] Determining a symbol definition corresponding to the symbol based on a symbol standard definition in an IEC language and type information corresponding to the symbol; wherein the symbol standard definition in the IEC language includes symbol standard definitions corresponding to different types of information;

[0017] A symbol table consisting of symbols included in the programming statements to be translated and symbol definitions corresponding to the symbols is used as a symbol structure corresponding to the programming statements to be translated.

[0018] Optionally, based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol contained in the programming statement to be translated and type information corresponding to the symbol, including:

[0019] When a variable symbol contained in the programming statement to be translated is identified from the lexical structure of the programming statement to be translated, variable symbol recognition is performed on the variable symbol to determine type information corresponding to the variable symbol; wherein the variable symbol recognition includes: variable symbol type recognition and variable symbol scope recognition.

[0020] Optionally, constructing an abstract syntax tree corresponding to the programming statement to be translated based on the IEC language general structure includes:

[0021] According to the lexical structure in the IEC language general structure, an abstract syntax tree corresponding to the programming statement to be translated is constructed, wherein the abstract syntax tree contains references to symbols in the symbol structure in the IEC language general structure.

[0022] Optionally, based on the translation rule between the IEC language general structure and the target language, translating the abstract syntax tree corresponding to the programming statement to be translated into a target translation programming statement corresponding to the target language includes:

[0023] Based on the translation rules between the general structure of the IEC language and the target language, the lexical structure and the symbolic structure in the abstract syntax tree corresponding to the programming statement to be translated are translated into the target language, and according to the abstract syntax tree, the translated lexical structure and the symbolic structure are combined into a target translated programming statement corresponding to the target language.

[0024] According to a second aspect of an embodiment of the present application, a mixed language programming translation device is provided, comprising:

[0025] A parsing and identifying module, used for parsing and identifying the programming statements to be translated, and obtaining the IEC language general structure corresponding to the programming statements to be translated; wherein the programming statements to be translated are composed of at least one IEC language, and the general structure includes: a lexical structure and a symbolic structure;

[0026] A syntax tree construction module, used to construct an abstract syntax tree corresponding to the programming statement to be translated based on the general structure of the IEC language; wherein the abstract syntax tree is a general syntax tree structure of the IEC language;

[0027] The syntax tree translation module is used to translate the abstract syntax tree corresponding to the programming statement to be translated into a target translation programming statement corresponding to the target language based on the translation rules between the IEC language general structure and the target language.

[0028] According to a third aspect of an embodiment of the present application, there is provided an electronic device, including: a memory and a processor;

[0029] The memory is connected to the processor and is used to store programs;

[0030] The processor is used to implement the above-mentioned mixed language programming translation method by running the program in the memory.

[0031] According to a fourth aspect of an embodiment of the present application, a storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the mixed-language programming translation method described above is implemented.

[0032] According to a fifth aspect of an embodiment of the present application, a computer program product is provided, comprising computer program instructions, which, when executed by a processor, enable the processor to implement the above-mentioned mixed-language programming translation method.

[0033] The mixed language programming translation method proposed in the present application parses and identifies the programming statements to be translated, and obtains the IEC language general structure corresponding to the programming statements to be translated; wherein the programming statements to be translated are composed of at least one IEC language, and the general structure includes: lexical structure and character structure; based on the IEC language general structure, an abstract syntax tree corresponding to the programming statements to be translated is constructed; wherein the abstract syntax tree is a general syntax tree structure of the IEC language; based on the translation rules between the IEC language general structure and the target language, the abstract syntax tree corresponding to the programming statements to be translated is translated into a target translation programming statement corresponding to the target language. With the technical solution of the present application, various IEC languages ​​share the IEC language general structure, thereby constructing an abstract syntax tree that conforms to the general syntax tree structure of the IEC language, without the need to write conversion code to the intermediate language separately for each IEC language, reducing duplicate code, and improving the efficiency of mixed language programming translation. Moreover, all IEC languages ​​are abstract syntax trees constructed based on the IEC language general structure, which improves the consistency between different languages, thereby improving the accuracy of mixed language programming translation. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] 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, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0035] Figure 1 A flow chart of a mixed language programming translation method provided in an embodiment of the present application;

[0036] Figure 2 A schematic diagram of a processing flow for symbol recognition of programming statements to be translated provided in an embodiment of the present application;

[0037] Figure 3 A schematic diagram of the structure of a mixed language programming translation device provided in an embodiment of the present application;

[0038] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0039] The technical solution of the embodiment of the present application is applicable to the application scenario of programming translation, and is specifically used in the application scenario of multi-language mixed programming translation. The technical solution of the embodiment of the present application can improve the efficiency and accuracy of mixed language programming translation.

[0040] As the complexity of industrial automation and control systems continues to increase, the requirements for programming languages ​​and tools are also increasing. The IEC 61131-3 standard came into being in this context, which defines a set of programming languages ​​and programming environments for industrial control systems. The IEC 61131-3 standard aims to achieve standardization, modularization and reusability of control system programming, thereby improving development efficiency, system reliability and maintainability.

[0041] The IEC 61131-3 standard supports multiple programming languages, including structured text (ST), ladder diagram (LD), function block diagram (FBD), sequential function chart (SFC) and instruction list (IL). These languages ​​have their own characteristics and are suitable for different programming scenarios and personnel needs. Modern control system programming software generally supports the IEC 61131-3 standard and provides multi-language mixed programming functions. Developers can create program modules in different languages ​​in the same project and connect them through data interfaces, function calls, etc. to form a complete control system.

[0042] Among them, the background of multi-language hybrid programming is also reflected in the following aspects: First, system complexity: With the expansion of the scale of control systems and the increase of functions, a single language is often unable to handle all programming tasks. Multi-language hybrid programming can make full use of the strengths of various languages ​​to reduce programming difficulty and error rate; Second, personnel requirements: Different developers may be familiar with different programming languages. Multi-language hybrid programming allows developers to use the language they are most proficient in for programming, improving development efficiency and code quality; Third, maintainability: Multi-language hybrid programming can improve the maintainability of the system. When a language module has a problem, it can be modified and tested separately without affecting the normal operation of other modules; Fourth, flexibility: Multi-language hybrid programming can flexibly adjust the programming language and module structure according to actual needs to meet the ever-changing control needs.

[0043] The existing multi-language mixed programming applications usually convert the IEC language (i.e. the programming language supported by the IEC 61131-3 standard) into an intermediate language (such as C language, etc.), and implement mixed calls between languages ​​through the intermediate language interface standard. However, each IEC language needs to develop conversion code for the intermediate language, which has a high amount of duplicate code and may cause inconsistencies in the implementation of each language, resulting in differences in the calculation results of different languages, thus affecting the efficiency and accuracy of mixed language programming translation.

[0044] Based on this, the present application proposes a mixed-language programming translation method. This technical solution enables various IEC languages ​​to share the common structure of the IEC language, thereby constructing an abstract syntax tree that conforms to the common syntax tree structure of the IEC language. There is no need to write conversion code to the intermediate language separately for each IEC language, which reduces duplicate code. Moreover, all IEC languages ​​are abstract syntax trees constructed based on the common structure of the IEC language, which improves the consistency between different languages, thereby solving the problem of low efficiency and accuracy of mixed-language programming translation in the prior art.

[0045] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions 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 are within the scope of protection of this application.

[0046] Exemplary Methods

[0047] See also Figure 1 As shown, the embodiment of the present application proposes a mixed language programming translation method. The method includes:

[0048] S101, parsing and identifying the programming statements to be translated, and obtaining the IEC language general structure corresponding to the programming statements to be translated.

[0049] In this embodiment, programming statements composed of at least one IEC language are used as programming statements to be translated, wherein the IEC language is a programming language supported by the IEC 61131-3 standard, including: structured text (ST), ladder diagram (LD), function block diagram (FBD), sequential function chart (SFC) and instruction list (IL). After obtaining the programming statement to be translated, it is necessary to parse and identify the programming statement to be translated, and identify the lexical structure and symbol structure in the programming statement to be translated. Since the IEC 61131-3 standard stipulates the unified lexical structure and symbol definition of the programming language supported by the IEC 61131-3 standard, even if the programming statement to be translated contains multiple IEC languages, the lexical structure and symbols obtained by identifying the programming statement to be translated are also common to the IEC language. In this embodiment, the lexical structure and symbol structure identified from the programming statement to be translated are used as the IEC language common structure corresponding to the programming statement to be translated. Among them, after parsing and identifying the programming statement to be translated, if the same lexical structure or symbol structure is identified, it only needs to be recorded once, that is, the IEC language general structure does not contain repeated lexical structures and symbol structures, thereby avoiding the waste of storage resources.

[0050] In this embodiment, the parsing of the programming statement to be translated is a grammatical parsing. Generally, different IEC languages ​​correspond to different parsing methods. The various IEC language statements contained in the programming statement to be translated are parsed using the corresponding parsing methods, so that the syntax trees corresponding to the various IEC language statements can be parsed, so as to perform lexical recognition and symbol recognition on the syntax trees corresponding to the parsed various IEC language statements. For example, for the ST language statement in the programming statement to be translated, antlr can be used to perform grammatical parsing on it to generate an antlry syntax tree structure, and then the antlry syntax tree structure is subjected to lexical recognition and symbol recognition to obtain the lexical structure and symbol structure corresponding to the ST language statement in the programming statement to be translated.

[0051] Specifically, this embodiment parses and identifies the programming statement to be translated to obtain the IEC language general structure corresponding to the programming statement to be translated, including the following steps:

[0052] First, lexical recognition is performed on the programming statements to be translated to obtain the lexical structure contained in the programming statements to be translated.

[0053] After obtaining the programming statement to be translated, the present embodiment first performs lexical recognition on the programming statement to be translated to obtain the lexical structure contained in the programming statement to be translated, wherein lexical recognition is lexical analysis, and performing lexical analysis on the programming statement to be translated is a process of decomposing the programming statement to be translated into a series of meaningful lexical units, which are the lexical structures contained in the programming statement to be translated. The lexical units in the programming statement to be translated are basic building blocks of programming language grammar, such as keywords, identifiers, operators, literals, etc. Keywords are if, else, for, while, etc., identifiers are variable names, function names, etc., which are composed of letters, numbers, and underscores, operators are +, -, ×, / , =, ==, ! =, etc., and literals include integers, floating-point numbers, character constants, string constants, etc.

[0054] In this embodiment, the existing lexical analyzer (Lexer or Scanner) can be used to perform lexical recognition on the programming statements to be translated, and the programming statements to be translated can be divided into a series of lexical units according to the lexical rules of the language.

[0055] Second, based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol structure contained in the programming statement to be translated.

[0056] Since symbols are named and used in accordance with the rules prescribed by the lexical structure, that is, symbols are defined on the basis of the lexical structure, when performing symbol recognition on the programming statement to be translated, it is necessary to identify the symbol structure contained in the programming statement to be translated based on the lexical structure contained in the programming statement to be translated. Specifically, input is read character by character from the programming statement to be translated, and the lexical structure contained in the programming statement to be translated is used to match the currently read character sequence, so that the symbol structure that conforms to the lexical structure contained in the programming statement to be translated can be identified.

[0057] Third, the lexical structure contained in the programming statement to be translated and the symbolic structure contained in the programming statement to be translated are used as the IEC language general structure corresponding to the programming statement to be translated.

[0058] After the lexical structure and symbol structure contained in the programming statement to be translated are identified through the above steps, all the lexical structures and symbol structures are used as the IEC language general structure corresponding to the programming statement to be translated.

[0059] S102: construct an abstract syntax tree corresponding to the programming statement to be translated based on the general structure of the IEC language.

[0060] After the IEC language general structure corresponding to the programming statement to be translated is determined through the above steps, the programming statement to be translated is subjected to grammatical analysis, and the lexical structure and the symbolic structure are called from the IEC language general structure according to the grammar in the programming statement to be translated, and an abstract syntax tree that conforms to the grammar in the programming statement to be translated is constructed, and the abstract syntax tree is constructed by calling the IEC language general structure, so the abstract syntax is a general syntax tree structure of the IEC language. Among them, the grammatical analysis of the programming statement to be translated can adopt an existing grammatical analysis method, such as recursive descent analysis, etc.

[0061] Taking ST language as an example, the ST language assignment syntax A:=B+CD is divided into left A and right value expression (B+CD). The expression is recursively descended to finally obtain two variable symbols B and CD. Based on the result of syntax analysis, the corresponding lexical structure and symbol structure are called from the IEC language general structure to construct an abstract structure tree that conforms to the assignment syntax, and finally obtain the general syntax tree structure of the IEC language that conforms to the assignment syntax.

[0062] Specifically, based on the general structure of the IEC language, constructing an abstract syntax tree corresponding to the programming statement to be translated includes the following steps:

[0063] According to the lexical structure in the general structure of the IEC language, an abstract syntax tree corresponding to the programming statement to be translated is constructed.

[0064] In this embodiment, the IEC language general structure corresponding to the programming statement to be translated includes the lexical structure and the symbol structure of the IEC language. The lexical structure provides a specification and framework for the use of the symbol structure, and the symbol structure needs to be named and used in accordance with the rules specified by the lexical structure. Therefore, in this embodiment, it is necessary to refer to symbols from the symbol structure in the IEC language general structure according to the lexical structure in the IEC language general structure to construct an abstract syntax tree that conforms to the grammatical rules of the programming statement to be translated, that is, the constructed abstract syntax tree corresponding to the programming statement to be translated conforms to the grammar of the programming statement to be translated, and the symbols are all references to the symbol structure in the IEC language general structure.

[0065] S103 : Based on the translation rules between the IEC language general structure and the target language, the abstract syntax tree corresponding to the programming statement to be translated is translated into a target translation programming statement corresponding to the target language.

[0066] In this embodiment, the translation rules between the IEC language general structure and the target language are constructed based on the correspondence between each lexical structure and each symbol structure in the IEC language general structure and the target language. In this embodiment, an abstract syntax tree of the general syntax tree structure of the IEC language corresponding to the programming statement to be translated is constructed through the above steps. The lexical structure and symbol structure in the IEC language general structure are used when constructing the abstract syntax tree. Therefore, when translating the abstract syntax tree, it is necessary to translate the lexical structure and symbol structure in the abstract syntax tree corresponding to the programming statement to be translated into the target language based on the translation rules between the IEC language general structure and the target language, and combine the translated lexical structure and symbol structure into the target translation programming statement corresponding to the target language according to the abstract syntax tree.

[0067] Specifically, this embodiment is based on the correspondence between the lexical structure in the general structure of the IEC language and the target language, and performs lexical translation on the abstract syntax tree corresponding to the programming language to be translated, that is, the lexical structure in the abstract syntax tree corresponding to the programming language to be translated is translated into the target language, and based on the correspondence between the symbol structure in the general structure of the IEC language and the target language, the abstract syntax tree corresponding to the programming language to be translated is symbolically translated, that is, the symbol structure in the abstract syntax tree corresponding to the programming language to be translated is translated into the target language. Finally, according to the grammar embodied by the abstract syntax tree corresponding to the programming language to be translated, the lexical structure translated into the target language and the symbol structure translated into the target language are combined into the target translation programming statement corresponding to the target language. In addition, if the abstract syntax tree corresponding to the programming language to be translated includes a parent syntax tree and a child syntax tree, then when the abstract syntax tree is translated, the parent syntax tree and the child syntax tree can be translated separately, and after the translation is completed, according to the calling relationship between the parent syntax tree and the child syntax tree in the abstract syntax tree, the translation statement translated by the parent syntax tree and the translation statement translated by the child syntax tree can be spliced ​​together. Among them, the lexical translation and symbolic translation of the parent syntax tree, as well as the lexical translation and symbolic translation of the child syntax tree, are the same as the lexical translation and symbolic translation of the above-mentioned abstract syntax tree, and will not be repeated in this embodiment.

[0068] From the above introduction, it can be seen that the mixed language programming translation method proposed in the embodiment of the present application parses and identifies the programming statements to be translated, and obtains the IEC language general structure corresponding to the programming statements to be translated; wherein, the programming statements to be translated are composed of at least one IEC language, and the general structure includes: lexical structure and character structure; based on the general structure of the IEC language, an abstract syntax tree corresponding to the programming statements to be translated is constructed; wherein the abstract syntax tree is a general syntax tree structure of the IEC language; based on the translation rules between the general structure of the IEC language and the target language, the abstract syntax tree corresponding to the programming statements to be translated is translated into a target translation programming statement corresponding to the target language. With the technical solution of this embodiment, various IEC languages ​​share the general structure of the IEC language, thereby constructing an abstract syntax tree that conforms to the general syntax tree structure of the IEC language, without the need to write conversion codes to the intermediate language separately for each IEC language, reducing duplicate codes, and improving the efficiency of mixed language programming translation. Moreover, all IEC languages ​​are abstract syntax trees constructed based on the general structure of the IEC language, which improves the consistency between different languages, thereby improving the accuracy of mixed language programming translation.

[0069] In addition, in the application of traditional multi-mixed language programming, different IEC languages ​​can be used between different program organization units (pou), and then the languages ​​of different language pou are converted into intermediate languages ​​(such as C language), and the inter-call between different language pou is realized through the intermediate language interface standard. However, in traditional applications, the implementation schemes of translating different languages ​​into intermediate languages ​​are not necessarily consistent, and the consistency of implementation cannot be guaranteed at the code level. The consistency of implementation can only be guaranteed in the interface call between pou. However, this scheme can ensure the consistency of implementation at the code level because it adopts a common symbol structure and lexical structure for translation. In addition, in traditional applications, different IEC languages ​​cannot be used for writing in the same pou, and the mixed language programming translation method of this application shields the differences between different languages ​​when constructing the abstract syntax tree, and different IEC languages ​​can be used in the same pou for mixed programming at the same time, which reduces the granularity of mixed programming, and the configuration method is more flexible, allowing users to perform more detailed code operations.

[0070] As an optional implementation, see Figure 2 As shown, in another embodiment of the present application, based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol structure contained in the programming statement to be translated, including the following steps:

[0071] S201 . Based on the lexical structure contained in the programming statement to be translated, perform symbol recognition on the programming statement to be translated to obtain the symbols contained in the programming statement to be translated and type information corresponding to the symbols.

[0072] This embodiment is based on the lexical structure contained in the programming statement to be translated. First, the symbols in the programming statement to be translated are identified, that is, the input is read character by character from the programming statement to be translated, and the lexical structure contained in the programming statement to be translated is used to match the character sequence currently read, so that the symbols that conform to the lexical structure contained in the programming statement to be translated can be identified. Then it is necessary to identify the type information corresponding to each symbol, wherein the symbol type includes variable symbols, constant symbols, direct address symbols, operators, etc., and the operators include unary operators and binary operators. Take the expression a+b+c+1+%MB10 as an example, wherein a, b, c are variable symbols, 1 is a constant symbol, %MB10 is a direct address symbol, and + is a binary operator. The type information of the variable symbol includes not only the variable symbol, but also the specific type of variable symbol and the scope of the variable symbol. For example, the variable symbol includes types such as simple variables, member variables, array variables, pointer variables, and bit field variables, and the scope of the variable symbol includes local scope and global scope.

[0073] When the variable symbol contained in the programming statement to be translated is identified from the lexical structure of the programming statement to be translated, the variable symbol is identified to determine the type information corresponding to the variable symbol; wherein the variable symbol identification includes: variable symbol type identification and variable symbol scope identification. The variable symbol type identification result includes: one of a simple variable, a member variable, an array variable, a pointer variable and a bit field variable, and the variable symbol scope identification result includes: one of a local scope and a global scope.

[0074] Specifically, the variable symbol recognition is first performed to determine whether the variable symbol is a simple variable. If the variable symbol is determined to be a simple variable, the variable symbol is subjected to simple variable recognition, and then local scope recognition is performed. If the recognition is successful, the type information of the variable symbol is determined to include simple variables and local scopes. If the recognition is unsuccessful, the global scope recognition is performed. If the global scope recognition is successful, the type information of the variable symbol is determined to include simple variables and global scopes. If the global scope recognition is unsuccessful, the variable symbol is determined to be undefined, and it is necessary to feedback to the user that the variable symbol is undefined so that the user can modify the programming statement to be translated. If the variable symbol is determined not to be a simple variable, the variable symbol is sequentially subjected to complex variable recognition, root node recognition, member variable recognition, array subscript recognition, expression recognition, etc., and finally the type information of the variable symbol is recognized.

[0075] S202: Determine a symbol definition corresponding to the symbol based on the symbol standard definition of the IEC language and type information corresponding to the symbol.

[0076] The IEC 61131-3 standard specifies the symbol definitions corresponding to various symbol types that are unified in the programming languages ​​supported by the IEC 61131-3 standard as the standard symbol definitions of the IEC language. In this embodiment, the symbols contained in the programming statements to be translated and the type information of the symbols are determined by symbol recognition of the programming statements to be translated. The symbols contained in the programming statements to be translated and the symbol definitions corresponding to the symbols can be determined by the standard symbol definitions of the IEC language and the type information corresponding to the symbols. Among them, the symbol definition of the constant symbol usually stores the IEC data type and constant value corresponding to the constant, the symbol definition of the direct address symbol stores the data area header, byte offset and bit offset of the direct address, and the symbol definition of the variable symbol stores the symbol scope, variable symbol type and other information. For example, the definition of the variable symbol can be as follows:

[0077] class variable_token:public symbol_c

[0078] {

[0079] / / Symbol scope local global

[0080] enum scope

[0081] {

[0082] scope_global,

[0083] scope_local

[0084] };

[0085] / / Symbol type simple variable member variable array variable pointer variable bit field variable

[0086] enum variable_type

[0087] {

[0088] pt_single_var,

[0089] pt_member_pin,

[0090] pt_array_pin,

[0091] pt_dereference_pin,

[0092] pt_bit_pin,

[0093] };

[0094] public:

[0095] variable_token(void);

[0096] ~variable_token(void);

[0097] scope scope_;

[0098] variable_type type_;

[0099] std::string name_;

[0100] variable_token*parent_;

[0101] variable_token*child_;

[0102] std::list <expression>array_index_;

[0103] }

[0104] Among them, the symbol scope_ member distinguishes whether the symbol scope is a global or local variable, and the type_ member distinguishes the symbol type. Simple variables: such as variable a; member variables, such as ab, will record the pointer to the parent variable symbol in its members, parent_ is the pointer to the parent variable symbol of variable b, that is, the symbolic representation of variable a.

[0105] S203: Use a symbol table consisting of symbols included in the programming statements to be translated and symbol definitions corresponding to the symbols as a symbol structure corresponding to the programming statements to be translated.

[0106] The symbols included in the programming statements to be translated identified through the above steps and the symbol definitions corresponding to the symbols are stored in a symbol table, and the symbol table is used as a symbol structure corresponding to the programming statements to be translated.

[0107] Exemplary Devices

[0108] Accordingly, the present application embodiment also provides a mixed language programming translation device, see Figure 3 As shown, the device comprises:

[0109] The parsing and identifying module 100 is used to parse and identify the programming statement to be translated, and obtain the IEC language general structure corresponding to the programming statement to be translated; wherein the programming statement to be translated is composed of at least one IEC language, and the general structure includes: a lexical structure and a symbolic structure;

[0110] The syntax tree construction module 110 is used to construct an abstract syntax tree corresponding to the programming statement to be translated based on the general structure of the IEC language; wherein the abstract syntax tree is a general syntax tree structure of the IEC language;

[0111] The syntax tree translation module 120 is used to translate the abstract syntax tree corresponding to the programming statement to be translated into a target translation programming statement corresponding to the target language based on the translation rules between the IEC language general structure and the target language.

[0112] From the above introduction, it can be seen that in the mixed-language programming translation device proposed in the embodiment of the present application, various IEC languages ​​share the common structure of the IEC language, thereby constructing an abstract syntax tree that conforms to the common syntax tree structure of the IEC language. There is no need to write conversion code from each IEC language to the intermediate language separately, which reduces duplicate code and improves the efficiency of mixed-language programming translation. Moreover, all IEC languages ​​are abstract syntax trees constructed based on the common structure of the IEC language, which improves the consistency between different languages ​​and thereby improves the accuracy of mixed-language programming translation.

[0113] In addition, in the application of traditional multi-mixed language programming, different IEC languages ​​can be used between different program organization units (pou), and then the languages ​​of different language pou are converted into intermediate languages ​​(such as C language), and the inter-call between different language pou is realized through the intermediate language interface standard. However, in traditional applications, the implementation schemes of translating different languages ​​into intermediate languages ​​are not necessarily consistent, and the consistency of implementation cannot be guaranteed at the code level. The consistency of implementation can only be guaranteed in the interface call between pou. However, this scheme can ensure the consistency of implementation at the code level because it adopts a common symbol structure and lexical structure for translation. In addition, in traditional applications, different IEC languages ​​cannot be used for writing in the same pou, and the mixed language programming translation method of this application shields the differences between different languages ​​when constructing the abstract syntax tree, and different IEC languages ​​can be used in the same pou for mixed programming at the same time, which reduces the granularity of mixed programming, and the configuration method is more flexible, allowing users to perform more detailed code operations.

[0114] As an optional implementation, another embodiment of the present application discloses that the parsing and recognition module 100 includes: a lexical recognition unit, a symbol recognition unit and a determination unit.

[0115] A lexical recognition unit is used to perform lexical recognition on the programming statement to be translated, and obtain the lexical structure contained in the programming statement to be translated;

[0116] A symbol recognition unit, used for performing symbol recognition on the programming statement to be translated based on the lexical structure contained in the programming statement to be translated, and obtaining the symbol structure contained in the programming statement to be translated;

[0117] The first determining unit is used to use the lexical structure contained in the programming statement to be translated and the symbolic structure contained in the programming statement to be translated as the IEC language general structure corresponding to the programming statement to be translated.

[0118] As an optional implementation, another embodiment of the present application discloses that a symbol recognition unit includes: a symbol type recognition unit, a symbol definition unit and a second determination unit.

[0119] A symbol type recognition unit, used to perform symbol recognition on the programming statement to be translated based on the lexical structure contained in the programming statement to be translated, and obtain the symbols contained in the programming statement to be translated and the type information corresponding to the symbols;

[0120] A symbol definition unit, used to determine a symbol definition corresponding to a symbol based on a symbol standard definition in an IEC language and type information corresponding to the symbol; wherein the symbol standard definition in the IEC language includes symbol standard definitions corresponding to different types of information;

[0121] The second determining unit is used to use a symbol table consisting of symbols included in the programming statement to be translated and symbol definitions corresponding to the symbols as a symbol structure corresponding to the programming statement to be translated.

[0122] As an optional implementation manner, another embodiment of the present application discloses a symbol type identification unit, which is specifically used to:

[0123] When the variable symbols contained in the programming statements to be translated are identified from the lexical structure of the programming statements to be translated, the variable symbols are identified to determine the type information corresponding to the variable symbols; wherein the variable symbol identification includes: variable symbol type identification and variable symbol scope identification.

[0124] As an optional implementation, another embodiment of the present application discloses a syntax tree construction module 110, which is specifically used for:

[0125] According to the lexical structure in the IEC language general structure, an abstract syntax tree corresponding to the programming statement to be translated is constructed, wherein the abstract syntax tree contains references to symbols in the symbol structure in the IEC language general structure.

[0126] As an optional implementation, another embodiment of the present application discloses a syntax tree translation module 120, which is specifically used for:

[0127] Based on the translation rules between the general structure of the IEC language and the target language, the lexical structure and symbolic structure in the abstract syntax tree corresponding to the programming statement to be translated are translated into the target language, and according to the abstract syntax tree, the translated lexical structure and symbolic structure are combined into the target translation programming statement corresponding to the target language.

[0128] The mixed language programming translation device provided in this embodiment belongs to the same application concept as the mixed language programming translation method provided in the above embodiments of this application, and can execute the mixed language programming translation method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of executing the mixed language programming translation method. For technical details not fully described in this embodiment, please refer to the specific processing content of the mixed language programming translation method provided in the above embodiments of this application, and will not be repeated here.

[0129] Exemplary Electronic Devices

[0130] Another embodiment of the present application also provides an electronic device, see Figure 4 As shown, the device includes:

[0131] Memory 200 and processor 210;

[0132] The memory 200 is connected to the processor 210 and is used to store programs;

[0133] The processor 210 is used to implement the mixed language programming translation method disclosed in any of the above embodiments by running the program stored in the memory 200.

[0134] Specifically, the electronic device may further include: a bus, a communication interface 220 , an input device 230 and an output device 240 .

[0135] The processor 210, the memory 200, the communication interface 220, the input device 230 and the output device 240 are connected to each other via a bus.

[0136] A bus may include a pathway that transfers information between components of a computer system.

[0137] The processor 210 may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0138] The processor 210 may include a main processor, and may also include a baseband chip, a modem, and the like.

[0139] The memory 200 stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes a computer operation instruction. More specifically, the memory 200 may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.

[0140] The input device 230 may include a device for receiving data and information input by a user, such as a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.

[0141] Output device 240 may include devices that allow information to be output to a user, such as a display screen, printer, speaker, etc.

[0142] The communication interface 220 may include any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.

[0143] The processor 210 executes the program stored in the memory 200 and calls other devices, which can be used to implement each step of any mixed language programming translation method provided in the above embodiments of the present application.

[0144] Exemplary computer program products and storage media

[0145] In addition to the above-mentioned methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the mixed-language programming translation method according to various embodiments of the present application described in the above "Exemplary Method" section of this specification.

[0146] The computer program product may be written in any combination of one or more programming languages ​​to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user computing device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0147] In addition, an embodiment of the present application may also be a storage medium on which a computer program is stored, and the computer program is executed by a processor to execute the steps of the mixed language programming translation method according to various embodiments of the present application described in the above "Exemplary Method" section of this specification.

[0148] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0149] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0150] The steps in the methods of each embodiment of the present application can be adjusted in order, combined and deleted according to actual needs, and the technical features recorded in each embodiment can be replaced or combined.

[0151] The modules and sub-modules in the devices and terminals of the various embodiments of the present application can be combined, divided and deleted according to actual needs.

[0152] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0153] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0154] In addition, each functional module or submodule in each embodiment of the present application may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.

[0155] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0156] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0157] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0158] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.< / expression>

Claims

1. A mixed language programming translation method, characterized in that: include: Parsing and identifying the programming statements to be translated to obtain the IEC language general structure corresponding to the programming statements to be translated; wherein the programming statements to be translated are composed of at least one IEC language, and the general structure includes: a lexical structure and a symbolic structure; Based on the general structure of the IEC language, construct an abstract syntax tree corresponding to the programming statement to be translated; wherein the abstract syntax tree is a general syntax tree structure of the IEC language; Based on the translation rules between the IEC language general structure and the target language, the abstract syntax tree corresponding to the programming statement to be translated is translated into a target translation programming statement corresponding to the target language.

2. The method according to claim 1, characterized in that Parsing and identifying the programming statements to be translated to obtain the IEC language general structure corresponding to the programming statements to be translated, including: Performing lexical recognition on the programming statement to be translated to obtain the lexical structure contained in the programming statement to be translated; Based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol structure contained in the programming statement to be translated; The lexical structure contained in the programming statement to be translated and the symbolic structure contained in the programming statement to be translated are used as the IEC language general structure corresponding to the programming statement to be translated.

3. The method according to claim 2, characterized in that Based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol structure contained in the programming statement to be translated, including: Based on the lexical structure contained in the programming statement to be translated, the programming statement to be translated is subjected to symbol recognition to obtain the symbol contained in the programming statement to be translated and the type information corresponding to the symbol; Determining a symbol definition corresponding to the symbol based on a symbol standard definition in an IEC language and type information corresponding to the symbol; wherein the symbol standard definition in the IEC language includes symbol standard definitions corresponding to different types of information; A symbol table consisting of symbols included in the programming statements to be translated and symbol definitions corresponding to the symbols is used as a symbol structure corresponding to the programming statements to be translated.

4. The method according to claim 3, characterized in that Based on the lexical structure contained in the programming statement to be translated, symbol recognition is performed on the programming statement to be translated to obtain the symbol contained in the programming statement to be translated and the type information corresponding to the symbol, including: When a variable symbol contained in the programming statement to be translated is identified from the lexical structure of the programming statement to be translated, variable symbol recognition is performed on the variable symbol to determine type information corresponding to the variable symbol; wherein the variable symbol recognition includes: variable symbol type recognition and variable symbol scope recognition.

5. The method according to claim 1, characterized in that Based on the IEC language general structure, constructing an abstract syntax tree corresponding to the programming statement to be translated, including: According to the lexical structure in the IEC language general structure, an abstract syntax tree corresponding to the programming statement to be translated is constructed, wherein the abstract syntax tree contains references to symbols in the symbol structure in the IEC language general structure.

6. The method according to claim 1, characterized in that Based on the translation rules between the IEC language general structure and the target language, translating the abstract syntax tree corresponding to the programming statement to be translated into a target translation programming statement corresponding to the target language includes: Based on the translation rules between the general structure of the IEC language and the target language, the lexical structure and the symbolic structure in the abstract syntax tree corresponding to the programming statement to be translated are translated into the target language, and according to the abstract syntax tree, the translated lexical structure and the symbolic structure are combined into a target translated programming statement corresponding to the target language.

7. A mixed language programming translation device, characterized in that: include: A parsing and identifying module, used for parsing and identifying the programming statements to be translated, and obtaining the IEC language general structure corresponding to the programming statements to be translated; wherein the programming statements to be translated are composed of at least one IEC language, and the general structure includes: a lexical structure and a symbolic structure; A syntax tree construction module, used to construct an abstract syntax tree corresponding to the programming statement to be translated based on the general structure of the IEC language; wherein the abstract syntax tree is a general syntax tree structure of the IEC language; The syntax tree translation module is used to translate the abstract syntax tree corresponding to the programming statement to be translated into a target translation programming statement corresponding to the target language based on the translation rules between the IEC language general structure and the target language.

8. An electronic device, characterized in that: include: Memory and processor; The memory is connected to the processor and is used to store programs; The processor is used to implement the mixed-language programming translation method as described in any one of claims 1 to 6 by running the program in the memory.

9. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the mixed-language programming translation method according to any one of claims 1 to 6 is implemented.

10. A computer program product, characterized in that The method comprises computer program instructions, which, when executed by a processor, enable the processor to implement the mixed-language programming translation method according to any one of claims 1 to 6.