Expression analysis method, system, working machine, and electronic device

CN117111956BActive Publication Date: 2026-09-18SHANGHAI HUAXING DIGITAL TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311121830.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-31
Publication Date
2026-09-18
Estimated Expiration
2043-08-31

AI Technical Summary

Technical Problem

[0004]本发明提供一种表达式解析方法、系统、作业机械及电子设备,用以解决因现有的组件式开发对于纯运算类处理功能开发并不友好,所造成的影响开发效率和客户主观满意度的缺陷

Benefits of technology

[0039] This invention provides an expression parsing method, system, operating machinery, and electronic equipment. The parsing method is applied to the assembly program source file of the LM function block based on the IEC61499 standard. It obtains the assembly program source file; parses the assembly program source file based on predefined lexical and grammatical rules of operational expressions; generates an abstract syntax tree representing the structure of the expressions in the assembly program source file based on the information obtained from the parsing, with the abstract syntax tree using expressions as nodes; traverses the abstract syntax tree to generate an intermediate file of the assembly program source file; and parses the intermediate file to generate a target file independent of the assembly program source file and the target platform. This optimizes the programming of operational classes in the LM function block by adding lexical and grammatical support to the existing compiler, automatically converting operational expressions into operational class components based on predefined lexical and grammatical rules of operational expressions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117111956B_ABST
    Figure CN117111956B_ABST
Patent Text Reader

Abstract

The application provides an expression analysis method, system, working machine and electronic equipment, and belongs to the technical field of language compilation, wherein the method is applied to an assembly program source file of an LM function block based on the IEC61499 standard, and comprises the following steps: obtaining the assembly program source file; analyzing the assembly program source file based on the lexical and syntactic rules of a predefined operation expression; generating an abstract syntax tree representing the structure of an expression in the assembly program source file based on the information of the analyzed assembly program source file, wherein the abstract syntax tree takes the expression as a node; traversing the abstract syntax tree to generate an intermediate file of the assembly program source file; and analyzing the intermediate file to generate a target file independent of the assembly program source file and a target platform. The application is used to solve the defects of influencing the development efficiency and customer subjective satisfaction caused by the fact that the existing component-based development is not friendly to the development of pure operation type processing functions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of language compilation technology, and in particular to an expression parsing method, system, operating machinery, and electronic equipment. Background Technology

[0002] IEC 61499 is an international standard for function blocks used in distributed industrial process measurement and control systems (IPMCS). LM software uses a linguistic model, hence the abbreviation LM. LM function blocks, also known as MMB (MicroMessage Bus) function blocks, are function blocks developed based on IEC 61499 for building control systems. They adopt a modular assembly concept and method, using predefined "modules" to specify the algorithm details and specific descriptions of "how to do it," allowing end users to simply specify "what to do" during module assembly. Function blocks can be assembled like building blocks, making program development flexible.

[0003] However, this component-based development approach is not ideal for developing purely computational processing functions, impacting development efficiency and customer satisfaction. Summary of the Invention

[0004] This invention provides an expression parsing method, system, operating machinery, and electronic equipment to address the shortcomings of existing component-based development, which is not friendly to the development of pure computational processing functions, thus affecting development efficiency and customer satisfaction.

[0005] This invention provides an expression parsing method applied to the assembly program source file of LM function blocks based on the IEC61499 standard, including:

[0006] Obtain the assembly program source file;

[0007] The assembly program source file is parsed based on the lexical and syntactic rules of predefined operational expressions;

[0008] Based on the information obtained from the parsed assembly program source file, an abstract syntax tree is generated representing the structure of the expressions in the assembly program source file, with the expressions as nodes in the abstract syntax tree;

[0009] The abstract syntax tree is traversed to generate intermediate files of the assembly program source file;

[0010] The intermediate file is parsed to generate a target file that is independent of the assembly program source file and the target platform.

[0011] According to the expression parsing method of the present invention, the lexical and grammatical rules include: reserved keywords, definitions of operators, and definitions of the precedence of each of the operators.

[0012] According to the expression parsing method of the present invention, after obtaining the assembly program source file, the method further includes:

