Command constructor generation method, device and equipment based on abstract syntax tree

Through the method based on the abstract syntax tree, the complexity problem of command constructor generation in chip design is solved, accurate command construction and verification are achieved, and the design efficiency and accuracy are improved.

CN119166157BActive Publication Date: 2025-02-18SHENZHEN HONGXIN MICRO NANO TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411629777.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-02-18
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

In chip physical layout design, it is difficult for developers to accurately write command constructors, especially because there are complex dependencies and constraints between multiple command options, making it difficult to determine the valid conditions and values ​​of the options.

Method used

Using an abstract syntax tree (AST)-based method, obtain user constraints and expected results. By traversing the logical nodes of AST, combining option child nodes and applying constraints, generating pattern units, and verifying pattern units combinations under user constraints , if the desired result is met, a command constructor is generated.

Benefits of technology

Through the checksum combination calculation of the abstract syntax tree, it is possible to accurately generate command constructors that meet user constraints and expectations, simplifying the command construction process and improving the accuracy and efficiency of the design.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166157B_ABST
    Figure CN119166157B_ABST
Patent Text Reader

Abstract

The present application provides a method, device and equipment for generating a command constructor based on an abstract syntax tree, which belongs to the field of chip design. The method includes: obtaining an abstract syntax tree according to a domain-specific language, traversing the logical nodes of the abstract syntax tree, and combining the option sub-nodes under each logical node and the corresponding constraints to form a pattern unit; performing a combination calculation on the pattern units between the logical nodes to obtain a pattern unit combination; verifying the pattern unit combination under the user constraint conditions to obtain a verification result, and judging whether the verification result is consistent with the user's expected result; if so, generating a command constructor for the current command based on the abstract syntax tree of the current command. Verify the domain-specific language of the current command under the given user constraint conditions. If the verification result meets the user's expected result, automatically generate a command constructor based on the abstract syntax tree to facilitate the generation of the command constructor of CMD.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of chip design, and in particular to a method, device and equipment for generating a command constructor based on an abstract syntax tree. Background Art

[0002] When using EDA (Electronic Design Automation Tools) tools for chip physical layout design, many commands (Command, CMD) are used to complete the layout design process. The commands used in development may have more than dozens of options (options), and multiple options may have complex dependencies. In the program code, multiple interfaces that describe dependencies or mutual exclusions must be called to clearly define the relationship between options. For the values ​​of multi-layer nested complex types of options, it is necessary to write separate parsing functions for them to obtain pre-fetched values. Since it is difficult to know the constraint relationship between different options, the specific conditions for the options to take effect, and the value of the options, it is also difficult to write an accurate command constructor that conforms to the CMD semantics. Summary of the invention

[0003] In order to solve the above technical problems, the embodiments of the present application provide a method, apparatus and device for generating a command constructor based on an abstract syntax tree.

[0004] In a first aspect, an embodiment of the present application provides a method for generating a command constructor based on an abstract syntax tree, the method comprising: obtaining user constraints, user expected results, and a domain specific language of the current command;

[0005] Acquire an abstract syntax tree according to the domain specific language, traverse the logic nodes of the abstract syntax tree, obtain option sub-node combinations under each logic node, and obtain constraints of each option sub-node combination according to the constraints of each logic node, and form a pattern unit with the option sub-node combination and the corresponding constraints under each logic node;

[0006] Perform combination calculation on the pattern units between the logic nodes to obtain a pattern unit combination;

[0007] Verifying the mode unit combination under the user constraint condition to obtain a verification result, and determining whether the verification result is consistent with the user expected result;

[0008] If so, a command constructor of the current command is generated based on the abstract syntax tree of the current command.

[0009] In one implementation, logical nodes are classified into categories, including fully selected nodes, single selected nodes, and partially selected nodes;

[0010] If the logic node is a fully selected node, a multiplication operation is performed on the combination of option subnodes in the pattern unit under the logic node;

[0011] If the logic node is a single-choice node, then performing an addition operation on the combination of option subnodes in the mode unit under the logic node;

[0012] If the logic node is a partial selection node, a mandatory label or an optional label is added to the logic node, and a multiplication operation is performed on the combination of option sub-nodes in the pattern unit under the logic node according to the mandatory label and the optional label.

[0013] In one embodiment, the user expected result includes the existence of a feasible solution and the non-existence of a feasible solution, and verifying the mode unit combination under the user constraint condition to obtain the verification result includes:

[0014] Constructing a constraint tree for each mode unit combination according to the constraint of each mode unit combination and the user constraint;

[0015] Performing AND or OR calculations on the constraints according to the constraint tree until the constraints in the pattern unit combination are numerical constraints;

