CN109254776B - Multi-language code compiling method and compiler - Google Patents

Multi-language code compiling method and compiler Download PDF

Info

Publication number
CN109254776B
CN109254776B CN201811153588.9A CN201811153588A CN109254776B CN 109254776 B CN109254776 B CN 109254776B CN 201811153588 A CN201811153588 A CN 201811153588A CN 109254776 B CN109254776 B CN 109254776B
Authority
CN
China
Prior art keywords
language
semantic analysis
analysis result
model
code
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.)
Active
Application number
CN201811153588.9A
Other languages
Chinese (zh)
Other versions
CN109254776A (en
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 Leadshine Control Technology Co Ltd
Original Assignee
Shenzhen Leadshine Control 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 Leadshine Control Technology Co Ltd filed Critical Shenzhen Leadshine Control Technology Co Ltd
Priority to CN201811153588.9A priority Critical patent/CN109254776B/en
Publication of CN109254776A publication Critical patent/CN109254776A/en
Application granted granted Critical
Publication of CN109254776B publication Critical patent/CN109254776B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/436Semantic checking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The application provides a multi-language code compiling method and a compiler, and relates to the technical field of language compiling. The compiling method comprises the following steps: performing lexical analysis processing on a source program code according to a preset lexical analysis rule to generate a lexical analysis result, wherein the source program code comprises source program codes of a plurality of different languages; performing syntactic-semantic analysis on the lexical analysis result according to a preset semantic analysis rule to generate a syntactic-semantic analysis result; and analyzing the target code according to the semantic analysis result of the grammar according to the generation rule of the preset target code to generate the target code. The compiling method integrates the language independence modules based on the IEC61131-3 standard, so that the structure of the multi-language compiler is greatly simplified, the code efficiency is improved, the code maintenance is reduced, and the support of the BASIC language is added on the basis of the IEC61131-3 programming language.

Description

Multi-language code compiling method and compiler
Technical Field
The present application relates to the field of language compilation technologies, and in particular, to a multi-language code compiling method and a compiler.
Background
The IEC61131-3 standard is an international standard on hardware, installation, testing, programming, communication, etc. of programmable controllers. The IEC61131-3 is a PLC programming language standard, and describes five programming languages in detail, including a Ladder Diagram (LD), a Sequential Function flowchart (SFC), a Function Block Diagram (FBD), and three graphical languages; and the system also comprises two Text languages of an Instruction List (IL) and a Structured Text (ST). The IEC61131-3 standard is used as an industrial standard of soft logic programming in the industrial control field and is widely applied to various PLC manufacturers.
In the existing IEC61131-3 standard language-based multi-language compiler, a simplified compiler is realized by adding a language converter to translate multiple languages into one or a few language source programs and then compiling the source programs by one or a few single-language compilers, although the compiler is simplified, functional modules still have much redundancy, and the user experience is not good in the aspects of improving code efficiency and code maintenance.
Content of application
The present application aims to provide a multi-language code compiling method and compiler to improve the code efficiency and reduce the code maintenance, and add the support of the BASIC language on the basis of the IEC61131-3 programming language, in order to overcome the above-mentioned shortcomings in the prior art.
In order to achieve the above purpose, the technical solutions adopted in the embodiments of the present application are as follows:
in a first aspect, an embodiment of the present application provides a multi-language code compiling method, where the method includes:
performing lexical analysis processing on the source program codes according to preset lexical analysis rules to generate lexical analysis results, wherein the source program codes comprise source program codes of multiple different languages;
performing syntactic and semantic analysis on the lexical analysis result according to a preset syntactic and semantic analysis rule to generate a syntactic and semantic analysis result;
and analyzing the target code according to the syntax and semantic analysis result of the preset target code to generate the target code.
Further, the source program code includes at least 2 of the following source program code:
ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
Further, performing lexical analysis processing on the source program code according to a preset lexical analysis rule to generate a lexical analysis result, including:
adding a header file code required by source program code compiling to a source program code to obtain a new source program code;
carrying out lexical analysis processing on the new source program code according to a preset lexical analysis rule and generating a lexical analysis result; the preset lexical analysis rule comprises one or more of the following combinations: a delimiter category, an operator category, an identifier category, an annotation category, a constant category, or a keyword category rule.
Further, according to a preset syntax and semantic analysis rule, syntax and semantic analysis is performed on the lexical analysis result to generate a syntax and semantic analysis result, which comprises the following steps:
and carrying out syntactic and semantic analysis on the lexical analysis result of the source program code by adopting a variable model to generate a syntactic and semantic analysis result of the variable model, wherein the variable model comprises the following steps: defining a single variable and a variable segment, wherein the definition of the variable segment comprises the definitions of an input variable segment, an output variable segment, a local variable segment and a global variable segment;
and performing syntax and semantic analysis of the software model on the syntax and semantic analysis result of the variable model by adopting the software model to generate the syntax and semantic analysis result of the software model, wherein the definition of the software model comprises the following steps: defining software configuration, software resources and software tasks;
adopting a program organization unit model to carry out the syntactic semantic analysis of the program organization unit model on the syntactic semantic analysis result of the software model, and generating the syntactic semantic analysis result of the program organization unit model, wherein the definition of the program organization unit model comprises the following steps: definition of functions, functional blocks, and procedures.
Further, according to the syntax semantic analysis result of the variable model, performing syntax semantic analysis of the program organization unit model to generate a syntax semantic analysis result of the program organization unit model, including:
dividing the syntactic and semantic analysis results of the software model to obtain analysis results of at least 2 languages;
performing syntactic and semantic analysis of the program organization unit model on the analysis results of the at least 2 languages respectively; wherein the at least 2 languages include at least 2 of: ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
In a second aspect, an embodiment of the present application further provides a multi-language code compiler, including a lexical analyzer, a semantic parser, and an object code generator;
the lexical analyzer is used for carrying out lexical analysis processing on the source program codes according to preset lexical analysis rules to generate lexical analysis results, wherein the source program codes comprise source program codes of different languages;
the syntactic and semantic analyzer is used for carrying out syntactic and semantic analysis on the lexical analysis result according to a preset syntactic and semantic analysis rule to generate a syntactic and semantic analysis result;
and the target code generator is used for analyzing the target code according to the generation rule of the preset target code on the syntactic semantic analysis result to generate the target code.
Further, the source program code includes at least 2 source program codes selected from the group consisting of a ladder diagram language, a sequential function flow diagram language, a function block diagram language, a command list language, a structured text language, and a compilation of a BASIC language.
Further, the lexical analyzer is specifically configured to add a header file code required for compiling the source program code to obtain a new source program code; carrying out lexical analysis processing on the new source program code according to a preset lexical analysis rule and generating a lexical analysis result; the preset lexical analysis rule comprises one or more of the following combinations: a delimiter category, an operator category, an identifier category, an annotation category, a constant category, or a keyword category rule.
Further, the syntax semantic analyzer is specifically configured to perform syntax semantic analysis on a lexical analysis result of the source program code by using the variable model, and generate a syntax semantic analysis result of the variable model, where the variable model includes: defining a single variable and a variable segment, wherein the definition of the variable segment comprises the definitions of an input variable segment, an output variable segment, a local variable segment and a global variable segment; and performing syntax and semantic analysis of the software model on the syntax and semantic analysis result of the variable model by adopting the software model to generate the syntax and semantic analysis result of the software model, wherein the definition of the software model comprises the following steps: defining software configuration, software resources and software tasks; adopting the program organization unit model to carry out the syntactic semantic analysis of the program organization unit model on the syntactic semantic analysis result of the software model, and generating the syntactic semantic analysis result of the program organization unit model, wherein the definition of the program organization unit model comprises the following steps: definition of functions, functional blocks, and procedures.
Further, the syntax semantic analyzer is specifically configured to divide syntax semantic analysis results of the software model to obtain analysis results of at least 2 languages; respectively carrying out syntactic and semantic analysis on the analysis results of at least 2 languages on the program organization unit model; wherein the at least 2 languages include at least 2 of: ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
The beneficial effect of this application is:
in the multilingual code compiling method and the compiler provided by the embodiment of the application, based on the IEC61131-3 standard, the source program codes of various different languages can be compiled by using the compiling method, and the source language-independent parts are integrated, so that the structure of the multilingual compiler is greatly simplified, the code efficiency is improved, the code maintenance is reduced, and the BASIC language compiling support is added on the basis of the IEC61131-3 programming language.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.
FIG. 1 is a schematic diagram of a hierarchical structure of the IEC61131-3 programming standard provided by an embodiment of the present application;
FIG. 2 is a flowchart illustrating a multilingual compiling method according to an embodiment of the present application;
FIG. 3 is a diagram illustrating a multi-language compiler according to an embodiment of the present application;
fig. 4 is a schematic diagram of an architecture of a multilingual compiler according to an embodiment of the present application.
Icon: 201-lexical analyzer; 202-syntax semantic analyzer; 203-object code generator; 204-a variable model analyzer; 205-software model analyzer; 206-program organization unit model analyzer; 207-intermediate code generator; 208-an environmental monitoring analyzer; 209-error manager.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. 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.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The application firstly introduces the IEC61131-3 standard, and the IEC11131-3 programming standard mainly comprises two parts: common elements and programming languages. The two parts are normalized to the standard control engineering language at different levels of the language, and the hierarchical structure is shown in FIG. 1. The common language elements are standard universal modules and have the same definition structure in any editing language; the programming language part is a specific definition of the control engineering programming language and relates to a syntactic semantic structure of the specific language.
Secondly, the present application introduces the existing multi-language compiler supporting the IEC61131-3 standard, as mentioned above, the IEC61131-3 standard describes 5 programming languages, which includes three graphical languages, namely Ladder Diagram (LD), sequential function flow chart (SFC) and Function Block Diagram (FBD); and two text languages of an Instruction List (IL) and a Structured Text (ST) are also included. Particularly, the LD language, the SFC language, and the FBD language are easy in terms of logic control; IL language and ST language, it is easy to implement some complex algorithms.
An embodiment of the present application provides a multi-language code compiling method, as shown in fig. 3, where the method includes:
s101, performing lexical analysis processing on source program codes according to preset lexical analysis rules to generate lexical analysis results, wherein the source program codes comprise source program codes of different languages.
The preset lexical analysis rule can be a pre-defined lexical rule, the source program codes are firstly analyzed and processed according to the lexical rule, and particularly, the unified preset lexical analysis rule is used for carrying out lexical analysis preprocessing on the source program codes of various different languages.
And S102, carrying out syntactic and semantic analysis on the lexical analysis result according to a preset syntactic and semantic analysis rule to generate a syntactic and semantic analysis result.
In the generation of the syntax and semantic analysis result, a source program code is divided into a source language related part and a source language irrelevant part according to whether the lexical analysis result is an implementation part of a source language function. The source language related part is an implementation part of a source language function; definitions of some variables in the "source language independent" part, i.e. the source language program, etc., for example: definition of variable models and software model sections in source program code.
And the source program code generates a lexical analysis result after carrying out lexical analysis preprocessing, and the lexical analysis result further generates a syntactic and semantic analysis result after carrying out syntactic and semantic division preprocessing.
Particularly, for source program codes of a plurality of different languages, the source language related part is used for respectively processing lexical analysis results of the different languages by using different preset syntactic and semantic analysis rules so as to generate corresponding syntactic and semantic analysis results; and the source language irrelevant part is used for processing lexical analysis results of different languages by using a uniform preset syntactic and semantic analysis rule so as to generate a syntactic and semantic analysis result.
And S103, analyzing the target code according to the syntax and semantic analysis result of the preset target code to generate the target code.
In the process of generating the target code by the semantic analysis result of the grammar, an intermediate code needs to be introduced, the intermediate code is an equivalent internal representation code which is oriented to the grammar and easy to translate into a source program of the target program, and the intelligibility and the degree of easy generation of the target code are between the source language and the target language. Therefore, the obtained syntax semantic analysis result firstly generates an intermediate code result according to a generation rule of a preset intermediate code; and generating the target code according to the intermediate code result and the target code generation rule.
Particularly, for source program codes of a plurality of different languages, a uniform generation rule of preset intermediate codes is used for generating an intermediate code result; and generating the target code by using the uniform preset target code generation rule as the intermediate code result.
Specifically, the multi-language code compiling method provided by the application has the following compiling steps:
firstly, lexical analysis is carried out on source programs of a plurality of different languages through unified preset lexical analysis rules, and lexical analysis results are generated. Secondly, in the process of generating the syntax semantic analysis result, the source program code is divided into a source language related part and a source language unrelated part according to whether the input program code to be processed is an implementation part of a source language function. For the source language relevant part, different languages are respectively processed by using different preset syntactic and semantic analysis rules to generate corresponding syntactic and semantic analysis results; for the source language irrelevant part, processing by using a uniform preset syntax and semantic analysis rule to generate a syntax and semantic analysis result; and finally, analyzing the target code according to the generation rule of the preset target code on the syntactic and semantic analysis result to generate the target code and finish the compiling of the multi-language code.
In summary, the multi-language code compiling method provided by the application is based on the IEC61131-3 standard, and can support not only the compiling of the specified language of the IEC61131-3 standard, but also the compiling of the BASIC language, and the source program codes of a plurality of different languages can be compiled by using the compiling method, and the structure of the multi-language compiler is greatly simplified by integrating the source language irrelevant parts, so that the code efficiency is improved, and the code maintenance is reduced.
Further, the source program code includes at least 2 of the following source program code:
the source program code includes LD language, SFC language, FBD language, IL language, and ST language, and BASIC language.
The method supports the compiling of multi-language source program codes, wherein the source program codes comprise source program codes of various different languages, and particularly, an LD language, an SFC language and an FBD language are graphical languages; the IL language and the ST language are textual languages. The BASIC language is similar to the ST language in syntax structure, richer than ST language instructions, and has similar properties to ST, so the present application will support compilation of the BASIC language.
Further, performing lexical analysis processing on the source program code according to a preset lexical analysis rule to generate a lexical analysis result, including: adding a header file code required by source program code compiling to a source program code to obtain a new source program code; carrying out lexical analysis processing on the new source program code according to a preset lexical analysis rule and generating a lexical analysis result; the preset lexical analysis rule comprises one or more of the following combinations: a delimiter category, an operator category, an identifier category, an annotation category, a constant category, or a keyword category rule.
The header file is used as a bridge and a link between the user source program code and the function library, when compiling, the compiler finds the corresponding function library through the header file, and then exports the actual content of the quoted function to replace the original function, the compiling process of the source program code can be simplified by using the uniform definition function, and the reusability of the code is improved.
The preset lexical analysis rule comprises one or more of the following combinations: a delimiter category, an operator category, an identifier category, an annotation category, a constant category, or a keyword category rule, including but not limited to. Specifically, in the preset lexical rule, for example: the delimiters and the comments only play roles of separating words and assisting editing, have no practical significance, and do not need to perform additional operation after recognition; after the constant is identified, returning a constant type and a constant value; after the identifier is identified, it is determined whether the keyword is a keyword.
Further, according to a preset syntax and semantic analysis rule, syntax and semantic analysis is performed on the lexical analysis result to generate a syntax and semantic analysis result, which comprises the following steps: performing syntax and semantic analysis on the lexical analysis result of the source program code by using a variable model to generate a syntax and semantic analysis result of the variable model, wherein the variable model comprises the following steps: the definition of the variable section comprises the definition of an input variable section, an output variable section, a local variable section and a global variable section.
Wherein the variable definition model comprises two parts, a single variable definition and a variable segment definition. Several variables may be defined in each variable segment.
And performing syntax and semantic analysis of the software model on the syntax and semantic analysis result of the variable model by adopting the software model to generate the syntax and semantic analysis result of the software model, wherein the definition of the software model comprises the following steps: definition of software configuration, software resources and software tasks.
Performing syntax and semantic analysis of the Program Organization Unit model on syntax and semantic analysis results of the software model by adopting a Program Organization Unit (POU) model to generate syntax and semantic analysis results of the Program Organization Unit model, wherein the definition of the Program Organization Unit model comprises the following steps: definition of functions, functional blocks, and procedures.
POUs are specifically defined areas of user algorithm implementation, POUs can call each other with or without parameters, and are the smallest, independent software units in a user program.
Further, according to the syntax semantic analysis result of the software model, performing syntax semantic analysis of the program organization unit model to generate a syntax semantic analysis result of the program organization unit model, including: dividing the syntactic and semantic analysis results of the software model to obtain analysis results of at least 2 languages; respectively carrying out syntactic and semantic analysis on the analysis results of at least 2 languages on the program organization unit model; wherein the at least 2 languages include at least 2 of: LD language, SFC language, FBD language, IL language, ST language, and BASIC language.
In addition, it should be noted that, according to the present application, the operating environment and the error state of the lexical analysis result generation process, the syntactic and semantic analysis result generation process, and the target code generation process may be monitored according to a preset operating environment rule and a preset error management rule.
In addition, as shown in fig. 3, another embodiment of the present application further provides a multilingual code compiler, including: a lexical analyzer 201, a semantic parser 202 and an object code generator 203;
and the lexical analyzer 201 is configured to perform lexical analysis processing on the source program codes according to preset lexical analysis rules to generate lexical analysis results, where the source program codes include source program codes in multiple different languages.
And the syntactic and semantic analyzer 202 is used for performing syntactic and semantic analysis on the lexical analysis result according to a preset syntactic and semantic analysis rule to generate a syntactic and semantic analysis result.
And the target code generator 203 is configured to analyze the target code according to a preset target code generation rule on the syntax semantic analysis result, so as to generate a target code.
Further, the source program code includes at least 2 source program codes of: compilation of LD language, SFC language, FBD language, IL language, ST language, and BASIC language.
Further, the lexical analyzer 201 is specifically configured to add a header file code required for compiling the source program code to obtain a new source program code; carrying out lexical analysis processing on the new source program code according to a preset lexical analysis rule and generating a lexical analysis result; the preset lexical analysis rule comprises one or more of the following combinations: a delimiter category, an operator category, an identifier category, an annotation category, a constant category, or a keyword category rule.
Specifically, the LEXical analyzer 201 of the present application may be a LEXical generator (LEX), and a source file of the LEX-generated LEXical analyzer has a three-part structure: the definition segment, the rule segment and the supporting program segment are divided between each part by two consecutive percentiles of the top row "%". Among them, there are three support programs: the method comprises a keyword judgment program, a keyword type program acquisition program and an identifier registration program, wherein the program of the part of the supporting program segment is briefly listed as follows:
IsKeyWord()
{/' search the keyword table to determine if the keyword is ^ based
// KeyTextFirst is the first character of the keyword; KeyTextLeng: key length };
GetKeyWordType () {// get keyword type };
register Key () {// load key into symbol table };
further, the syntax semantic analyzer 202 is specifically configured to perform syntax semantic analysis on the lexical analysis result of the source program code by using a variable model, and generate a syntax semantic analysis result of the variable model, where the variable model includes: defining a single variable and a variable segment, wherein the definition of the variable segment comprises the definitions of an input variable segment, an output variable segment, a local variable segment and a global variable segment; and performing syntax and semantic analysis of the software model on the syntax and semantic analysis result of the variable model by adopting the software model to generate the syntax and semantic analysis result of the software model, wherein the definition of the software model comprises the following steps: defining software configuration, software resources and software tasks; adopting a program organization unit model to carry out syntactic semantic analysis of the program organization unit model on syntactic semantic analysis results of the software model, and generating syntactic semantic analysis results of the program organization unit model, wherein the definition of the program organization unit model comprises the following steps: definition of functions, functional blocks, and procedures.
In the present application, when the parser 202 is a Compiler code generator (YACC), the YACC parser source file has a three-part structure: the definition segment, the rule segment and the supporting program segment are divided between each part by two consecutive percentiles of the top row "%". When the parser 202 is a YACC parser, it will include three parsers 202, as shown in fig. 4, which are: a variable model analyzer 204, a software model analyzer 205, and a program organization unit model analyzer 206. It should be noted that the syntax parser 202 of each model has its corresponding definition segment, rule segment and supporting program segment, and the syntax parser 202 of the three types of models will be described separately in the following application.
The variable model analyzer 204 is configured to perform syntax and semantic analysis on the lexical analysis result of the source program code by using a variable model, and generate a syntax and semantic analysis result of the variable model, where the variable model includes: defining a single variable and a variable segment, wherein the definition of the variable segment comprises the definitions of an input variable segment, an output variable segment, a local variable segment and a global variable segment;
that is, the variable model analyzer 204 includes two parts, a single variable definition and a variable segment definition. Several variables may be defined in each variable segment. Two specification rules and actions for a single variable are defined as follows:
%%
VarDefine:VarName VarType;
{InstallVar(VarName.exp,VarType.exp);}
VarDefine:VarName VarType:=immediate;
{InstallVar(VarName.exp,VarType.exp,immediate.val);}
%%
after the reduction variables are defined, the syntax parser calls the corresponding grammar definition
Figure GDA0003354787900000171
An action code.
VarInSeg:VAR_INPUT{SetCurrSegVarIn();}
VarDefine*
END_VAR{CloseCurrVarSeg();}
The above statements are input variable segment specification rules and action definitions, and the C language program in the parentheses is used for completing the functions of setting the current code segment and closing the current code segment. The reduction rules and action definitions of other output variable segments, local variable segments, global variable segments are similar to the input variables.
The software model analyzer 205 is configured to perform syntax and semantic analysis of the software model on the syntax and semantic analysis result of the variable model by using the software model to generate the syntax and semantic analysis result of the software model, where the definition of the software model includes: definition of software configuration, software resources and software tasks.
The rule fragment of YACC describes the specification rules and specification actions of the syntax semantics. For example, after the lexical analyzer 201 reads "Configuration", it searches for a grammar definition and determines to use a definition formula of Configuration; the "configuration" contract is followed by an identifier that defines the name of the configuration. After the parser reads in the program, the following actions are performed: registering a configuration module of the ConfigName; then continuing to execute, identifying configuration statement information, and executing a SetConfigAttribute () action of setting configuration attributes; when "END _ Configuration" is read, the grammar definition is executed completely, and the parser performs Configuration reduction.
Figure GDA0003354787900000181
A program organization unit model analyzer 206, configured to perform syntax and semantic analysis on the syntax and semantic analysis result of the software model by using the program organization unit model to generate the syntax and semantic analysis result of the program organization unit model, where the definition of the program organization unit model includes: definition of functions, functional blocks, and procedures.
Figure GDA0003354787900000182
Figure GDA0003354787900000191
Further, the syntax semantic analyzer 202 is specifically configured to divide syntax semantic analysis results of the software model to obtain analysis results of at least 2 languages; performing syntactic and semantic analysis of the program organization unit model on the analysis results of the at least 2 languages respectively; wherein the at least 2 languages include at least 2 of: ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
The syntax parser 202 first divides the syntax parsing result of the software model into a "source language dependent" part and a "source language independent" part. For the definition of the "source language related" part and the "source language irrelevant" part, please refer to the above description, which is not repeated herein. The syntax parser 202 divides the syntax parsing result of the software model of at least 2 languages, which is described herein by taking IL language and BASIC language as examples. Specifically, in the definition part of "program" in the program organization unit model, different analysis tools need to be called according to specific languages for the PouBody part of the program.
The syntax semantic analyzer 202 firstly divides the syntax semantic analysis result of the software model of the IL language and the BASIC language into a source language related part of the IL language; the "source language dependent" section of the BASIC language; a "source language independent" section that is independent of both the IL language and the BASIC language.
For the "source language related" part of the IL language, a specific program organization unit model analyzer 206 of the IL language is used to perform syntactic semantic analysis of the corresponding program organization unit model; finally, the intermediate code generator 207 and the object code generator 203 sequentially generate an object code.
For the source language correlation part of the BASIC language, a specific program organization unit model analyzer 206 of the BASIC language is adopted to analyze the syntax and the semantics of the corresponding program organization unit model; finally, the intermediate code generator 207 and the object code generator 203 sequentially generate an object code.
For the source language independent parts which are not related to both IL language and BASIC language, the intermediate code generator 207 and the target code generator 203 will be passed directly through to generate the target code.
Further, the system comprises a runtime environment monitoring analyzer 208 and an error manager 209, wherein the runtime environment monitoring analyzer 208 is configured to monitor, in real time, the execution environment of the LEX generation lexical analyzer, the YACC semantic analyzer, the target code generator 203, and the like according to preset execution environment rules; the error manager 209 is used for real-time monitoring, statistics, etc. of errors and warnings generated by the LEX parser, YACC parser, and object code generator 203.
Another embodiment of the present application provides a program product, such as a computer-readable storage medium, having a computer program stored thereon, which, when executed by a processor, is adapted to perform the above-described method embodiments. The specific implementation and technical effects are similar, and are not described herein again.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
The above description is only a preferred embodiment of the present application and is not intended to limit the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims (8)

1. A multi-language code compilation method, comprising:
performing lexical analysis processing on a source program code according to a preset lexical analysis rule to generate a lexical analysis result, wherein the source program code comprises source program codes of a plurality of different languages;
performing syntactic and semantic analysis on the lexical analysis result according to a preset syntactic and semantic analysis rule to generate a syntactic and semantic analysis result;
analyzing the target code according to the semantic analysis result of the grammar according to a generation rule of a preset target code to generate a target code;
the syntax and semantic analysis is carried out on the lexical analysis result according to a preset syntax and semantic analysis rule to generate a syntax and semantic analysis result, and the syntax and semantic analysis method comprises the following steps:
performing syntax and semantic analysis on the lexical analysis result of the source program code by using a variable model to generate a syntax and semantic analysis result of the variable model, wherein the variable model comprises: defining a single variable and a variable segment, wherein the definition of the variable segment comprises the definitions of an input variable segment, an output variable segment, a local variable segment and a global variable segment;
and performing syntax and semantic analysis of the software model on the syntax and semantic analysis result of the variable model by adopting the software model to generate the syntax and semantic analysis result of the software model, wherein the definition of the software model comprises the following steps: defining software configuration, software resources and software tasks;
adopting a program organization unit model to carry out the syntactic semantic analysis of the program organization unit model on the syntactic semantic analysis result of the software model, and generating the syntactic semantic analysis result of the program organization unit model, wherein the definition of the program organization unit model comprises the following steps: definition of functions, functional blocks, and procedures.
2. The method of claim 1, wherein the source program code comprises at least 2 source program codes selected from the group consisting of:
ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
3. The method of claim 1, wherein the lexical analysis processing is performed on the source program code according to a preset lexical analysis rule to generate a lexical analysis result, and the method comprises:
adding a header file code required by compiling the source program code to obtain a new source program code;
performing lexical analysis processing on the new source program code according to a preset lexical analysis rule and generating a lexical analysis result; wherein the preset lexical analysis rule comprises one or more of the following combinations: a delimiter category, an operator category, an identifier category, an annotation category, a constant category, or a keyword category rule.
4. The method of claim 1, wherein the performing semantic analysis of the program organization unit model according to the semantic analysis result of the variable model to generate the semantic analysis result of the program organization unit model comprises:
dividing the syntactic and semantic analysis results of the software model to obtain analysis results of at least 2 languages;
performing syntactic and semantic analysis of the program organization unit model on the analysis results of the at least 2 languages respectively; wherein the at least 2 languages include at least 2 of: ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
5. A multi-language code compiler, comprising: a lexical analyzer, a semantic parser and an object code generator;
the lexical analyzer is used for performing lexical analysis processing on the source program codes according to preset lexical analysis rules to generate lexical analysis results, wherein the source program codes comprise source program codes of multiple different languages;
the syntactic and semantic analyzer is used for carrying out syntactic and semantic analysis on the lexical analysis result according to a preset syntactic and semantic analysis rule to generate a syntactic and semantic analysis result;
the target code generator is used for analyzing the target code according to the generation rule of the preset target code on the syntactic semantic analysis result to generate the target code;
the syntax semantic analyzer is specifically configured to perform syntax semantic analysis on the lexical analysis result of the source program code by using a variable model to generate a syntax semantic analysis result of the variable model, where the variable model includes: defining a single variable and a variable segment, wherein the definition of the variable segment comprises the definitions of an input variable segment, an output variable segment, a local variable segment and a global variable segment;
and performing syntax and semantic analysis of the software model on the syntax and semantic analysis result of the variable model by adopting the software model to generate the syntax and semantic analysis result of the software model, wherein the definition of the software model comprises the following steps: defining software configuration, software resources and software tasks;
adopting a program organization unit model to carry out the syntactic semantic analysis of the program organization unit model on the syntactic semantic analysis result of the software model, and generating the syntactic semantic analysis result of the program organization unit model, wherein the definition of the program organization unit model comprises the following steps: definition of functions, functional blocks, and procedures.
6. The multi-lingual code compiler of claim 5, wherein the source program code comprises at least 2 of the following source program codes:
the compilation of ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
7. The multi-language code compiler of claim 5, wherein the lexical analyzer is specifically configured to add header code required for compiling the source program code to obtain a new source program code;
performing lexical analysis processing on the new source program code according to a preset lexical analysis rule and generating a lexical analysis result; wherein the preset lexical analysis rule comprises one or more of the following combinations: a delimiter category, an operator category, an identifier category, an annotation category, a constant category, or a keyword category rule.
8. The multi-lingual code compiler of claim 5, wherein the syntax parser is specifically configured to divide the syntax parsing result of the software model to obtain parsing results of at least 2 languages;
performing syntactic and semantic analysis of the program organization unit model on the analysis results of the at least 2 languages respectively; wherein the at least 2 languages include at least 2 of: ladder diagram language, sequential function flow diagram language, function block diagram language, instruction list language, structured text language and BASIC language.
CN201811153588.9A 2018-09-29 2018-09-29 Multi-language code compiling method and compiler Active CN109254776B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811153588.9A CN109254776B (en) 2018-09-29 2018-09-29 Multi-language code compiling method and compiler

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811153588.9A CN109254776B (en) 2018-09-29 2018-09-29 Multi-language code compiling method and compiler

Publications (2)

Publication Number Publication Date
CN109254776A CN109254776A (en) 2019-01-22
CN109254776B true CN109254776B (en) 2022-02-01

Family

ID=65044874

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811153588.9A Active CN109254776B (en) 2018-09-29 2018-09-29 Multi-language code compiling method and compiler

Country Status (1)

Country Link
CN (1) CN109254776B (en)

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109918081B (en) * 2019-03-01 2022-06-03 中安智联未来有限公司 Compiling method and compiler
US11036907B2 (en) 2019-03-01 2021-06-15 Synopsys, Inc. Automatic testbench generator for test-pattern validation
CN112416313B (en) * 2019-08-23 2022-07-12 无锡江南计算技术研究所 Compiling method supporting large integer data type and operator
CN112579059B (en) * 2019-09-27 2022-10-04 无锡江南计算技术研究所 Compiling method supporting finite field data type and operator
CN110825384A (en) * 2019-10-28 2020-02-21 国电南瑞科技股份有限公司 ST language compiling method, system and compiler based on LLVM
CN110908668A (en) * 2019-11-21 2020-03-24 深圳市新威尔电子有限公司 Compiler for compiling battery test system script program
CN111381817A (en) * 2020-03-25 2020-07-07 北京字节跳动网络技术有限公司 Method, device, medium and electronic equipment for realizing cross-platform multi-language development
CN111488154B (en) * 2020-04-23 2024-01-12 北京东土科技股份有限公司 ST language source code compiling method, device, computer equipment and medium
CN111639501A (en) * 2020-05-04 2020-09-08 国网浙江省电力有限公司 Power grid service micro-service combination method based on AMSL
CN114647413A (en) * 2020-12-17 2022-06-21 华为云计算技术有限公司 Code processing method and related equipment
CN112882408B (en) * 2020-12-31 2022-10-18 深圳市雷赛控制技术有限公司 Online editing method and device for ST text language
CN112835323B (en) * 2020-12-31 2022-05-17 深圳市雷赛控制技术有限公司 Programmable logic control language compiling method and device
CN113360142B (en) * 2021-06-24 2023-07-07 广东工贸职业技术学院 Design and compiling method for numerical control embedded PLC intermediate file

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103123590A (en) * 2011-11-18 2013-05-29 中国科学院沈阳计算技术研究所有限公司 Compiling method from intermediate language (IL) program to C language program of instruction list
CN104239115A (en) * 2014-07-24 2014-12-24 汕头大学 Programming language compiling method of PLC (Programmable Logic Controller)
CN108303948A (en) * 2018-04-16 2018-07-20 深圳市雷赛控制技术有限公司 A kind of execution method and apparatus of the compiled PLC based on motion controller

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8799880B2 (en) * 2011-04-08 2014-08-05 Siemens Aktiengesellschaft Parallelization of PLC programs for operation in multi-processor environments
CN103294666B (en) * 2013-05-28 2017-03-01 百度在线网络技术(北京)有限公司 Grammar compilation method, semantic analytic method and corresponding intrument
CN107943486B (en) * 2017-12-19 2020-12-18 北京微网通联股份有限公司 Multi-language code compiling method, multi-language code distributing method, multi-language code compiling device, multi-language code distributing device and multi-language code system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103123590A (en) * 2011-11-18 2013-05-29 中国科学院沈阳计算技术研究所有限公司 Compiling method from intermediate language (IL) program to C language program of instruction list
CN104239115A (en) * 2014-07-24 2014-12-24 汕头大学 Programming language compiling method of PLC (Programmable Logic Controller)
CN108303948A (en) * 2018-04-16 2018-07-20 深圳市雷赛控制技术有限公司 A kind of execution method and apparatus of the compiled PLC based on motion controller

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
基于Powerlink的网络化交流伺服系统的研究;王丹;《中国优秀硕士学位论文全文数据库信息科技辑》;20141015(第10期);正文第35页 *
基于图像识别的城市燃气SCADA系统技术研究;黄涛;《中国优秀硕士学位论文全文数据库工程科技Ⅱ辑》;20170315(第03期);正文第46页 *
软PLC运行系统的研究;高进;《中国优秀硕士学位论文全文数据库信息科技辑》;20110515(第05期);正文第5-8、12-28页,图2.2、3.4 *
高进.软PLC运行系统的研究.《中国优秀硕士学位论文全文数据库信息科技辑》.2011,(第05期),I140-379. *

Also Published As

Publication number Publication date
CN109254776A (en) 2019-01-22

Similar Documents

Publication Publication Date Title
CN109254776B (en) Multi-language code compiling method and compiler
CN110825384A (en) ST language compiling method, system and compiler based on LLVM
US9122540B2 (en) Transformation of computer programs and eliminating errors
CN110673854A (en) SAS language compiling method, device, equipment and readable storage medium
CN107193745A (en) Automated construction method of the PLC program to NuSMV input models
CN116540986A (en) Method for constructing text programming language code editor based on Web end
CN112835323B (en) Programmable logic control language compiling method and device
US8434071B2 (en) Method for translating a graphical workflow in a textual description
CN110442520B (en) Cross debugging system and method based on PLC programming language
CN110825433B (en) Design method of edge control equipment
CN116501330A (en) Text programming language compiling method based on decoupling architecture
KR20090011974A (en) Method for extracting the target files of compilation
Wang et al. Formal modelling of PLC systems by BIP components
JP2007122187A (en) Program code generation device
EP4196874A1 (en) Representing asynchronous state machine in intermediate code
Cserép et al. Integration of Incremental Build Systems Into Software Comprehension Tools.
GB2420638A (en) Method of substituting code fragments in Internal Representation
Darvas et al. What is special about PLC software model checking
CN111694738A (en) Method for generating SQL test script
Grigorev et al. String-embedded language support in integrated development environment
Veerman Automated mass maintenance of software assets
KR100246544B1 (en) Thread creation method for parallel constructs on high speed parallel computer
Darvas et al. JACoW: What is special about PLC software model checking?
JP2002312167A (en) Program for making computer calculate value of variable, compile program, variable value determining method, and program generating method
Rinko Efficient IEC 61131-3 Structured Text tooling in modern distributed control system

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
GR01 Patent grant
GR01 Patent grant