[0013] The assembly program source file is parsed based on predefined type conversion syntax rules.

[0014] The forced type conversion syntax rules include: defining the data types of variables in the assembly program source file, defining the forced conversion types for conversions between different types in the assembly program source file, and adding data type specification suffixes to constants in the assembly program source file.

[0015] According to the expression parsing method of the present invention, before traversing the abstract syntax tree to generate the intermediate file of the assembly program source file, the method further includes:

[0016] The abstract syntax tree is traversed to determine whether the data types of the operands of the expression are consistent;

[0017] If they are inconsistent, and the operands are not marked with a conversion identifier corresponding to the type of the forced conversion, an expression parsing error will be indicated.

[0018] According to the expression parsing method of the present invention, before traversing the abstract syntax tree to generate the intermediate file of the assembly program source file, the method further includes:

[0019] For the first expression in the expression, determine whether the format of the first expression is a preset format. The first expression is an operation expression in which the operator is a binary operator and one of the operands is a constant. The preset format is first operand - binary operator - second operand, where the first operand is a variable and the second operand is a constant.

[0020] When the format is not the preset format and the binary operator supports commutativity, the positions of the first operand and the second operand in the first expression are swapped;

[0021] When the format is not the preset format and the binary operator does not support the commutative law, a variable of the same type as the first operand is defined, and the value of the constant is assigned to the defined variable.

[0022] According to the expression parsing method of the present invention, before traversing the abstract syntax tree to generate the intermediate file of the assembly program source file, the method further includes:

[0023] For the second expression in the expression, define a variable of the same data type and assign it a constant value, replacing the operands that are constants in the second expression. The second expression is an arithmetic expression that includes operators other than the binary operator and whose operands include constants.

[0024] According to the expression parsing method of the present invention, before traversing the abstract syntax tree to generate the intermediate file of the assembly program source file, the method further includes:

[0025] The abstract syntax tree is traversed, and the operational expressions in the expression are optimized;

[0026] The optimizations include:

[0027] Merge consecutive constant assignment operations of the same data type in the operation expression and use a single assignment component.

[0028] The operation expressions containing consecutive variables of the same data type are merged and processed using a single transmission component of the same type.

[0029] The operation expressions involving consecutive variables of different data types are merged using a single heterogeneous transfer component.

[0030] If the operators included in the operational expression have decreasing precedence from left to right and are of the same type, they are merged.

[0031] This invention also provides an expression parsing system applied to the assembly program source file of LM function blocks based on the IEC61499 standard, comprising:

[0032] The acquisition module is used to acquire the assembly program source file;

[0033] The parsing module is used to parse the assembly program source file based on predefined lexical and grammatical rules of operational expressions;

[0034] The first generation module is used to generate an abstract syntax tree representing the structure of expressions in the assembly program source file based on the information obtained from the parsing, wherein the abstract syntax tree uses the expressions as nodes;

[0035] The second generation module is used to traverse the abstract syntax tree and generate intermediate files of the assembly program source file;

[0036] The third generation module is used to parse the intermediate files and generate target files that are independent of the assembly program source files and the target platform.

[0037] The present invention also provides a working machine that employs a control system based on LM function blocks, wherein the assembly program source file of the LM function blocks is parsed using the expression parsing method or expression parsing system described above.

[0038] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the expression parsing method described above.

[0039] This invention provides an expression parsing method, system, operating machinery, and electronic equipment. The parsing method is applied to the assembly program source file of the LM function block based on the IEC61499 standard. It obtains the assembly program source file; parses the assembly program source file based on predefined lexical and grammatical rules of operational expressions; generates an abstract syntax tree representing the structure of the expressions in the assembly program source file based on the information obtained from the parsing, with the abstract syntax tree using expressions as nodes; traverses the abstract syntax tree to generate an intermediate file of the assembly program source file; and parses the intermediate file to generate a target file independent of the assembly program source file and the target platform. This optimizes the programming of operational classes in the LM function block by adding lexical and grammatical support to the existing compiler, automatically converting operational expressions into operational class components based on predefined lexical and grammatical rules of operational expressions. Attached Figure Description