[0016] Verify whether there is a feasible solution for the numerical constraint condition under the mode unit combination, and obtain the verification result, which includes whether there is a feasible solution or not.

[0017] In one embodiment, the checking whether there is a feasible solution to the numerical constraint condition under the mode unit combination includes:

[0018] Constructing a numerical constraint condition tree according to the numerical constraint conditions of the pattern unit combination;

[0019] Performing AND or OR calculations on the numerical constraints according to the numerical constraint tree to obtain an initial feasible solution;

[0020] If all the values ​​of the initial feasible solution conflict, then the pattern unit combination has no feasible solution under the user constraints; if some of the values ​​of the initial feasible solution conflict or there is no value conflict, then the pattern unit combination has a feasible solution under the user constraints.

[0021] In one embodiment, the performing AND or OR calculation on the numerical constraint condition according to the numerical constraint condition tree, the method further comprises:

[0022] If the AND or OR calculation of the numerical constraints according to the numerical constraint tree fails, then the pattern unit combination has no feasible solution under the user constraints.

[0023] In one embodiment, after the pattern unit combination has a feasible solution under the user constraint, the method further includes:

[0024] According to the numerical constraint condition of the pattern unit combination, the numerical type and numerical range of the option sub-node combination under the pattern unit combination, adding a numerical value to the option sub-node combination;

[0025] And the value type, value range and value of the option sub-node combination are concatenated into a character string.

[0026] In one implementation, generating a command constructor of the current command based on the abstract syntax tree of the current command includes:

[0027] Obtaining dependency relationships and values ​​of each option sub-node based on the abstract syntax tree;

[0028] A command constructor of the current command is generated according to the dependency relationship and value of each option sub-node.

[0029] In a second aspect, an embodiment of the present application provides a command constructor generation device based on an abstract syntax tree, wherein the command constructor generation device based on an abstract syntax tree comprises:

[0030] The acquisition module is used to obtain the user's constraints, the user's expected results, and the domain-specific language of the current command;

[0031] A composition module, used to obtain an abstract syntax tree according to the domain specific language, traverse the logic nodes of the abstract syntax tree, obtain the option sub-node combination under each logic node, and obtain the constraint conditions of each option sub-node combination according to the constraint conditions of each logic node, and form the option sub-node combination and the corresponding constraint conditions under each logic node into a pattern unit;

[0032] A calculation module, used for performing combination calculation on the pattern units between the logic nodes to obtain a pattern unit combination;

[0033] A verification module, used to verify the mode unit combination under the user constraint condition, obtain a verification result, and determine whether the verification result is consistent with the user expected result;

[0034] A generation module is used to generate a command constructor of the current command based on the abstract syntax tree of the current command.

[0035] In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory is used to store a computer program, and when the computer program is run by the processor, the command constructor generation method based on the abstract syntax tree provided in the first aspect is executed.

[0036] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when running on a processor, executes the command constructor generation method based on an abstract syntax tree provided in the first aspect.

[0037] The above-mentioned command constructor generation method based on the abstract syntax tree provided by the present application obtains user constraints, user expected results and the domain-specific language of the current command; obtains an abstract syntax tree according to the domain-specific language, traverses the logical nodes of the abstract syntax tree, obtains the option sub-node combination under each logical node, and obtains the constraint conditions of each option sub-node combination according to the constraint conditions of each logical node, and the option sub-node combination under each logical node and the corresponding constraint conditions are combined into a pattern unit; the pattern units between each logical node are combined and calculated to obtain a pattern unit combination; the pattern unit combination is verified under the user constraint conditions to obtain a verification result, and it is determined whether the verification result is consistent with the user expected result; if so, the command constructor of the current command is generated based on the abstract syntax tree of the current command. Through the abstract syntax tree, the domain-specific language of the current command is verified under the given user constraint conditions. If the verification result meets the user's expected result, the method of automatically generating a command constructor based on the abstract syntax tree provides convenience for the generation of the command constructor of CMD. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present application and should not be regarded as limiting the scope of protection of the present application. In each of the drawings, similar components are numbered similarly.

[0039] Figure 1 A schematic diagram of a flow chart of a command constructor generation method based on an abstract syntax tree provided in an embodiment of the present application is shown;

[0040] Figure 2 Another schematic diagram of a flow chart of a command constructor generation method based on an abstract syntax tree provided in an embodiment of the present application is shown;

[0041] Figure 3 Another schematic diagram of a flow chart of a command constructor generation method based on an abstract syntax tree provided in an embodiment of the present application is shown;

[0042] Figure 4 A schematic diagram of a constraint tree provided in an embodiment of the present application is shown;

