Language transformation method based on meta-model

Through the meta-model-based language conversion method, the ST language source program is parsed to generate an abstract syntax tree and instantiated the generation model, which solves the cross-platform problem between the PLC development platforms and realizes the efficient portability of the ST program.

CN120068804APending Publication Date: 2025-05-30SHANGHAI FORMAL TECH INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411443369.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-16
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

The existing PLC development platform can only debug and maintain source programs written in the ST language on specific platforms, and cannot be efficiently ported between different platforms.

Method used

The meta-model-based language conversion method is adopted to generate an abstract syntax tree by analyzing the ST language source program, instantiating the generation model, and output the target language text according to the conversion rules to realize cross-platform language conversion.

Benefits of technology

It improves the portability of ST programs and enhances the operability of program development, so that programs written in ST language can run seamlessly on different platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120068804A_ABST
    Figure CN120068804A_ABST
Patent Text Reader

Abstract

The invention discloses a language conversion method based on a meta-model, and belongs to the technical field of language conversion methods, and the conversion method comprises the steps of creating the meta-model, constructing a generation model, compiling a text conversion rule, and generating a target text. The purpose of the present disclosure is to improve the portability of a program. At present, the number of platforms or compilers supporting ST is small, and compilers supporting C + + are richer. And C + + also supports object-oriented support, so that the object-oriented support of ST addition can be mapped.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a language conversion method, in particular to a language conversion method based on a metamodel, and belongs to the technical field of language conversion methods. Background Art

[0002] With the continuous progress of electronic technology, the hardware technology of PLCs is also constantly developing, with higher performance, larger storage capacity, and more input / output (I / O) points, and can handle more complex control tasks; currently, there are many PLC manufacturers and development platforms, and the standard IEC61131-3 issued by the International Electrotechnical Commission stipulates the unified standard for PLC programming languages;

[0003] The ST language has a syntax structure similar to traditional programming languages and has gradually become the mainstream of PLC development. Currently, the PLC development platforms that support the ST language are relatively fixed and can only be debugged and maintained on their respective platforms, or a required runtime must be used. Therefore, a language conversion method based on a metamodel is designed to solve the above problems. Summary of the Invention

[0004] The main purpose of the present invention is to provide a language conversion method based on a metamodel.

[0005] The object of the present invention can be achieved by adopting the following technical solutions:

[0006] A language conversion method based on a metamodel includes the following steps:

[0007] Step 101: Parse the source program written in the ST language to generate an abstract syntax tree;

[0008] Step 102: Instantiate the model based on the abstract syntax tree;

[0009] Step 103: Output the target language text based on the generated model.

[0010] Preferably, step 101 further includes the following steps:

[0011] Step S201: Perform lexical analysis on the source program written in the ST language to convert the input character sequence into character stream units;

[0012] Step S202: Form an abstract syntax tree based on the above character stream units.

[0013] Preferably, in this step S201, according to the lexical analyzer defined by the above grammar rules, read the character sequence in the source program and convert it into identifier, keyword, and operator character stream units.

[0014] Preferably, in this step S202, the parser defined according to the above grammar rules determines whether the character stream unit is a sentence in the source language. If so, an abstract syntax tree composed of the above character stream units is constructed; otherwise, a syntax error is prompted.

[0015] Preferably, before step 101, the following steps are further included:

[0016] Step S401: Traverse the syntax tree, enter the syntax tree node, and recursively visit and continue to enter deeper nodes of the syntax tree. In this process, the custom method enterNode() can be completed;

[0017] Step S402: Traverse the syntax tree and exit the syntax tree node. In this process, the custom method exitNode() can be completed;

[0018] Step S403: After traversing the syntax tree, through the above two custom methods, instantiate and generate the model and perform semantic checking.

[0019] Preferably, step 103 further includes the following steps:

[0020] Step S601: Obtain the top-level generation model;

[0021] Step S602: Through the top-level generation model, access the reference relationship and call other generation models for access;

[0022] Step S603: According to the accessed generation model, output the target text using the corresponding conversion rules.

[0023] Advantageous technical effects of the present invention:

[0024] A language conversion method based on a meta-model provided by the present invention forms ST grammar rules based on the IEC61131-3 standard form specification, defines a meta-model according to the grammar rules, and defines conversion rules according to the meta-model; the meta-model can be used to construct a generation model of the source program, and the conversion rules can convert the generation model into a target language program.

[0025] The present disclosure realizes the language conversion function through the idea of first abstracting and then implementing, which can improve the portability of ST programs and improve the operability of program development by establishing a meta-model.

[0026] In the embodiments of the present disclosure, before constructing a generation model through the source program, the method further includes:

[0027] Identify lexical units from the source language text;

[0028] Establish an abstract syntax tree according to the lexical units;

[0029] Build the generation model based on the abstract syntax tree.

[0030] Traverse each node based on the abstract syntax tree to build a corresponding generation model, and the generation model is a domain class object instantiated based on the meta-model.

[0031] Based on the generation model and combined with transformation rules, output to target code to improve the portability of programs written in ST language. Converting ST to programming languages such as C or C++ that already have multi-platform compilers can well solve the problem. Description of the Drawings

[0032] Figure 1 It is a schematic flowchart of the language conversion method according to a preferred embodiment of the language conversion method based on the meta-model of the present invention.

[0033] Figure 2 It is a schematic diagram of the construction of the syntax tree according to a preferred embodiment of the language conversion method based on the meta-model of the present invention.

[0034] Figure 3 It is according to a preferred embodiment of the language conversion method based on the meta-model of the present invention Figure 2 Supplementary description schematic diagram.

[0035] Figure 4 It is a schematic diagram of the process of traversing the abstract syntax tree to instantiate the generation model according to a preferred embodiment of the language conversion method based on the meta-model of the present invention.