[0040] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0041] Figure 1 This is a flowchart illustrating an expression parsing method provided in an embodiment of the present invention;

[0042] Figure 2 This is a flowchart illustrating the process of compiling the assembly program of the LM function block using the expression parsing method provided in the embodiments of the present invention;

[0043] Figure 3 This is a schematic diagram of the structure of an expression parsing system provided in an embodiment of the present invention;

[0044] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation

[0045] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0046] First, to facilitate understanding of the technical solution of the present invention, the terms involved in the embodiments will be explained.

[0047] LM function blocks: These are function blocks developed based on the IEC61499 standard, also known as MMB function blocks. They are predefined modules, meaning that the modules specify the algorithm details and the specific description of "how to do it". Therefore, when assembling modules, users only need to specify "what to do" to assemble function blocks like building blocks, making program development flexible.

[0048] Understandably, this component-based development approach, which uses LM function blocks to build control systems, is not ideal for developing purely computational processing functions, impacting development efficiency and customer satisfaction.

[0049] Based on this, the expression parsing method provided in this embodiment of the invention, by adding lexical and syntactic support for operational expressions on the basis of the original compiler, automatically converts operational expressions into operational class components of LM function blocks according to predefined lexical and syntactic rules such as data type and operation priority, thereby optimizing operational class programming.

[0050] The expression parsing method provided by this invention can be executed by software and / or hardware in electronic devices such as computers, tablets, and mobile phones.

[0051] The following is combined with Figures 1 to 4 This invention describes the expression parsing method, system, machinery, and electronic equipment of the present invention.

[0052] This embodiment provides an expression parsing method based on the assembly program source file of the LM function block of the IEC61499 standard, such as... Figure 1 As shown, the parsing method includes at least the following steps:

[0053] 101. Obtain the assembly program source file;

[0054] Specifically, the assembly program source file for the LM function block is generally a .inva or .ginva file.

[0055] 102. Based on predefined lexical and syntactic rules of operational expressions, parse the assembly program source file;

[0056] In a specific embodiment, the lexical and syntactic rules for the operation expressions of the assembly program source file can be defined based on Flex / Bison, antlr4, etc.

[0057] Based on the above embodiments, the lexical and syntactic rules of the predefined operational expressions include: reserved keywords, definitions of operators, and definitions of the precedence of each operator.

[0058] Understandably, the defined operators and their corresponding precedence need to cover all the operational functions supported by the existing LM function block's operational class components, thereby ensuring comprehensive parsing of the operational expressions in the assembly program source file.

[0059] Specifically, by parsing the assembly program source file according to predefined lexical and syntactic rules, the component assembly information and expression information of the LM function block can be obtained. The component assembly information includes, for example, the program component assembly instance name, input parameters, and output parameters. The expression information includes, for example, the type of each expression in the assembly program source file, the operator, the operator's priority, the operands, the operand types, the operand data types, the position information in the source program, and the type casting information.

[0060] 103. Based on the information obtained from the parsed assembly program source file, generate an abstract syntax tree representing the structure of the expressions in the assembly program source file, with the abstract syntax tree using expressions as nodes;

[0061] 104. Traverse the abstract syntax tree to generate intermediate files for the assembly program source file;

[0062] Specifically, the intermediate files of the assembler source files corresponding to the .inva / .ginva files are generated by traversing the abstract syntax tree, and are called .invac / .ginvac files.

[0063] More specifically, in order to avoid modifying other parts of the original language system of the LM function block, non-expression programs should be kept consistent with the original program files of the LM function block.

[0064] 105. Parse intermediate files to generate target files that are independent of the assembly program source files and the target platform.

[0065] Specifically, the generated target file is usually a .code file.

[0066] In this embodiment, the assembly program source file of the LM function block is parsed based on the lexical and grammatical rules of predefined operational expressions. Then, based on the information of the parsed assembly program source file, an abstract syntax tree with expressions as nodes is generated, representing the structure of the expressions in the assembly program source file. After traversing the abstract syntax tree, an intermediate file of the assembly program source file is generated. This allows the intermediate file to be parsed and an object file independent of the assembly program source file and the target platform to be generated. This enables the underlying parser to use the object file independently without knowing the assembly program source file associated with the object file or the target platform on which it was generated.