[0043] Figure 5Another schematic diagram of a flow chart of a command constructor generation method based on an abstract syntax tree provided in an embodiment of the present application is shown;

[0044] Figure 6 A schematic diagram of a numerical constraint condition tree provided in an embodiment of the present application is shown;

[0045] Figure 7 A schematic diagram of an option sub-node provided in an embodiment of the present application is shown;

[0046] Figure 8 A schematic diagram showing member variables corresponding to a base class command provided in an embodiment of the present application is shown;

[0047] Fig. 9 A structural schematic diagram of a command constructor generation device based on an abstract syntax tree provided in an embodiment of the present application is shown.

[0048] Icon: 900 - command constructor generation device based on abstract syntax tree, 901 - acquisition module, 902 - composition module, 903 - calculation module, 904 - verification module, 905 - generation module. DETAILED DESCRIPTION

[0049] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.

[0050] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0051] Hereinafter, the terms "including", "having" and their cognates, which may be used in various embodiments of the present application, are intended only to indicate specific features, numbers, steps, operations, elements, components, or combinations of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components, or combinations of the foregoing items or adding the possibility of one or more features, numbers, steps, operations, elements, components, or combinations of the foregoing items.

[0052] Furthermore, the terms “first”, “second”, “third”, etc. are merely used for distinguishing descriptions and are not to be understood as indicating or implying relative importance.

[0053] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.

[0054] Example 1

[0055] An embodiment of the present application provides a command constructor generation method based on an abstract syntax tree.

[0056] See also Figure 1 , the command constructor generation method based on the abstract syntax tree includes steps S101-S105:

[0057] S101: Obtain user constraints, user expected results, and a domain-specific language of a current command, and obtain an abstract syntax tree according to the domain-specific language.

[0058] In this embodiment, user constraints represent mutually exclusive relationships, dependency relationships, and value ranges between certain option nodes, and the relationships between option nodes are constrained by user constraints. The user expected result is that the user verifies the domain-specific language of CMD through given constraints and determines whether the verification result meets the expected output. The domain-specific language (DSL) of the current command is the syntax and rules used to describe and generate the current command statement. DSL defines the structure of the CMD statement, the naming and value-taking methods of options, and the combination and constraint relationships between options.

[0059] For example, if the user expects that option-a and option-b cannot appear at the same time, the domain-specific language of the current CMD is verified by giving the constraint "-a&&-b". The constraint indicates that the option-a node and the options-b node need to exist at the same time. The verification result under the constraint will be returned through calculation. The verification result can be False or True. If the verification result is True, it indicates that the option-a node and the options-b node exist at the same time, which is contrary to the user's expected result, and there is an error in the domain-specific language of the current CMD.

[0060] S102: obtaining an abstract syntax tree according to the domain specific language, traversing the logic nodes of the abstract syntax tree, obtaining option sub-node combinations under each logic node, and obtaining constraints of each option sub-node combination according to the constraints of each logic node, and forming a pattern unit with the option sub-node combination and the corresponding constraints under each logic node.

[0061] In this embodiment, the DSL is parsed by a commonly used lexical analyzer and syntax analyzer generation tool (flex-bison) to obtain a syntax structure, and a node type is defined for each syntax structure, including a logical node and multiple option sub-nodes under each logical node, where the Option sub-node represents an option, including an option name, a value, and related constraints, and an Abstract Syntax Tree (AST) is constructed through nodes and node types.

[0062] Optionally, after generating AST, traverse each node on AST, obtain option child nodes under logical nodes, and logically combine different option child nodes under each logical node through the type corresponding to each logical node (such as && node type and || node type, etc.) to obtain different option child node combinations; during the traversal process, logically combine the constraints corresponding to each child node under the logical node to obtain the constraints that hold for different option child node combinations, and then combine the option child node combinations and corresponding constraints under each logical node into pattern units. Each logical node may return multiple groups of option child node combinations, which are represented by Comb (Pattern1, Pattern2, …, PatternN), where Comb represents the logical node and Pattern1 = options child node combination + constraints. For example, Pattern1 of the logical node CombA is (-ab, -b) +{(-ab) -b::1}, where (-ab) and -b represent different option child node combinations. When the constraint is (-ab), option-a and option-b must exist. When the constraint is -b::1, the value of option-b is 1. Pattern2 is (-a) +{(-a) -a::2}, where (-a) represents an option child node combination. When the constraint is (-a), option-a must exist. When the constraint is -a::2, the value of option-a is 2.

[0063] S103: Perform combination calculation on the pattern units between the logical nodes to obtain a pattern unit combination.

