A Synchronous Dataflow Language Conversion Method for Extended Conditional Blocks
The method extends Lustre's condition blocks to support multiple branches, simplifying conversions and enabling graphical modeling, addressing the complexity of Lustre's limited branch support in embedded systems.
Patent Information
- Application Number
- CN202311577794.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-23
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2043-11-23
AI Technical Summary
When the prior art converts the synchronous data streaming language Lustre into the C language used by embedded devices, there is a problem that conditional branches are complex and unintuitive, especially that multiple conditional branches require multiple if nesting, resulting in high conversion complexity.
A synchronous data stream language conversion method for extended condition blocks is proposed. By obtaining the target extended condition blocks, checking and parsing the target, generating an abstract syntax tree, and converting it into synchronous data stream language code, supporting two or more condition branches, adopting the form of if condition blocks and match condition blocks, providing graphical representation methods to simplify modeling.
It implements a clear and intuitive description of conditional control flow, supports conversion of multiple conditional branches, is compatible with existing Lustre to C code generators, simplifies the conversion process and provides graphical modeling tools.
Smart Images

Figure CN117454848B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of nuclear power plant instrument control software, and particularly relates to a method for converting synchronous data flow language with extended conditional blocks. Background Art
[0002] The synchronous data flow language Lustre is widely used in software development in safety-critical fields such as nuclear power. It can describe a system graphically and has a strict formal definition, and is usually used for graphical algorithm modeling. In actual engineering, software usually runs on embedded devices, and the Lustre language needs to be converted into a lower-level language, such as the C language commonly used in nuclear power equipment. The characteristics of the Lustre language and the C language are very different. For example, for the implementation of conditional branches, the C language has the if-else statement to support two conditional branches, and the switch-case statement to support multiple conditional branches. While the Lustre language uses expressions and clocks and adopts the form of if...then...else..., only supporting two conditional branches. Similar to the switch-case statement in the C language, it can only be implemented in the form of nested ifs. The more conditional branch cases there are, the more nested ifs are used, and the more complex and unintuitive it is to implement. Summary of the Invention
[0003] The purpose of the present invention is to provide a method for converting synchronous data flow language with extended conditional blocks, which solves the problem of complex conversion existing in the prior art when running on embedded devices.
[0004] The present invention is achieved by the following technical solutions:
[0005] A method for converting synchronous data flow language with extended conditional blocks includes:
[0006] Obtain a target extended conditional block; the target extended conditional block is used to represent the conditional block to be converted into synchronous data flow language.
[0007] Verify the target extended conditional block and obtain a verification result; the verification result includes passing the verification or failing the verification.
[0008] When the verification result is passing the verification, then parse the target extended conditional block to generate a first abstract syntax tree including the syntax structure of the target extended conditional block.
[0009] Convert the first abstract syntax tree into a second abstract syntax tree with the syntax structure of synchronous data flow language, and generate synchronous data flow language code with the second abstract syntax tree to complete the conversion of synchronous data flow language.
[0010] In a possible implementation, the target extended condition block is an extended condition block input by human-machine interaction or an extended condition block pre-stored in a database;
[0011] The syntax structure of the extended condition block includes a condition block name declaration, a condition block type definition, and a condition block return value declaration;
[0012] The condition block name declaration is set as a unique identifier;
[0013] The condition block type definition includes an if condition block and a match condition block;
[0014] The condition block return value declaration defines the return value of the condition block as the output of the condition block.
[0015] In a possible implementation, the form of the if condition block is set as: if conditional expression then the first conditional branch else the first conditional branch; where the type of the conditional expression is set as bool, and the first conditional branch is set as a custom statement or an if nest;
[0016] The form of the match condition block is set as: match enumeration expression with the second conditional branch; where the enumeration expression represents a defined enumeration type, and the form of the second conditional branch is: enumeration variable: custom statement.
[0017] In a possible implementation, validating the target extended condition block and obtaining a validation result includes:
[0018] Checking whether there is a syntax error in the target extended condition block. If so, determining that the validation result is failed and ending the conversion process; otherwise, determining that the validation result is passed.
[0019] In a possible implementation, when the validation result is passed, parsing the target extended condition block to generate a first abstract syntax tree including the syntax structure of the target extended condition block, including:
[0020] When the validation result is passed, parsing the target extended condition block to obtain the if condition block and the match condition block in the target extended condition block;
[0021] Performing a first conversion on the if condition block and a second conversion on the match condition block to convert the target extended condition block into a first abstract syntax tree.
[0022] In a possible implementation, performing a first conversion on the if condition block includes:
[0023] Determine the output parameters of the if conditional block, and use the output parameters of the if conditional block as the left value of the equation in the first abstract syntax tree; the number of output parameters of the if conditional block is the same as the number of equations;
[0024] Assign the value of the conditional variable in the if conditional block to the value of the conditional variable in the first abstract syntax tree;
[0025] Obtain the values of the output parameters in the then_equation_list of the if conditional block, and assign the values of the output parameters in the then_equation_list to the then_expr whose left value of the equation in the first abstract syntax tree is the corresponding output parameter;
[0026] Obtain the values of the output parameters in the else_equation_list of the if conditional block, and assign the values of the output parameters in the else_equation_list to the else_expr whose left value of the equation in the first abstract syntax tree is the corresponding output parameter;
[0027] For the then_expr and else_expr in the first abstract syntax tree that have not been assigned values, take the default values in the node variable declaration.
[0028] In a possible implementation, perform a second conversion on the match conditional block, including:
[0029] Parse the number of branches in the match conditional block, and based on the number of branches in the match conditional block, convert the match conditional block into at least one if conditional block;
[0030] On the basis of the existing first abstract syntax tree, perform the first conversion on the converted if conditional block to obtain the first abstract syntax tree.
[0031] In a possible implementation, it further includes a graphical representation method for the if conditional block and a graphical representation method for the match conditional block.
[0032] In a possible implementation, the graphical representation method for the if conditional block includes:
[0033] The entire conditional block is represented by a dotted rounded rectangle frame, and the name of the conditional block is edited in the upper left corner;
[0034] The conditional expression is represented by a solid oval frame, and the content of the conditional expression is edited inside the frame;
[0035] Connect the conditional expression and the then conditional branch with a first solid arrow, and connect the conditional expression and the else conditional branch with a thick dotted arrow; the conditional branches are nested conditional blocks or equation lists;
[0036] Equation lists are represented by solid-line right-angled rectangular boxes, and the content of the equation lists is edited within the boxes.
[0037] In one possible implementation, a graphical representation and an editing method for defining a match condition block are provided, including:
[0038] The entire condition block is represented by a dashed-line right-angled rectangular box, and the name of the condition block is edited in the upper left corner;
[0039] The enumeration expression is represented by a solid-line hexagonal box, and the content of the enumeration expression is edited within the box;
[0040] A second solid-line arrow is used to connect the enumeration instance and the conditional branch, and the conditional branch is a nested condition block or an equation list;
[0041] The equation list is represented by a solid-line right-angled rectangular box, and the content of the conditional branch is edited within the box.
[0042] A synchronous data flow language conversion method for an extended condition block provided by the present invention. The proposed extended condition block can support two or more conditional branches, and can more clearly and intuitively describe the jump relationship of the conditional control flow; at the same time, considering the actual engineering requirement of converting the standard Lustre language into the C language and having been realized, a method for converting the condition block into an equivalent Lustre code is proposed to achieve the purpose of not changing the original Lustre-to-C code generator; finally, a graphical representation and an editing method for the condition block are proposed, which can conveniently perform graphical modeling on the condition block. Brief Description of the Drawings
[0043] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention, and therefore should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts. In the drawings:
[0044] Figure 1 It is a flowchart of a synchronous data flow language conversion method for an extended condition block provided by the present invention.
[0045] Figure 2 It is a schematic diagram of the conversion process from the extended condition block provided by the present invention to the standard Lustre code.
[0046] Figure 3 It is a schematic diagram of the abstract syntax tree AST-Lustre* provided by the present invention.
[0047] Figure 4 It is a schematic diagram of the abstract syntax tree AST-Lustre provided by the present invention.
[0048] Figure 5 This is an example of converting the match_block syntax tree to the if_block syntax tree provided by the present invention.
[0049] Figure 6 This is an example of the graphical representation and editing method of the if conditional block provided by the present invention.
[0050] Figure 7 This is an example of the syntax tree of the if conditional block code provided by the present invention.
[0051] Figure 8 This is an example of the graphical representation and editing method of the match conditional block provided by the present invention.
[0052] Figure 9 This is an example of the syntax tree of the match conditional block code provided by the present invention. Detailed implementation manners
[0053] To make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below in conjunction with embodiments and the accompanying drawings. The illustrative embodiments of the present invention and their descriptions are only used to explain the present invention and are not intended to limit the present invention.
[0054] Embodiment
[0055] As Figure 1 shown, a method for converting an extended conditional block into a synchronous data flow language includes:
[0056] S101. Obtain a target extended conditional block; the target extended conditional block is used to represent a conditional block to be converted into a synchronous data flow language;
[0057] S102. Verify the target extended conditional block and obtain a verification result; the verification result includes passing the verification or failing the verification;
[0058] S103. When the verification result is passing the verification, parse the target extended conditional block to generate a first abstract syntax tree including the syntax structure of the target extended conditional block;
[0059] S104. Convert the first abstract syntax tree into a second abstract syntax tree with the syntax structure of the synchronous data flow language, and generate synchronous data flow language code with the second abstract syntax tree to complete the conversion of the synchronous data flow language.
[0060] The present invention proposes a syntax definition and implementation for an extended conditional block for the standard synchronous data flow language Lustre. The extended conditional block syntax supports two or more conditional branches to solve the problem of using if nesting multiple times in the standard Lustre language.
[0061] In a possible implementation, the target extended condition block is an extended condition block input by human-machine interaction or an extended condition block pre-stored in a database;
[0062] The syntax structure of the extended condition block includes a condition block name declaration, a condition block type definition, and a condition block return value declaration;
[0063] The condition block name declaration is set as a unique identifier;
[0064] The condition block type definition includes an if condition block and a match condition block;
[0065] The condition block return value declaration defines the return value of the condition block as the output of the condition block.
[0066] For example: The condition block name declaration is in the form of "condition identifier", and the identifier can be empty, but cannot be repeated with other condition block names. The condition block type definition includes two forms: an if condition block and a match condition block. The if condition block supports two condition branches, and the match condition block supports multiple condition branches. The condition block return value declaration defines the return value of the condition block as the output of the condition block.
[0067] In a possible implementation, the form of the if condition block is set as: if conditional expression then the first condition branch else the first condition branch; where the type of the conditional expression is set as bool, and the first condition branch is set as a custom statement or an if nest;
[0068] The form of the match condition block is set as: match enumeration expression with the second condition branch; where the enumeration expression represents a defined enumeration type, and the form of the second condition branch is: enumeration variable: custom statement.
[0069] In a possible implementation, verifying the target extended condition block and obtaining the verification result includes:
[0070] Checking whether there is a syntax error in the target extended condition block. If so, determining that the verification result is verification failed and ending the conversion process; otherwise, determining that the verification result is verification passed.
[0071] In a possible implementation, when the verification result is verification passed, parsing the target extended condition block to generate a first abstract syntax tree including the syntax structure of the target extended condition block, including:
[0072] When the verification result is verification passed, parsing the target extended condition block to obtain the if condition block and the match condition block in the target extended condition block;
[0073] Perform a first transformation on the if conditional block and a second transformation on the match conditional block to transform the target extended conditional block into a first abstract syntax tree.
[0074] In one possible implementation, performing the first transformation on the if conditional block includes:
[0075] Determine the output parameters of the if conditional block and use the output parameters of the if conditional block as the left value of the equation in the first abstract syntax tree; the number of output parameters of the if conditional block is the same as the number of equations;
[0076] Assign the value of the conditional variable in the if conditional block to the value of the conditional variable in the first abstract syntax tree;
[0077] Obtain the values of the output parameters in the then_equation_list (then equation list) of the if conditional block and assign the values of the output parameters in the then_equation_list to the then_expr (then expression) whose left value of the equation in the first abstract syntax tree is the corresponding output parameter;
[0078] Obtain the values of the output parameters in the else_equation_list (else equation list) of the if conditional block and assign the values of the output parameters in the else_equation_list to the else_expr (else expression) whose left value of the equation in the first abstract syntax tree is the corresponding output parameter;
[0079] For the then_expr and else_expr that are not assigned values in the first abstract syntax tree, take the default values in the node variable declaration.
[0080] In one possible implementation, performing the second transformation on the match conditional block includes:
[0081] Parse the number of branches in the match conditional block and, based on the number of branches in the match conditional block, transform the match conditional block into at least one if conditional block;
[0082] On the basis of the existing first abstract syntax tree, perform the first transformation on the transformed if conditional block to obtain the first abstract syntax tree.
[0083] In one possible implementation, it further includes a graphical representation method for the if conditional block and a graphical representation method for the match conditional block.
[0084] In one possible implementation, the graphical representation method for the if conditional block includes:
[0085] The entire conditional block is represented by a dashed - rounded rectangle, and the conditional block name is edited in the upper - left corner;
[0086] The conditional expression is represented by a solid - line ellipse, and the content of the conditional expression is edited within the box;
[0087] Connect the conditional expression to the then conditional branch with a first solid - line arrow, and connect the conditional expression to the else conditional branch with a thick dashed arrow; the conditional branch is a nested conditional block or an equation list;
[0088] The equation list is represented by a solid - line right - angled rectangle, and the content of the equation list is edited within the box.
[0089] In one possible implementation, a graphical representation and editing method for the match conditional block are defined, including:
[0090] The entire conditional block is represented by a dashed - line right - angled rectangle, and the conditional block name is edited in the upper - left corner;
[0091] The enumeration expression is represented by a solid - line hexagon, and the content of the enumeration expression is edited within the box;
[0092] Connect the enumeration instance to the conditional branch with a second solid - line arrow, and the conditional branch is a nested conditional block or an equation list;
[0093] The equation list is represented by a solid - line right - angled rectangle, and the content of the conditional branch is edited within the box.
[0094] A method for converting a synchronous data - flow language of an extended conditional block provided by the present invention. The proposed extended conditional block can support two or more conditional branches, and can more clearly and intuitively describe the jump relationship of the conditional control flow; at the same time, considering the need in actual engineering to convert the standard Lustre language to the C language and having been implemented, a method for converting the conditional block into equivalent Lustre code is proposed to achieve the purpose of not changing the original Lustre - to - C code generator; finally, a graphical representation and editing method for the conditional block are proposed, which can conveniently perform graphical modeling on the conditional block.
[0095] Example 2
[0096] Based on Example 1, this example further uses examples to explain the claims of the present invention.
[0097] A method for defining and implementing the syntax of an extended conditional block in synchronous data - flow, which supports two or more conditional branches.
[0098] The syntax structure of the conditional block consists of the following parts: conditional block name declaration, conditional block type definition, and conditional block return - value declaration.
[0099] Among them, the condition block name is declared in the form of "condition identifier", where the identifier can be empty but cannot be repeated with other condition block names. The condition block type definition includes two forms: the if condition block and the match condition block. The if condition block supports two condition branches, and the match condition block supports multiple condition branches. The condition block return value declaration defines the return value of the condition block, which serves as the output of the condition block.
[0100] The if condition block is defined in the form of: "if condition expression then condition branch else condition branch". The type of the condition expression is bool, and the condition branch is a custom statement or a nested if condition block.
[0101] The match condition block is defined in the form of: "match enumeration expression with condition branch". The enumeration expression is an enumeration type defined in the node, and the condition branch is in the form of "enumeration variable: custom statement". The enumeration variables should correspond one by one to all the variables of the enumeration type in the enumeration expression. They can be in any order, but there should be no duplicates or undefined variables.
[0102] The condition block return value declaration is defined in the form of: "returns identifier, identifier,...;". The return variables should be declared in the node variables. When declaring, the initial values can be assigned to them through the keywords default (to assign a default value) or last (to assign the default value for the first cycle, and the default value for the remaining cycles is the value of the previous cycle). If the condition block return variables are not assigned initial values, they must be assigned values in the custom statements of the condition block and can only appear on the left side of the equation. The return variables of the condition block are not allowed to be undeclared variables or local variables declared in the condition block. The return variables of the condition block can be empty, in which case they default to the same as the node return variables.
[0103] The custom statements are defined to include: equations and custom fields.
[0104] An equation can be a simple equation, such as in the form of "left value = expression", or it can be a state machine or a condition block. The custom field includes a local variable block and an equation list block. The local variable block is used to declare the local variables of the custom field, such as in the form of "var identifier: type expression; identifier: type expression;...". The equation list block consists of a series of equations, with the keywords let - tel at the beginning and end, such as in the form of "let equation; equation;... tel". The custom statement can be empty, indicating that no statement is executed for the corresponding condition branch.
[0105] The syntactic structure of the defined conditional block is in Extended Backus-Naur Form (BNF for short). The bold fonts in the figure are keyword declarations, and the meanings of the symbols used can be interpreted as follows: "::=" represents definition; "[A]" represents that A appears 0 or 1 time; "(A|B)" represents A or B, "|" represents or, "{A}" represents that A appears 0 or more times, and "{A}+" represents that A appears 1 or more times.
[0106] For example: condition_block::=conditon[id](if_block|match_block)return
[0107] if_block::=if expr then(data_def|if_block)
[0108] else(data_def|if_block)
[0109] match_block::=match expr with{|pattern:data_ef}+
[0110] return::=returns{id,}[id;]
[0111] data_def::=equation;
[0112] |scope
[0113] scope::=[local_block][eqs]
[0114] local_block::=var{var_decls;}
[0115] eqs::=let{equation;}tel
[0116] Define the method to convert the extended conditional block into standard Lustre code. First, check for syntax errors through the static syntax checking module. If there are syntax errors (such as undefined variables, identifier name conflicts, etc.), the parsing fails and an error is reported, and the translation process exits; if the syntax conforms to the specification, then parse the code containing the extended conditional block through lexical analysis and a parser to generate an abstract syntax tree AST-Lustre* containing the syntactic structure of the extended conditional block, and then convert AST-Lustre* into an abstract syntax tree AST-Lustre with the syntactic structure of the standard Lustre language. Finally, generate standard Lustre code based on AST-Lustre. The overall conversion process is as Figure 2As shown, the structure of the Abstract Syntax Tree AST-Lustre* is as Figure 3 As shown, the conditional block types include two forms: if_block and match_block. The structures of the Abstract Syntax Trees AST-Lustre are respectively as Figure 4 shown.
[0117] Define the method for converting if_block in the conditional block syntax tree AST-Lustre* to the AST-Lustre syntax tree: 1) Determine the output parameters of the conditional block. The output parameters serve as the left-hand side values of the equations in the AST-Lustre syntax tree, and the number of output parameters is equal to the number of equations. 2) Assign the value of condition in if_block to the condition in the AST-Lustre syntax tree. 3) Calculate the values of the output parameters in then_equation_list and assign them to then_expr in the AST-Lustre syntax tree whose left-hand side value of the equation is the corresponding output parameter. 4) Calculate the values of the output parameters in else_equation_list and assign them to else_expr in the AST-Lustre syntax tree whose left-hand side value of the equation is the corresponding output parameter. 5) For then_expr and else_expr in the AST-Lustre syntax tree that are not assigned values, take the default values in the node variable declarations.
[0118] Define the method for converting match_block in the conditional block syntax tree AST-Lustre* to the AST-Lustre syntax tree: First, define the method for converting match_block to if_block. Then, simply convert if_block to the AST-Lustre syntax tree according to the method described above. The method for converting match_block to if_block is as follows: If match_block has only one branch c1, e1, then assign c1 to the condition of if_block and e1 to the then_expr of if_block; If match_block has two branches c1, e1, c2, e2, then assign c1 to the condition of if_block, e1 to the then_expr of if_block, and e2 to the else_expr of if_block; Assume match_block has three branches c1, e1, c2, e2, c3, e3, then assign c1 to the condition of if_block, e1 to the then_expr of if_block, and the else_expr is a nested if_block'. Assign c2 to the condition of if_block', e2 to the then_expr of if_block', and e3 to the else_expr of if_block'. And so on for the remaining cases, to obtain the method for converting the match_block syntax tree to the if_block syntax tree as Figure 5 shown.
[0119] Define the graphical representation and editing method of the if conditional block. The entire conditional block is represented by a dashed rounded rectangle, and the name of the conditional block is edited in the upper left corner. The conditional expression is represented by a solid oval, and the content of the conditional expression is edited inside the box. Connect the conditional expression and the then conditional branch with a solid thick arrow, and connect the conditional expression and the else conditional branch with a dashed thick arrow. The conditional branch is a nested conditional block or an equation list. The equation list is represented by a solid right rectangle, and the content of the equation list is edited inside the box.
[0120] In this embodiment, an example of the graphical representation and editing method of the if conditional block is as Figure 6As shown, the entire conditional block is represented by a dashed rounded rectangle. Edit the conditional block name and return variables "if_block(returns x,y)" in the upper left corner. Edit the conditional expression content "i>0" within the solid-line ellipse. Connect the conditional expression to the then conditional branch with a thick solid arrow, and connect the conditional expression to the else conditional branch with a thick dashed arrow. The then conditional branch is a nested conditional expression "j>0", and the else conditional branch is an equation list "x = -1, y = -2", which is represented by a solid right rectangle. The conversion to if conditional block code is as follows:
[0121]
[0122] Generate the abstract syntax tree of the if conditional block code as Figure 7 As shown, convert it into a standard lustre syntax tree, and then convert it into standard lustre code through the standard lustre syntax tree as follows:
[0123] x = if i>0 then if j>0 then 1 else 0 else -1;
[0124] y = if i>0 then if j>0 then 2 else 0 else -2;
[0125] Define the graphical representation and editing method of the match conditional block. The entire conditional block is represented by a dashed right rectangle. Edit the conditional block name in the upper left corner. The enumeration expression is represented by a solid hexagon. Edit the content of the enumeration expression within the box. Connect the enumeration instance to the conditional branch with a thin solid arrow. The conditional branch is a nested conditional block or equation list. The equation list is represented by a solid right rectangle. Edit the content of the conditional branch within the box.
[0126] In this embodiment, an example of the graphical representation and editing method of the match conditional block is as Figure 8 As shown, the entire conditional block is represented by a dashed right rectangle. Edit the conditional block name and return variables "match_block(returns R,G,B)" in the upper left corner. Edit the enumeration expression "color" within the solid hexagon. Connect the enumeration instance to the conditional branch with a thin solid arrow. The conditional branch corresponding to "red" is the equation list "R = 255; G = 0; B = 0;", the conditional branch corresponding to "green" is the equation list "R = 0; G = 255; B = 0;", and the conditional branch corresponding to "blue" is the equation list "R = 0; G = 0; B = 255". The equation list is represented by a solid right rectangle. The conversion to match conditional block code is as follows:
[0127] condition match_block_eg match color with
[0128] |red:R = 255; G = 0; B = 0;
[0129] |green:R = 0; G = 255; B = 0;
[0130] |blue:R = 0; G = 0; B = 255;
[0131] returns R,G,B;
[0132] The abstract syntax tree of the generated match condition block code is as follows Figure 9 shown. Convert it into a standard Lustre syntax tree, and then convert it into standard Lustre code through the standard Lustre syntax tree as follows:
[0133] R = if red then 255 else if green then 0 else 0;
[0134] G = if red then 0 else if green then 255 else 0;
[0135] B = if red then 0 else if green then 0 else 255;
[0136] The present invention proposes a syntax definition and implementation for extending conditional blocks for the standard synchronous data flow language Lustre. The extended conditional block syntax supports two or more conditional branches, solving the problem of multiple uses of if nesting in the standard Lustre language. In addition, this patent also proposes a graphical representation and editing method for conditional blocks, which can conveniently perform graphical modeling on conditional blocks, and a method for converting extended conditional blocks into equivalent Lustre code, which can be compatible with the Lustre to C code generator.
[0137] The above-described specific embodiments have further elaborated on the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above is only the specific embodiment of the present invention and is not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for converting a synchronous data flow language for an extended conditional block, characterized in that, Including: Obtain a target extended condition block; The target extended condition block is used to represent a condition block to be converted into a synchronous data flow language; Verify the target extended condition block and obtain a verification result; the verification result includes passing the verification or failing the verification; When the verification result is passing the verification, parse the target extended condition block to generate a first abstract syntax tree including the syntax structure of the target extended condition block; Convert the first abstract syntax tree into a second abstract syntax tree with the syntax structure of the synchronous data flow language, and generate synchronous data flow language code with the second abstract syntax tree to complete the conversion of the synchronous data flow language; The step of when the verification result is passing the verification, parsing the target extended condition block to generate a first abstract syntax tree including the syntax structure of the target extended condition block includes: When the verification result is passing the verification, parse the target extended condition block to obtain the if condition block and the match condition block in the target extended condition block; Perform a first conversion on the if condition block and a second conversion on the match condition block to convert the target extended condition block into a first abstract syntax tree; The step of performing a first conversion on the if condition block includes: determining the output parameter of the if condition block, and using the output parameter of the if condition block as the left value of the equation in the first abstract syntax tree; the number of output parameters of the if condition block is the same as the number of equations; assign the value of the conditional variable in the if condition block to the value of the conditional variable in the first abstract syntax tree; The step of performing a second conversion on the match condition block includes: parsing the number of branches in the match condition block, and based on the number of branches in the match condition block, converting the match condition block into at least one if condition block; on the basis of the existing first abstract syntax tree, perform a first conversion on the converted if condition block to obtain the first abstract syntax tree.
2. The method for converting a synchronous data flow language of an extended condition block according to claim 1, wherein The target extended condition block is an extended condition block input by human-computer interaction or an extended condition block pre-stored in a database; The syntax structure of the extended condition block includes a condition block name declaration, a condition block type definition, and a condition block return value declaration; The condition block name declaration is set as a unique identifier; The condition block type definition includes an if condition block and a match condition block; The condition block return value declaration defines the return value of the condition block as the output of the condition block.
3. The method for converting a synchronous data flow language of an extended condition block according to claim 2, characterized in that, The form of the if condition block is set as: if conditional expression then first conditional branch else first conditional branch; where the type of the conditional expression is set as bool, and the first conditional branch is set as a custom statement or an if nest; The form of the match condition block is set as: match enumeration expression with second conditional branch; where the enumeration expression represents a defined enumeration type, and the form of the second conditional branch is: enumeration variable: custom statement.
4. The method for converting a synchronous data flow language of an extended conditional block according to claim 3, wherein Verifying the target extended condition block and obtaining a verification result includes: Check whether there is a syntax error in the target extended condition block. If so, determine that the verification result is verification failed and end the conversion process. Otherwise, determine that the verification result is verification passed.
5. The method for converting a synchronous data flow language of an extended conditional block according to claim 1, characterized in that The first conversion performed on the if condition block also includes: Obtain the values of the output parameters in the then_equation_list of the if condition block, and assign the values of the output parameters in the then_equation_list to the then_expr in the first abstract syntax tree whose left value of the equation is the corresponding output parameter; Obtain the values of the output parameters in the else_equation_list of the if condition block, and assign the values of the output parameters in the else_equation_list to the else_expr in the first abstract syntax tree whose left value of the equation is the corresponding output parameter; For the then_expr and else_expr in the first abstract syntax tree that have not been assigned values, take the default values in the node variable declaration.
6. The method for converting synchronous data flow language of an extended condition block according to claim 2, characterized in that, It also includes the graphical representation method of the if condition block and the graphical representation method of the match condition block.
7. The method for converting synchronous data flow language of an extended condition block according to claim 6, characterized in that The graphical representation method of the if condition block includes: The entire condition block is represented by a dotted rounded rectangle frame, and the condition block name is edited in the upper left corner; The conditional expression is represented by a solid ellipse frame, and the content of the conditional expression is edited inside the frame; Connect the conditional expression and the then conditional branch with a first solid arrow, and connect the conditional expression and the else conditional branch with a thick dotted arrow; the conditional branch is a nested conditional block or equation list; The equation list is represented by a solid right-angled rectangle frame, and the content of the equation list is edited inside the frame.
8. The method for converting synchronous data flow language of an extended condition block according to claim 6, characterized in that Define the graphical representation and editing method of the match condition block, including: The entire condition block is represented by a dotted right-angled rectangle frame, and the condition block name is edited in the upper left corner; The enumeration expression is represented by a solid hexagon frame, and the content of the enumeration expression is edited inside the frame; Connect the enumeration instance and the conditional branch with a second solid arrow, and the conditional branch is a nested conditional block or equation list; The equation list is represented by a solid right-angled rectangle frame, and the content of the conditional branch is edited inside the frame.
Citation Information
Patent Citations
AADL2TASM (Architecture Analysis and Design Language-to-Timed Abstract State Machine) model transformation method
CN102520925A
Extensible Lustre code generation method based on XML
CN116126304A