[0067] In this embodiment, by predefined lexical and syntactic rules of operational expressions, the data types and operational precedence of operands in the operational expressions are automatically converted into operational class components of LM function blocks, and the target file is compiled and generated. That is, by only adding support for the syntax of operational expressions, the structure of the generated target file is not changed, and it is compatible with the original language program of LM function blocks. This means that the underlying parser and other parts of the original LM function block language system do not need to be modified, thereby optimizing the programming of operational classes.

[0068] Based on the above embodiments, after obtaining the assembly program source file, the method further includes:

[0069] Parse the assembly program source file based on predefined type casting syntax rules;

[0070] The syntax rules for forced type conversion include: defining the data types of variables in the assembly program source file, defining the forced type conversion between different types in the assembly program source file, and adding data type declaration suffixes to constants in the assembly program source file.

[0071] In this embodiment, by adding predefined forced type conversion syntax rules, that is, when parsing the assembly program source file, the data type of the variable is clarified based on the definition of the data type of the variable in the assembly program source file, and the forced conversion type between different data types is clarified based on the definition of the forced conversion type between different types in the assembly program source file, and a data type specification suffix is ​​added to constants, thereby effectively improving the security of the program.

[0072] In one specific embodiment, the data type specification suffix added to the constant can be: 32-bit unsigned integer 12LU, etc.

[0073] Based on the above embodiments, before traversing the abstract syntax tree to generate intermediate files for the assembly program source files, the following steps are also included:

[0074] The abstract syntax tree is traversed to determine whether the data types of the operands of the expression are consistent;

[0075] If they are inconsistent, and the operands are not marked with a conversion identifier corresponding to the type of the type cast, an expression parsing error will be indicated.

[0076] In this embodiment, the abstract syntax tree is traversed before generating the intermediate file of the assembly program source file to determine whether the data types of the operands of the expression are consistent. If the data types of the operands are inconsistent, it is further determined whether the operands are marked with a conversion identifier corresponding to the type of forced conversion. If no conversion identifier is found, an expression parsing error is prompted, thereby further improving the security of the program.

[0077] Based on the above embodiments, before traversing the abstract syntax tree to generate intermediate files for the assembly program source files, the following steps are also included:

[0078] For the first expression in the expression, determine whether the format of the first expression is a preset format. The first expression is an arithmetic expression in which the operator is a binary operator and one of the operands is a constant. The preset format is first operand - binary operator - second operand, where the first operand is a variable and the second operand is a constant.

[0079] If the format is not the default format and the binary operator supports commutativity, swap the positions of the first and second operands in the first expression;

[0080] When the format is not the default format and the binary operator does not support commutativity, define a variable of the same type as the first operand and assign the value of the constant to the defined variable.

[0081] Understandably, the operational components of the LM function block have strict requirements on the assembly method of operations, such as the data type of the operands and the position of the operands. Therefore, when parsing an expression, the corresponding operational components need to be adjusted according to the operators.

[0082] In this embodiment, by ensuring that the expression contains binary operators and one operand is a constant, the format of the expression is operand (variable)-operator-operandron (constant), thus making the expression containing binary operators conform to the requirements of the LM function block's operation component for operation assembly. Specifically, when the format of the first expression is not a preset format, it is determined whether the operator supports commutativity. If it does, the operands are swapped; otherwise, a variable of the same data type is defined, and the value of the constant is assigned to the variable, thereby converting the first expression into the format operand (variable)-operator-operandron (variable).

[0083] Based on the above embodiments, before traversing the abstract syntax tree to generate intermediate files for the assembly program source files, the following steps are also included:

[0084] For the second expression in the expression, define a variable of the same data type and assign it a constant value, replacing the operands that are constants in the second expression. The second expression is an arithmetic expression that includes operators other than binary operators and whose operands include constants.

[0085] It is understandable that some computational components of the LM function block do not support constant operations.