[0064] In this embodiment, when the pattern unit performs combination calculation, there are two methods for combination calculation between option sub-nodes, including multiplication operation and addition operation, and the constraints corresponding to the option sub-nodes perform logical operations. For example, when the option sub-node combination performs a multiplication operation, the constraints corresponding to the option sub-node combination perform a && operation.

[0065] Exemplarily, when the option sub-node combination of logical node A and logical node B is multiplied, it can be expressed as A(-a, -ab)×B(-c, --cd), and the possible option sub-node combination obtained by multiplication should be (-ac, -acd, -abc, -ab--cd); when the option sub-node combination of logical node A and logical node B is added, it can be expressed as A(-a, -ab) + B(-c, --cd) = (-a, -ab, -c, --cd).

[0066] See also Figure 2 In one embodiment, the combined calculation includes multiplication calculation and addition calculation, and the combined calculation for each logical node includes steps S1031-S1034:

[0067] S1031: Classify the logical nodes into fully selected nodes, single selected nodes and partially selected nodes.

[0068] In this embodiment, in the process of traversing the AST, the node attribute category is identified according to the node type and attribute. For example, if a logic node indicates that all option sub-node combinations must be selected, it is classified as a full selection node (AllOfNode); if a logic node indicates that one of the option sub-node combinations is selected, it is classified as a single selection node (OneOfNode); if a logic node indicates that some of the option sub-node combinations in the option sub-node combination must be selected or may be selected, the logic node is classified as a partial selection node (SomeOfNode).

[0069] S1032: If the logic node is a fully selected node, a multiplication operation is performed on the combination of option sub-nodes in the pattern unit under the logic node.

[0070] In this embodiment, when the logic node is a fully selected node, all its option child node combinations must be fully selected and multiplication operations are applied to them. For example, if there are two fully selected nodes A (-a, -ab) and B (-c, --cd), the combination result is (-ac, -a--cd, -abc, -ab--cd).

[0071] S1033: If the logic node is a single-choice node, perform an addition operation on the option sub-node combination in the mode unit under the logic node.

[0072] In this embodiment, when the logic node is a single-choice node, one option subnode combination under the logic node is selected using an addition operation. For example, if there are two single-choice nodes A (-a, -ab) and B (-c, --cd), the possibility of the combination result is (-a, -ab, -c, --cd).

[0073] S1034: If the logic node is a partial selection node, a mandatory label or an optional label is added to the logic node, and a multiplication operation is performed on the combination of option sub-nodes in the pattern unit under the logic node according to the mandatory label and the optional label.

[0074] In this embodiment, when the logical node is a partial selection node, it is marked as a required node or an optional node, and different processing is performed according to the marking result. When the logical node is marked as a required node, a multiplication operation is used, and the result must include the option sub-node combination of the required node; when the logical node is an optional node, the final combination possibility can add the option sub-node combination itself multiplied with it. Exemplarily, for example, the logical node A of the required node and the logical node B of the optional node are combined, expressed as A(-a) (required)×B(-b), then the result is (-ab, -b); for example, the logical node A of the required node and the logical node B of the required node are combined A(-a)(required)×B(-b) (required), then the result is (-ab); for example, the logical node A of the optional node and the logical node B of the optional node are combined A(-a)×B(-b), then the result is (-a, -b, -ab).

[0075] S104: verifying the mode unit combination under the user constraint condition, obtaining a verification result, and determining whether the verification result is consistent with the user expected result.

[0076] In this embodiment, under the constraints given by the user, it is checked whether the pattern unit combination obtained in step S103 has a feasible solution, and it is determined whether the verification result is consistent with the result expected by the user (whether there is a feasible solution or not).

[0077] See also Figure 3 In one embodiment, the user expected result includes the existence of a feasible solution and the non-existence of a feasible solution, and S104 includes steps S1041-S1043.

[0078] S1041: Construct a constraint tree for each mode unit combination according to the constraint of each mode unit combination and the user constraint.

[0079] In this embodiment, the flex-bison tool is used to parse the constraints given by the user, generate an expression node (expr node), add the user constraints to the constraints of the option sub-node combination, and build a constraint tree. When building the constraint tree, it is necessary to consider the priority and logical relationship of the constraints to ensure the accuracy of the constraint tree. Exemplarily, the constraint set in the option sub-node combination under different logical nodes is {(-ab) -b::1} or {(-a) -a::2}, and the user constraint is -c::1 after parsing, then the constraint set in the option sub-node combination under different logical nodes should become {(-ab) -b::1&&-c::1} and {(-a) -a::2&&-c::1}.

[0080] S1042: Performing AND or OR calculations on the constraints according to the constraint tree until the constraints in the pattern unit combination are numerical constraints.