[0036] Figure 5 It is a schematic diagram of the establishment of the domain class according to a preferred embodiment of the language conversion method based on the meta-model of the present invention.

[0037] Figure 6 It is a schematic diagram of the model-to-text conversion process according to a preferred embodiment of the language conversion method based on the meta-model of the present invention. Detailed Embodiments

[0038] To make the technical solutions of the present invention clearer and more definite to those skilled in the art, the present invention will be further described in detail below in conjunction with embodiments and the accompanying drawings, but the embodiments of the present invention are not limited thereto.

[0039] Figure 1 It is a flowchart of an embodiment of the present disclosure. As Figure 1 shown, the process includes the following steps:

[0040] Step S101, parse the source program written in ST language to generate an abstract syntax tree;

[0041] Step S102, instantiate the generation model based on the abstract syntax tree;

[0042] Step S103, output the target language text based on the generation model.

[0043] Figure 2 It is an expansion description of step S101. Before steps S201 - S202, grammar rules need to be written according to the form specifications in the IEC61131 - 3 standard. Figure 2 The process includes the following steps:

[0044] Step S201, perform lexical analysis on the source program written in ST language, and convert the input character sequence into character stream units (tokens). In this step, according to the lexical analyzer defined by the above grammar rules, read the character sequence in the source program and convert it into character stream units such as identifiers, keywords, and operators.

[0045] Step S202, form an abstract syntax tree based on the above character stream units. In this step, according to the syntax analyzer defined by the above grammar rules, determine whether the character stream unit is a sentence in the source language. If so, construct an abstract syntax tree composed of the above character stream units; otherwise, prompt a syntax error.

[0046] Figure 3 Used to illustrate Figure 2 the progress of Figure 3 It is a schematic diagram of the process of constructing a syntax tree for a piece of source code based on grammar rules. The source text is an assignment statement, and the character sequence of the assignment statement can be decomposed by the lexical analyzer into four parts: variable, assignment operator, expression, and semicolon; the expression can be further decomposed into units such as operands and operators; then use independent character stream units to form an abstract syntax tree.

[0047] Figure 4 It is an expansion description of step S102. Before this step, the model establishment process shown in Figure 5 also needs to be completed. Figure 4 The process in the flow includes the following steps:

[0048] Step S401, traverse the syntax tree, enter the syntax tree node, and recursively visit and continue to enter deeper nodes of the syntax tree. In this process, the custom method enterNode() can be completed;

[0049] Step S402, traverse the syntax tree and exit the syntax tree node. In this process, the custom method exitNode() can be completed;

[0050] Step S403, after traversing the syntax tree, through the above two custom methods, complete the instantiation of the generation model and semantic check.

[0051] Figure 5It is a schematic diagram of the construction of domain classes. Each square in the figure represents a domain class, and a domain class can contain attributes, references, and methods; a class can inherit from other classes; in the present disclosure, the reference relationship is more important in the domain. Through the reference relationship, related elements can be quickly located, which cannot be achieved by an abstract syntax tree; this advantage is helpful for semantic analysis and debugging functions. These meta-model domain classes can be instantiated through code. By putting the instantiated code into the enterNode() and exitNode() methods and adding semantic analysis methods created based on the reference relationship, the generation model construction and semantic check of the abstract syntax tree can be completed in step S403.

[0052] Figure 6 It is an expanded description of step S103. This process includes the following steps:

[0053] Step S601, obtain the top-level generation model;

[0054] Step S602, through the top-level generation model, access the reference relationship and call other generation models for access;

[0055] Step S603, according to the accessed generation model, output the target text using the corresponding conversion rules.

[0056] As mentioned above, it is only a preferred specific implementation manner of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed by the present disclosure should be covered by the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.

[0057] As mentioned above, it is only a further embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any equivalent substitution or change made by those skilled in the art within the scope disclosed by the present invention according to the technical solution and concept of the present invention belongs to the protection scope of the present invention.

Claims

1. A language conversion method based on a metamodel, characterized in that: The steps include: Step 101: Parse the source program written in ST language to generate an abstract syntax tree; Step 102: instantiating a generation model based on the abstract syntax tree; Step 103: Outputting target language text based on the generation model.

2. The metamodel-based language conversion method according to claim 1, characterized in that: Step 101 also includes the following steps: Step S201: Perform lexical analysis based on the source program written in ST language, and convert the input character sequence into a character stream unit; Step S202: An abstract syntax tree is formed based on the above character stream units.

3. The metamodel-based language conversion method according to claim 2, characterized in that: In this step S201, the lexical analyzer defined according to the above grammatical rules reads the character sequence in the source program and converts it into identifier, keyword, and operator character stream units.

4. The metamodel-based language conversion method according to claim 2, characterized in that: In step S202, the grammar analyzer defined according to the grammar rules determines whether the character stream unit is a sentence of the source language. If so, an abstract syntax tree consisting of the character stream unit is constructed. Otherwise, a grammar error is prompted.

5. The metamodel-based language conversion method according to claim 4, characterized in that: Before step 101, the following steps are also included: Step S401: traverse the syntax tree, enter the syntax tree node, and recursively access to continue entering deeper nodes in the syntax tree. In this process, a custom method enterNode() can be completed; Step S402: traverse the syntax tree and exit the syntax tree node. In this process, a custom method exitNode() may be implemented. Step S403: After traversing the syntax tree, the instantiation generation model and semantic checking are completed through the above two custom methods.

6. The metamodel-based language conversion method according to claim 5, characterized in that: Step 103 also includes the following steps: Step S601: Obtain the top-level generative model; Step S602: Access reference relationships through the top-level generation model and call other generation models for access; Step S603: Outputting the target text using corresponding conversion rules according to the accessed generation model.