[0086] Based on this, in this embodiment, when the operand is a constant, by defining a variable of the same data type and assigning it a constant value to replace the constant operand, the requirements of the LM function block's computational components for the computational assembly method can be met.

[0087] Based on the above embodiments, before traversing the abstract syntax tree to generate intermediate files for the assembly program source files, the following steps are also included:

[0088] The abstract syntax tree is traversed, and the operational expressions in the expressions are optimized.

[0089] The optimizations include:

[0090] Merge consecutive constant assignment operations of the same data type in an operation expression and use a single assignment component.

[0091] Merge consecutive variables of the same data type in an arithmetic expression by using a single transfer component of the same type.

[0092] Merge consecutive variables of different data types in an arithmetic expression by using a heterogeneous transfer component;

[0093] If the operators in an expression have decreasing precedence from left to right and are of the same type, they are merged.

[0094] In this embodiment, assignment operations of consecutive constants of the same data type in the operation expression are merged using a single assignment component; transfer operations between consecutive variables of the same data type are merged using a single transfer component of the same type; and transfer operations between consecutive variables of different data types are merged using a single transfer component of different types. Furthermore, when the operators included in the operation expression satisfy a decreasing order from left to right and the operation types are consistent, they are merged, i.e., processed using a single operation component. This achieves optimization of the operation expression based on the assembly program of the LM function block and the usage characteristics of operation components, thereby improving the efficiency of the LM function block assembly program.

[0095] Figure 2This describes the specific process of compiling the assembly program for the LM function block using the expression parsing method provided in the above embodiments of the present invention. Figure 2 As shown, the main steps include:

[0096] 201. Define the lexical and syntactic rules and the syntax rules for type casting in arithmetic expressions;

[0097] 202. Obtain the assembly program source file for the LM function block;

[0098] 203. Obtain the component assembly information and expression information of the LM function block, and generate an abstract syntax tree;

[0099] 204. Check the consistency of the data types of the operands in the expression;

[0100] 205. Optimize the calculation expressions based on the assembly procedure of the LM function block and the usage characteristics of the calculation components;

[0101] 206. Generate intermediate files for the assembly program source file;

[0102] 207. Generate the target file.

[0103] Based on the same general inventive concept, this invention also protects an expression parsing system. The expression parsing system provided by this invention will be described below, and the expression parsing system described below can be referred to in correspondence with the expression parsing method described above.

[0104] Figure 3 This is a schematic diagram of the expression parsing system provided by the present invention. The system is applied to the assembly program source file of LM function blocks based on the IEC61499 standard, such as... Figure 3 As shown, the system includes: an acquisition module 310, a parsing module 320, a first generation module 330, a second generation module 340, and a third generation module 350; wherein,

[0105] Module 310 is used to acquire assembly program source files;

[0106] The parsing module 320 is used to parse the assembly program source file based on the lexical and grammatical rules of predefined operational expressions;

[0107] The first generation module 330 is used to generate an abstract syntax tree representing the structure of expressions in the assembly program source file based on the information obtained from the parsing. The abstract syntax tree uses expressions as nodes.

[0108] The second generation module 340 is used to traverse the abstract syntax tree and generate intermediate files for the assembly program source file;

[0109] The third generation module 350 is used to parse intermediate files and generate target files that are independent of the assembly program source files and the target platform.

[0110] The expression parsing system provided in this invention is applied to the assembly program source file of the LM function block based on the IEC61499 standard. It obtains the assembly program source file; parses the source file based on predefined lexical and syntactic rules of operational expressions; generates an abstract syntax tree representing the structure of the expressions in the source file based on the parsed information, with expressions as nodes; traverses the abstract syntax tree to generate an intermediate file of the assembly program source file; and parses the intermediate file to generate a target file independent of the assembly program source file and the target platform. Thus, by adding lexical and syntactic support for operational expressions to the existing compiler, the system automatically converts operational expressions into operational class components of the LM function block based on predefined lexical and syntactic rules, thereby optimizing the operational class programming in the LM function block.