[0081] In this embodiment, see Figure 4 For example, there is a constraint tree whose first layer is an AND logic node, the second layer is two OR logic nodes, and the third layer is the constraints corresponding to the option sub-node combination. When the option sub-node combination is -ac, then for the two OR nodes in the second layer, the constraints of their left nodes are satisfied, that is, -a exists and -c exists, so it can be simplified to -b::1 and -d::1; if the option sub-node combination is -ad, for the right OR node, the value constraint -d::1 is left, and for the first layer && node, it is found that the left side is satisfied and the right side is a value constraint, so it is simplified to -d::1 on the right.

[0082] In one embodiment, the numerical constraints are calculated according to the numerical constraint tree, and the method further includes: if the numerical constraints are calculated according to the numerical constraint tree and the AND or OR operation fails, then the pattern unit combination has no feasible solution under the user constraint.

[0083] In this embodiment, if the option sub-node combination is -a, the constraint condition that the right or node -c must exist is not satisfied, and -d::1 is also not satisfied, which means that the option sub-node combination has no feasible solution under the user constraint condition, and there is an error in the DSL language of the current command.

[0084] S1043: Check whether there is a feasible solution for the numerical constraint condition under the mode unit combination, and obtain the verification result, which includes whether there is a feasible solution or not.

[0085] In this embodiment, the numerical constraint conditions obtained after the AND or OR logic calculation are verified to determine whether there is a feasible solution for the numerical constraint conditions under the logic node. Based on the verification result, it is determined whether it is consistent with the result expected by the user. If it is consistent, it indicates that the mode unit combination satisfies the user constraint conditions and there is no error in the DSL language of the current CMD.

[0086] See also Figure 5 In one embodiment, the S1043 includes steps S501-S503:

[0087] S501: Constructing a numerical constraint condition tree according to the numerical constraint conditions under the pattern unit combination.

[0088] In this embodiment, see Figure 6 According to the logical relationship of the option sub-node combination corresponding to the numerical constraint condition, a numerical constraint condition tree of the numerical constraint condition under the pattern unit combination is constructed, wherein the first layer is an AND logic node, the second layer is an OR logic node and an AND logic node, and the third layer is the numerical constraint condition corresponding to the simplified option sub-node combination.

[0089] S502: Performing AND or OR calculations on the numerical constraint conditions according to the numerical constraint condition tree to obtain an initial feasible solution.

[0090] In this embodiment, continue to see Figure 6 , the feasible solution of the && node on the left is: (!a::1&&b::1), and the feasible solution of the || node on the right is: (a::2)(a::1). Processing the AND (&&) nodes on the first layer, we get two initial feasible solutions: (!-a::1&&b::1&&-a::2) and (!-a::1&&b::1&&a::1).

[0091] S503: If all the values ​​of the initial feasible solution conflict, then the pattern unit combination does not have a feasible solution under the user constraint conditions; if some of the values ​​of the initial feasible solution conflict or there is no value conflict, then the pattern unit combination has a feasible solution under the user constraint conditions.

[0092] In this embodiment, the first solution (!-a::1&&b::1&&-a::2), where the constraint condition that -a is 2 is satisfied, the numerical constraint tree can be simplified to (b::1&&-a::2), there is no value conflict, and the pattern unit combination has a feasible solution under the user constraint. The second solution (!-a::1&&b::1&&a::1), where -a has a value conflict, indicates that this user constraint is invalid, and the pattern unit combination does not have a feasible solution under the user constraint.

[0093] In one embodiment, after the pattern unit combination has a feasible solution under the user constraint conditions, the method further includes: adding a numerical value to the option sub-node combination according to the numerical constraint conditions of the pattern unit combination, the numerical type and numerical range of the option sub-node combination under the pattern unit combination; and concatenating the numerical type, numerical range and numerical value of the option sub-node combination into a character string.

[0094] In this embodiment, a value is added to the option sub-node combination according to the value constraint of the pattern unit and the value type (value type), value range (value range) of the option sub-node combination itself, and the values ​​are concatenated into a character string.

[0095] For example, if the patten unit combination that finally has a feasible solution is: -a -b -c, and its numerical constraint is -a!1&&-b::1, and the value range of the option sub-node combination -a under the patten unit combination is range[0~10], then the added value in the range of 0-10 that is not equal to 1, -b takes the value of 1, and -c takes a random value.

[0096] S105: If yes, then generate a command constructor of the current command based on the abstract syntax tree of the current command.

[0097] In this embodiment, if the DSL of the current command meets the expected result of the verification, the logical relationship of the option sub-nodes is extracted according to the abstract syntax tree of the current command, the constructor of CMD is automatically generated, and CMD is defined through the constructor.

[0098] In one implementation, the dependency relationship and the value of each option sub-node are obtained based on the abstract syntax tree; and the command constructor of the current command is generated according to the dependency relationship and the value of each option sub-node.

[0099] In this embodiment, the dependency verification of each option sub-node and the analysis of the value of each option sub-node can be easily performed based on AST. First, a base class command is generated for each current command, and a command constructor is generated according to the base class command. In the command constructor, only the option sub-node of the corresponding data type needs to be added, and there is no need to define the logical relationship between the option sub-nodes.

[0100] Furthermore, the CMD statement is verified based on AST. Based on AST, the constraint relationship and additional conditions between option subnodes can be clearly known, so the CMD statement can be verified very conveniently, including the constraint relationship between option subnodes and the value of option subnodes, and the correct CMD statement is generated at the same time. Optionally, the verification interface (dslCheck) in AST is called to verify the CMD statement.

[0101] Optionally, when generating a command constructor based on AST, for inputs of complex data types nested in AST, such as SpecNode and ArgsNode, for example, the complex data type of {a {bc} {d}}, where a represents the root node, {bc} and {d} represent child nodes, it is necessary to add corresponding member variables for them and generate corresponding conversion functions for them, which are used to convert the value after dslCheck into the expected data type, and generate a command constructor according to the expected data type. Specifically, for inputs of nested complex data types, after generating the corresponding structure (struct) structure for each sub-specification (subSpec), the value (value) after dslCheck is converted into the expected data type through the conversion function.

[0102] For example, if the value after dslCheck is converted into the corresponding data type through the ConvXXX conversion function, the corresponding struct structure needs to be generated before the value is converted into the corresponding data type. Figure 7 , a schematic diagram of the -site option subnode, see Figure 8 , which is the member variable corresponding to the generated base class command. For example, if the input is the option subnode -site, the value type of -site is a dynamic array type, and the array member is of the SITE_CFG (custom name) type. The member variables of the SITE_CFG composite structure have two items, one is the dbGroup pointer type, and the other is a dynamic array type. The array member is of the ISTE_PATTERN_CFG type. By analogy, SITE_PATTERN_CFG is also a composite structure data type.

[0103] The command constructor generation method based on the abstract syntax tree provided in this embodiment obtains user constraints, user expected results and the domain-specific language of the current command; obtains an abstract syntax tree according to the domain-specific language, traverses the logical nodes of the abstract syntax tree, obtains the option sub-node combination under each logical node, and obtains the constraint conditions of each option sub-node combination according to the constraint conditions of each logical node, and the option sub-node combination under each logical node and the corresponding constraint conditions are combined into a pattern unit; the pattern units between the logical nodes are combined and calculated to obtain a pattern unit combination; the pattern unit combination is verified under the user constraint conditions to obtain a verification result, and it is determined whether the verification result is consistent with the user expected result; if so, the command constructor of the current command is generated based on the abstract syntax tree of the current command. Through the abstract syntax tree, the domain-specific language of the current command is verified under the given user constraint conditions. If the verification result meets the user's expected result, the method of automatically generating a command constructor based on the abstract syntax tree provides convenience for the generation of the command constructor of CMD.

[0104] Example 2

[0105] In addition, an embodiment of the present application provides a command constructor generation device based on an abstract syntax tree, which is applied to an electronic device.

[0106] like Fig. 9 As shown, the command constructor generating device 900 based on the abstract syntax tree includes:

[0107] The acquisition module 901 is used to acquire user constraints, user expected results and the domain specific language of the current command.

[0108] The composition module 902 is used to obtain an abstract syntax tree according to the domain-specific language, traverse the logic nodes of the abstract syntax tree, obtain the option sub-node combination under each logic node, and obtain the constraint conditions of each option sub-node combination according to the constraint conditions of each logic node, and combine the option sub-node combination under each logic node and the corresponding constraint conditions into a pattern unit.

[0109] The calculation module 903 is used to perform combination calculation on the pattern units between the logical nodes to obtain a pattern unit combination.

[0110] The verification module 904 is used to verify the mode unit combination under the user constraint condition, obtain a verification result, and determine whether the verification result is consistent with the user expected result.

[0111] The generating module 905 is used to generate a command constructor of the current command based on the abstract syntax tree of the current command.

[0112] Optionally, the calculation module 903 shown is also used to classify the logical nodes, including fully selected nodes, single-selected nodes and partially selected nodes; if the logical node is a fully selected node, a multiplication operation is performed on the option sub-node combination in the pattern unit under the logical node; if the logical node is a single-selected node, an addition operation is performed on the option sub-node combination in the pattern unit under the logical node; if the logical node is a partially selected node, a mandatory label or an optional label is added to the logical node, and a multiplication operation is performed on the option sub-node combination in the pattern unit under the logical node according to the mandatory label and the optional label.