[0111] Optionally, lexical and grammatical rules include: reserved keywords, definitions of operators, and definitions of the precedence of each operator.

[0112] Optionally, the parsing module 320 is also used for:

[0113] The assembly program source file is parsed based on predefined type casting syntax rules. These rules include: defining the data types of variables in the assembly program source file, defining the type casting rules for conversions between different types in the assembly program source file, and adding data type declaration suffixes to constants in the assembly program source file.

[0114] Optionally, it may also include: a detection module;

[0115] The detection module is used to: traverse the abstract syntax tree to determine whether the data types of the operands of the expression are consistent; if they are inconsistent, and the operands are not marked with the conversion identifier corresponding to the type cast, an expression parsing error is indicated.

[0116] Optionally, it also includes: an optimization module;

[0117] The optimization module is used to: for the first expression in an expression, determine whether the format of the first expression is a preset format. The first expression is an arithmetic expression with a binary operator and one operand being a constant. The preset format is first operand - binary operator - second operand, where the first operand is a variable and the second operand is a constant. If the format is not the preset format and the binary operator supports commutativity, swap the positions of the first and second operands in the first expression. If the format is not the preset format and the binary operator does not support commutativity, define a variable of the same type as the first operand and assign the value of the constant to the defined variable.

[0118] Optionally, the optimization module is also used to: for the second expression in the expression, define a variable of the same data type and assign it a constant value, and replace the operands that are constants in the second expression, wherein the second expression is an expression that includes operators other than binary operators and whose operands include constants.

[0119] Optionally, the optimization module is also used to: traverse the abstract syntax tree and optimize the operational expressions in the expression; wherein the optimization includes: merging consecutive constant assignment operations of the same data type in the operational expression and using a single assignment component; merging consecutive variable transfer operations of the same data type in the operational expression and using a single transfer component of the same type; merging consecutive variable transfer operations of different data types in the operational expression and using a single transfer component of different types; if the operators included in the operational expression have precedence that decreases from left to right and the operation types are consistent, then they are merged.

[0120] Based on the same general inventive concept, this invention also protects a working machine that employs a control system built on LM function blocks, wherein the assembly program source file of the LM function blocks is parsed using the expression parsing method or expression parsing system provided in any of the above embodiments.

[0121] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4As shown, the electronic device may include a processor 410, a communications interface 420, a memory 430, and a communication bus 440. The processor 410, communications interface 420, and memory 430 communicate with each other via the communication bus 440. The processor 410 can call logical instructions in the memory 430 to execute an expression parsing method. This method is applied to an assembly program source file based on the LM function block of the IEC 61499 standard, and includes: obtaining the assembly program source file; parsing the assembly program source file based on predefined lexical and grammatical rules of operational expressions; generating an abstract syntax tree representing the structure of expressions in the assembly program source file based on the information obtained from the parsed assembly program source file, with expressions as nodes; traversing the abstract syntax tree to generate an intermediate file of the assembly program source file; and parsing the intermediate file to generate a target file independent of the assembly program source file and the target platform.

[0122] Furthermore, the logical instructions in the aforementioned memory 430 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0123] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can execute the expression parsing method provided by the above methods. This method is applied to an assembly program source file based on the LM function block of the IEC61499 standard, and includes: obtaining the assembly program source file; parsing the assembly program source file based on predefined lexical and grammatical rules of operational expressions; generating an abstract syntax tree representing the structure of expressions in the assembly program source file based on the information obtained from the parsed assembly program source file, wherein the abstract syntax tree is with expressions as nodes; traversing the abstract syntax tree to generate an intermediate file of the assembly program source file; and parsing the intermediate file to generate a target file independent of the assembly program source file and the target platform.

[0124] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the expression parsing methods provided by the above methods. This method is applied to an assembly program source file based on an LM function block of the IEC 61499 standard, and includes: obtaining the assembly program source file; parsing the assembly program source file based on predefined lexical and grammatical rules of operational expressions; generating an abstract syntax tree representing the structure of expressions in the assembly program source file based on the information obtained from the parsed assembly program source file, wherein the abstract syntax tree is with expressions as nodes; traversing the abstract syntax tree to generate an intermediate file of the assembly program source file; and parsing the intermediate file to generate a target file independent of the assembly program source file and the target platform.