[0113] Optionally, the verification module 904 shown is also used to construct a constraint tree for each pattern unit combination based on the constraints of each pattern unit combination and the user constraints; perform AND or calculations on the constraints according to the constraint tree until the constraints in the pattern unit combination are numerical constraints; verify whether there is a feasible solution for the numerical constraints under the pattern unit combination, and obtain the verification result, which includes the existence of a feasible solution and the absence of a feasible solution.

[0114] Optionally, the verification module 904 is further used to construct a numerical constraint tree according to the numerical constraints of the pattern unit combination; perform AND or OR calculations on the numerical constraints according to the numerical constraint tree to obtain an initial feasible solution; if all values ​​of the initial feasible solution conflict, then the pattern unit combination does not have a feasible solution under the user constraints; if some values ​​of the initial feasible solution conflict or there is no value conflict, then the pattern unit combination has a feasible solution under the user constraints.

[0115] Optionally, the verification module 904 is further configured to determine that if the AND or OR calculation of the numerical constraint condition according to the numerical constraint condition tree fails, then the pattern unit combination has no feasible solution under the user constraint condition.

[0116] Optionally, the verification module 904 shown is also used to add a numerical value to the option sub-node combination according to the numerical constraint conditions of the pattern unit combination, the numerical type and numerical range of the option sub-node combination under the pattern unit combination; and concatenate the numerical type, numerical range and numerical value of the option sub-node combination into a character string.

[0117] Optionally, the generating module 905 is further configured to generate a command constructor of the current command according to the dependency relationship and values ​​of each option sub-node.

[0118] The command constructor generation device 900 based on an abstract syntax tree provided in this embodiment can implement the command constructor generation method based on an abstract syntax tree provided in Embodiment 1, and will not be described again here to avoid repetition.

[0119] The command constructor generation device based on the abstract syntax tree provided in this embodiment obtains user constraints, user expected results and the domain-specific language of the current command; obtains an abstract syntax tree according to the domain-specific language, traverses the logical nodes of the abstract syntax tree, obtains the option sub-node combination under each logical node, and obtains the constraint conditions of each option sub-node combination according to the constraint conditions of each logical node, and the option sub-node combination under each logical node and the corresponding constraint conditions are combined into a pattern unit; the pattern units between the logical nodes are combined and calculated to obtain a pattern unit combination; the pattern unit combination is verified under the user constraint conditions to obtain a verification result, and it is determined whether the verification result is consistent with the user expected result; if so, the command constructor of the current command is generated based on the abstract syntax tree of the current command. Through the abstract syntax tree, the domain-specific language of the current command is verified under the given user constraint conditions. If the verification result meets the user's expected result, the method of automatically generating a command constructor based on the abstract syntax tree provides convenience for the generation of the command constructor of CMD.

[0120] Example 3

[0121] In addition, an embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program runs on the processor, the command constructor generation method based on the abstract syntax tree provided in Example 1 is executed.

[0122] The electronic device provided in the embodiment of the present invention can execute the steps of the command constructor generation method based on the abstract syntax tree provided in the above method embodiment 1, which will not be described again to avoid repetition.

[0123] Example 4

[0124] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the command constructor generation method based on the abstract syntax tree provided in Example 1 is implemented.

[0125] In this embodiment, the computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0126] The computer-readable storage medium provided in this embodiment can implement the command constructor generation method based on the abstract syntax tree provided in Example 1, and will not be described again here to avoid repetition.

[0127] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or terminal including the element.

[0128] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0129] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A command constructor generation method based on an abstract syntax tree, characterized in that: The method comprises: Obtaining user constraints, user expected results, and domain specific language of the current command, wherein the user expected results include whether a feasible solution exists or not; Acquire an abstract syntax tree according to the domain specific language, traverse the logic nodes of the abstract syntax tree, obtain option sub-node combinations under each logic node, and obtain constraints of each option sub-node combination according to the constraints of each logic node, and form a pattern unit with the option sub-node combination and the corresponding constraints under each logic node; Perform combination calculation on the pattern units between the logic nodes to obtain a pattern unit combination; Verifying the mode unit combination under the user constraint condition to obtain a verification result, and determining whether the verification result is consistent with the user expected result; If yes, then generating a command constructor of the current command based on the abstract syntax tree of the current command; Verifying the mode unit combination under the user constraint condition to obtain a verification result includes: Constructing a constraint tree for each mode unit combination according to the constraint of each mode unit combination and the user constraint; Performing AND or OR calculations on the constraints according to the constraint tree until the constraints in the pattern unit combination are numerical constraints; Verify whether there is a feasible solution for the numerical constraint condition under the mode unit combination, and obtain the verification result, wherein the verification result includes whether there is a feasible solution or not; The checking whether there is a feasible solution for the numerical constraint conditions under the mode unit combination includes: Constructing a numerical constraint condition tree according to the numerical constraint conditions of the pattern unit combination; Performing AND or OR calculations on the numerical constraints according to the numerical constraint tree to obtain an initial feasible solution; If all the values ​​of the initial feasible solution conflict, then the pattern unit combination has no feasible solution under the user constraints; if some of the values ​​of the initial feasible solution conflict or there is no value conflict, then the pattern unit combination has a feasible solution under the user constraints.

2. The method according to claim 1, characterized in that The combined calculation includes multiplication calculation and addition calculation, and the combined calculation for each logical node includes: Classify the logical nodes, including all selected nodes, single selected nodes and partial selected nodes; If the logic node is a fully selected node, a multiplication operation is performed on the combination of option subnodes in the pattern unit under the logic node; If the logic node is a single-choice node, then performing an addition operation on the combination of option subnodes in the mode unit under the logic node; If the logic node is a partial selection node, a mandatory label or an optional label is added to the logic node, and a multiplication operation is performed on the combination of option sub-nodes in the pattern unit under the logic node according to the mandatory label and the optional label.

3. The method according to claim 1, characterized in that The method further comprises: performing AND or OR calculation on the numerical constraint conditions according to the numerical constraint condition tree; If the AND or OR calculation of the numerical constraints according to the numerical constraint tree fails, then the pattern unit combination has no feasible solution under the user constraints.

4. The method according to claim 1, characterized in that: After the mode unit combination has a feasible solution under the user constraint condition, the method further includes: According to the numerical constraint condition of the pattern unit combination, the numerical type and numerical range of the option sub-node combination under the pattern unit combination, adding a numerical value to the option sub-node combination; And the value type, value range and value of the option sub-node combination are concatenated into a character string.

5. The method according to claim 1, characterized in that The step of generating a command constructor of the current command based on the abstract syntax tree of the current command includes: Obtaining dependency relationships and values ​​of each option sub-node based on the abstract syntax tree; A command constructor of the current command is generated according to the dependency relationship and value of each option sub-node.

6. A command constructor generation device based on an abstract syntax tree, characterized in that: The device comprises: An acquisition module, used to acquire user constraints, user expected results and domain specific language of the current command, wherein the user expected results include the existence of a feasible solution and the absence of a feasible solution; A composition module, used to obtain an abstract syntax tree according to the domain specific language, traverse the logic nodes of the abstract syntax tree, obtain the option sub-node combination under each logic node, and obtain the constraint conditions of each option sub-node combination according to the constraint conditions of each logic node, and form the option sub-node combination and the corresponding constraint conditions under each logic node into a pattern unit; A calculation module, used for performing combination calculation on the pattern units between the logic nodes to obtain a pattern unit combination; A verification module, used to verify the mode unit combination under the user constraint condition, obtain a verification result, and determine whether the verification result is consistent with the user expected result; A generating module, used for generating a command constructor of the current command based on the abstract syntax tree of the current command; Verifying the mode unit combination under the user constraint condition to obtain a verification result includes: Constructing a constraint tree for each mode unit combination according to the constraint of each mode unit combination and the user constraint; Performing AND or OR calculations on the constraints according to the constraint tree until the constraints in the pattern unit combination are numerical constraints; Verify whether there is a feasible solution for the numerical constraint condition under the mode unit combination, and obtain the verification result, wherein the verification result includes whether there is a feasible solution or not; The checking whether there is a feasible solution for the numerical constraint conditions under the mode unit combination includes: Constructing a numerical constraint condition tree according to the numerical constraint conditions of the pattern unit combination; Performing AND or OR calculations on the numerical constraints according to the numerical constraint tree to obtain an initial feasible solution; If all the values ​​of the initial feasible solution conflict, then the pattern unit combination has no feasible solution under the user constraints; if some of the values ​​of the initial feasible solution conflict or there is no value conflict, then the pattern unit combination has a feasible solution under the user constraints.

7. An electronic device, characterized in that: The invention comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is run by the processor, the method for generating a command constructor based on an abstract syntax tree according to any one of claims 1 to 5 is executed.

8. A computer-readable storage medium, characterized in that: The computer program stores a computer program, which executes the command constructor generation method based on an abstract syntax tree according to any one of claims 1 to 5 when running on a processor.

Citation Information

Patent Citations

  • Command configuration method and device for electronic automation design software, equipment and medium

    CN116911240A