[0125] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0126] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0127] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. An expression parsing method applied to an assembly program source file of an LM function block based on the IEC61499 standard, characterized by, include: Obtain the assembly program source file; The assembly program source file is parsed based on the lexical and syntactic rules of predefined operational expressions; Based on the information obtained from the parsed assembly program source file, an abstract syntax tree is generated representing the structure of the expressions in the assembly program source file, with the expressions as nodes in the abstract syntax tree; The abstract syntax tree is traversed to generate intermediate files of the assembly program source file; Before traversing the abstract syntax tree to generate the intermediate file of the assembly program source file, the method further includes: For the first expression in the expression, determine whether the format of the first expression is a preset format. The first expression is an operation expression in which the operator is a binary operator and one of the operands is a constant. The preset format is first operand - binary operator - second operand, where the first operand is a variable and the second operand is a constant. When the format is not the preset format and the binary operator supports commutativity, the positions of the first operand and the second operand in the first expression are swapped; When the format is not the preset format and the binary operator does not support the commutative law, a variable of the same type as the first operand is defined, and the value of the constant is assigned to the defined variable; For the second expression in the expression, define a variable of the same data type and assign it a constant value, replacing the operands that are constants in the second expression. The second expression is an arithmetic expression that includes operators other than the binary operator and whose operands include constants. The intermediate file is parsed to generate a target file that is independent of the assembly program source file and the target platform.

2. The expression parsing method according to claim 1, characterized by, The lexical and grammatical rules include: reserved keywords, definitions of operators, and definitions of the precedence of each of the operators.

3. The expression parsing method of claim 1, wherein, After obtaining the assembly program source file, the process further includes: The assembly program source file is parsed based on predefined type conversion syntax rules. The forced type conversion syntax rules include: defining the data types of variables in the assembly program source file, defining the forced conversion types for conversions between different types in the assembly program source file, and adding data type specification suffixes to constants in the assembly program source file.

4. The expression parsing method according to claim 3, characterized by, Before traversing the abstract syntax tree to generate the intermediate file of the assembly program source file, the method further includes: The abstract syntax tree is traversed to determine whether the data types of the operands of the expression are consistent; If they are inconsistent, and the operands are not marked with a conversion identifier corresponding to the type of the forced conversion, an expression parsing error will be indicated.

5. The expression parsing method according to claim 3, characterized by, Before traversing the abstract syntax tree to generate the intermediate file of the assembly program source file, the method further includes: The abstract syntax tree is traversed, and the operational expressions in the expression are optimized; The optimizations include: Merge consecutive constant assignment operations of the same data type in the operation expression and use a single assignment component. The operation expressions containing consecutive variables of the same data type are merged and processed using a single transmission component of the same type. The operation expressions involving consecutive variables of different data types are merged using a single heterogeneous transfer component. If the operators included in the operational expression have decreasing precedence from left to right and are of the same type, they are merged.

6. An expression parsing system applied to the expression parsing method as described in any one of claims 1 to 5, applied to the assembly program source file of an LM function block based on the IEC 61499 standard, characterized in that, include: The acquisition module is used to acquire the assembly program source file; The parsing module is used to parse the assembly program source file based on predefined lexical and grammatical rules of operational expressions; The first generation module is used to generate an abstract syntax tree representing the structure of expressions in the assembly program source file based on the information obtained from the parsing, wherein the abstract syntax tree uses the expressions as nodes; The second generation module is used to traverse the abstract syntax tree and generate intermediate files of the assembly program source file; The third generation module is used to parse the intermediate files and generate target files that are independent of the assembly program source files and the target platform.

7. A type of operating machinery, employing a control system based on LM function blocks, characterized in that, The assembly program source file of the LM function block is parsed using the expression parsing method as described in any one of claims 1 to 5 or the expression parsing system as described in claim 6.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the expression parsing method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Software source code language translation system and method

    CN104391730A

  • LLVM-based ST language compiling method and system and compiler

    CN110825384A