Syntax Tree-Based Code Generation Method, Its Device, and Electronic Device

Through the syntax tree-based code generation method, business interaction logic code in low-code platforms is automatically generated, which solves the development efficiency and maintainability problems caused by manual input of logical code in the existing technology, and achieves more efficient and maintainable code generation.

CN115048104BActive Publication Date: 2025-06-27INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210675213.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-15
Publication Date
2025-06-27
Estimated Expiration
2042-06-15

AI Technical Summary

Technical Problem

When developing front-end pages, existing low-code platforms need to manually enter the logical code of interactive events, resulting in low development efficiency and poor maintenance.

Method used

The syntax tree-based code generation method is adopted, and the initial flowchart and logical arrangement requests are received, and the operation behavior is logically checked, the syntax tree structure is updated, and the target code is finally generated.

Benefits of technology

It realizes automatic generation of business interaction logic code, improves development efficiency, enhances code maintainability, and solves the efficiency and maintainability problems caused by manual input of logical code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115048104B_ABST
    Figure CN115048104B_ABST
Patent Text Reader

Abstract

The present invention discloses a code generation method, device, and electronic device based on a syntax tree, which relate to the field of fintech or other related fields. The generation method includes: receiving an initial flowchart and a logic orchestration request, converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy, performing a logic check on the operation behavior to obtain a check result, and updating the initial syntax tree structure to obtain a target syntax tree structure when the check result indicates that the operation behavior passes the logic check, and generating target code based on the target syntax tree structure. The present invention solves the technical problem in the related art that the logic code of the interaction event needs to be manually input, resulting in low development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of fintech, and in particular, to a code generation method, an apparatus, and an electronic device based on a syntax tree. Background Art

[0002] With the development of informatization, more and more business scenarios require the support of front-end development. Therefore, in order to improve development efficiency and lower the development threshold, low-code platform technology has emerged as the times require. Low-code platform technology constructs software through visual models and graphic design techniques, reducing the time and cost of front-end development.

[0003] In related technologies, when developing a front-end page, most low-code platforms use a visual view UI interface (i.e., user interface). After generating business code through the UI interface, it is necessary to manually input the logical code of interaction events, resulting in low development efficiency and poor maintainability.

[0004] In view of the above problems, no effective solution has been proposed yet. Summary of the Invention

[0005] Embodiments of the present invention provide a code generation method, an apparatus, and an electronic device based on a syntax tree, so as to at least solve the technical problem in related technologies that the logical code of interaction events needs to be manually input, resulting in low development efficiency.

[0006] According to one aspect of the embodiments of the present invention, a code generation method based on a syntax tree is provided, including: receiving an initial flowchart and a logic orchestration request, where the logic orchestration request carries at least: an operation behavior executed by an external terminal; converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree policy; performing a logic check on the operation behavior to obtain a check result, and updating the initial syntax tree structure to obtain a target syntax tree structure when the check result indicates that the operation behavior passes the logic check; generating target code based on the target syntax tree structure by using a preset generation policy, where the preset generation policy includes: a mapping relationship between keywords in the syntax tree structure and code representation forms.

[0007] Optionally, before receiving the initial flowchart and the logic orchestration request, it further includes: creating a logic orchestration interface, where the logic orchestration interface at least includes: a logic method definition area, a logic orchestration canvas, a logic component library, and an attribute configuration area. The logic method definition area is used to create and delete logic methods, the logic orchestration canvas is used to draw a flowchart of the logic method, the logic component library is used to define and display logic components, and the attribute configuration area is used to display and modify the component attributes of the logic components; listening for a logic creation request based on the logic method definition area.

[0008] Optionally, after the listening logic creation request, it further includes: when the logic creation request is monitored, receiving the logic creation request, where the logic creation request at least includes: logic data, and the logic data at least includes: logic name, input parameters, output parameters, preset variables; based on the logic data, determining a start node and an end node; based on the start node and the end node, controlling the logic orchestration canvas to draw the initial flowchart.

[0009] Optionally, before converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy, it further includes: determining a first syntax tree attribute of the logic method, where the first syntax tree attribute at least includes: a first syntax tree identifier, a logic method name, logic method input parameters, logic method output parameters, logic method preset variables, a logic method body, a logic method identifier; determining a second syntax tree attribute of the logic component, where the second syntax tree attribute includes: a component attribute and a component extension attribute, and the component attribute at least includes: a second syntax tree identifier, a logic component identifier, a parent node identifier, a logic component subtype, and the component extension attribute includes at least one of the following: a preset condition, a logic block, an identifier of a called logic method, input parameters of the called logic method, an operation symbol, an expression on the left side of the operation symbol, an expression on the right side of the operation symbol, a parameter type identifier, a parameter value; based on the first syntax tree attribute and the second syntax tree attribute, determining the preset syntax tree strategy.

[0010] Optionally, the step of converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy includes: based on the first syntax tree attribute, determining a first syntax tree representation corresponding to each parameter in the logic data; inserting the start node and the end node into the logic component array of the logic method body; based on the second syntax tree attribute, determining a second syntax tree representation of the start node and a third syntax tree representation of the end node; pointing the parent node identifier in the third syntax tree representation to the logic component identifier in the second syntax tree representation; based on the initial flowchart, combining the first syntax tree representation, the second syntax tree representation, and the third syntax tree representation to obtain the initial syntax tree structure.

[0011] Optionally, before receiving the initial flowchart and the logic orchestration request, it further includes: binding preset mouse events to the logic nodes in the logic orchestration canvas, where the preset mouse events include at least one of the following: mouse click event, mouse press event, mouse move event, mouse release event; capturing operation behaviors based on the preset mouse events, where the operation behaviors include at least one of the following: logic node moving in, logic node modification, logic node deletion; combining all the operation behaviors to obtain the logic orchestration request.

[0012] Optionally, in the case where the verification result indicates that the operation behavior passes the logic verification, the step of updating the initial syntax tree structure to obtain the target syntax tree structure includes: executing the logic orchestration request to draw the target flowchart; listening to the coordinate positions obtained from the operation behavior based on the preset mouse events; when the coordinate positions coincide with the connection positions in the target flowchart, performing semantic checks on the operation behavior, where the semantic checks include at least one of the following: checking whether the logical node types of the left and right operators dragged to the assignment logic node, comparison operation logic node, and logical operation logic node are consistent, checking whether the judgment condition logic element dragged to the conditional judgment logic node is a logical node of the true result or false result, checking whether the logical node dragged to the preset process is a logical node of the expression type; when the semantic check of the operation behavior passes, updating the initial syntax tree structure based on the target flowchart to obtain the target syntax tree structure.

[0013] Optionally, the step of generating the target code based on the target syntax tree structure by using a preset generation strategy includes: scanning the target syntax tree structure to obtain a scanning result; using the preset generation strategy to convert each key-value pair corresponding to the keyword in the scanning result into a code sub-fragment corresponding to the keyword in the code representation form; generating the target code based on all the code sub-fragments.

[0014] According to another aspect of the embodiments of the present invention, there is also provided a code generation device based on a syntax tree, including: a receiving unit, configured to receive an initial flowchart and a logic orchestration request, where at least the following is carried in the logic orchestration request: operation behaviors executed by an external terminal; a conversion unit, configured to convert the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy; an updating unit, configured to perform a logic verification on the operation behavior to obtain a verification result, and update the initial syntax tree structure to obtain a target syntax tree structure in the case where the verification result indicates that the operation behavior passes the logic verification; a generating unit, configured to generate a target code based on the target syntax tree structure by using a preset generation strategy, where the preset generation strategy includes: a mapping relationship between keywords in the syntax tree structure and the code representation form.

[0015] Optionally, the generating device further includes: a first creation module, configured to create a logic orchestration interface before receiving the initial flowchart and the logic orchestration request, where the logic orchestration interface at least includes: a logic method definition area, a logic orchestration canvas, a logic component library, and an attribute configuration area. The logic method definition area is used to create and delete logic methods. The logic orchestration canvas is used to draw the flowchart of the logic method. The logic component library is used to define and display logic components. The attribute configuration area is used to display and modify the component attributes of the logic components. A first monitoring module, configured to monitor logic creation requests based on the logic method definition area.

[0016] Optionally, the generating device further includes: a first receiving module, configured to receive the logic creation request when the logic creation request is monitored after monitoring the logic creation request, where the logic creation request at least includes: logic data, and the logic data at least includes: a logic name, input parameters, output parameters, and preset variables. A first determination module, configured to determine a start node and an end node based on the logic data. A first drawing module, configured to control the logic orchestration canvas to draw the initial flowchart based on the start node and the end node.

[0017] Optionally, the generating device further includes: a second determination module, configured to determine a first syntax tree attribute of the logic method before converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy, where the first syntax tree attribute at least includes: a first syntax tree identifier, a logic method name, logic method input parameters, logic method output parameters, logic method preset variables, a logic method body, and a logic method identifier. A third determination module, configured to determine a second syntax tree attribute of the logic component, where the second syntax tree attribute includes: component attributes and component extension attributes, and the component attributes at least include: a second syntax tree identifier, a logic component identifier, a parent node identifier, and a logic component subtype. The component extension attributes include at least one of the following: a preset condition, a logic block, an identifier of a called logic method, input parameters of the called logic method, an operation symbol, an expression on the left side of the operation symbol, an expression on the right side of the operation symbol, a parameter type identifier, and a parameter value. A fourth determination module, configured to determine the preset syntax tree strategy based on the first syntax tree attribute and the second syntax tree attribute.

[0018] Optionally, the conversion unit includes: a fifth determination module, configured to determine a first syntax tree representation corresponding to each parameter in the logical data based on the first syntax tree attribute; a first insertion module, configured to insert the start node and the end node into the logical element array of the logical method body; a sixth determination module, configured to determine a second syntax tree representation of the start node and a third syntax tree representation of the end node based on the second syntax tree attribute; a first pointing module, configured to point the parent node identifier in the third syntax tree representation to the logical element identifier in the second syntax tree representation; a first combination module, configured to combine the first syntax tree representation, the second syntax tree representation, and the third syntax tree representation based on the initial flow chart to obtain the initial syntax tree structure.

[0019] Optionally, the generating device further includes: a first binding module, configured to bind a preset mouse event to a logical node in the logical orchestration canvas before receiving the initial flow chart and the logical orchestration request, where the preset mouse event includes at least one of the following: a mouse click event, a mouse press event, a mouse move event, and a mouse release event; a first capture module, configured to capture an operation behavior based on the preset mouse event, where the operation behavior includes at least one of the following: a logical node moving in, a logical node modifying, and a logical node deleting; a second combination module, configured to combine all the operation behaviors to obtain the logical orchestration request.

[0020] Optionally, the updating unit includes: a first execution module, configured to execute the logical orchestration request to draw a target flow chart; a second monitoring module, configured to monitor the coordinate position obtained from the operation behavior based on the preset mouse event; a first checking module, configured to perform a semantic check on the operation behavior when the coordinate position coincides with the connection position in the target flow chart, where the semantic check includes at least one of the following: checking whether the logical node types of the left and right operators of the logical nodes dragged to the assignment logical node, the comparison operation logical node, and the logical operation logical node are consistent, checking whether the judgment condition logical element of the logical node dragged to the conditional judgment logical node is a logical node of a true result or a false result, and checking whether the logical node dragged to the preset process is a logical node of an expression type; a first updating module, configured to update the initial syntax tree structure based on the target flow chart to obtain a target syntax tree structure when the semantic check of the operation behavior passes.

[0021] Optionally, the generating unit includes: a first scanning module configured to scan the target syntax tree structure to obtain a scanning result; a first conversion module configured to convert, by using a preset generation strategy, each key-value pair corresponding to the keyword in the scanning result into a code sub-fragment in a code representation form corresponding to the keyword; and a first generating module configured to generate the target code based on all the code sub-fragments.

[0022] According to another aspect of the embodiments of the present invention, an electronic device is further provided, including one or more processors and a memory, where the memory is configured to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the above-described code generation method based on a syntax tree.

[0023] In the present disclosure, an initial flowchart and a logic orchestration request are received, the initial flowchart is converted into an initial syntax tree structure based on a preset syntax tree strategy, a logical check is performed on an operation behavior to obtain a check result, and when the check result indicates that the operation behavior passes the logical check, the initial syntax tree structure is updated to obtain a target syntax tree structure, and based on the target syntax tree structure, a preset generation strategy is adopted to generate a target code. In the present application, the operation behavior in the logic orchestration request can be logically checked first, and when the check passes, the initial syntax tree structure is updated, and based on the updated target syntax tree structure, a preset generation strategy is adopted to generate a target code, thereby implementing the function of automatically generating business interaction logic code, improving the development efficiency, enhancing the maintainability of the code, and further solving the technical problem in the related art that the logical code of interaction events needs to be manually input, resulting in low development efficiency. Description of the Drawings

[0024] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention. In the drawings:

[0025] Figure 1 is a flowchart of an optional code generation method based on a syntax tree according to an embodiment of the present invention;

[0026] Figure 2 is a schematic diagram of an optional initialization of a logical method into an initial syntax tree structure according to an embodiment of the present invention;

[0027] Figure 3 is a schematic diagram of an optional insertion into the main process of a logic flowchart according to an embodiment of the present invention;

[0028] Figure 4It is a schematic diagram of an optional branch process inserted into a logic flow chart according to an embodiment of the present invention;

[0029] Figure 5 It is a schematic diagram of an optional visual logic orchestration method in a low-code platform according to an embodiment of the present invention;

[0030] Figure 6 It is a schematic diagram of an optional code generation device based on a syntax tree according to an embodiment of the present invention;

[0031] Figure 7 It is a hardware structure block diagram of an electronic device (or mobile device) for a code generation method based on a syntax tree according to an embodiment of the present invention. Detailed implementation manners

[0032] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily need to be limited to those clearly listed steps or units, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0034] To facilitate the understanding of the present invention by those skilled in the art, some terms or nouns involved in the embodiments of the present invention are explained below:

[0035] Abstract Syntax Tree (AST for short): It is an abstract representation of the syntax structure of source code, representing the syntax structure of a programming language in a tree-like form, and each node on the tree represents a structure in the source code.

[0036] Low-code platform: A platform that can quickly complete application development through visual dragging with only a small amount of coding or even without coding.

[0037] Logical element: The constituent unit of logic, which in this application refers to the abstract unit of a programming language logical expression.

[0038] Visual logic orchestration: The process of generating logic code through the arrangement and combination of logical elements on a UI (User Interface) interface (i.e., the user interface).

[0039] It should be noted that the code generation method and device based on the syntax tree in this disclosure can be used in the field of fintech. In the case of generating code based on the syntax tree, it can also be used in any field other than the fintech field. In the case of generating code based on the syntax tree, the application field of the code generation method and device based on the syntax tree in this disclosure is not limited.

[0040] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set between this system and relevant users or institutions. Before obtaining relevant information, a request for acquisition needs to be sent to the aforementioned users or institutions through the interface, and after receiving the consent information feedback from the aforementioned users or institutions, the relevant information can be obtained.

[0041] The following embodiments of the present invention can be applied to various systems / applications / devices for generating code based on the syntax tree. In order to solve the problem that the low-code platform can only generate front-end interface code through the UI interface, cannot generate business interaction logic code or is difficult to comprehensively support the generation of business interaction logic code, resulting in low development efficiency of the low-code platform, the present invention proposes a method for realizing visual logic orchestration in a low-code scenario. The visual logic orchestration in the present invention can express the originally obscure code in the form of a flowchart, making the logic very intuitive, with higher readability and maintainability, and without worrying about the problems of non-standard comments and incomplete documents when taking over other people's projects. The logic graph generated by the logic orchestration is a natural product document, which can reduce the learning cost of application developers and improve work efficiency.

[0042] The present invention will be described in detail below in conjunction with each embodiment.

[0043] Embodiment 1

[0044] According to an embodiment of the present invention, there is provided an embodiment of a code generation method based on a syntax tree. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.

[0045] Figure 1 is a flowchart of an optional code generation method based on a syntax tree according to an embodiment of the present invention. As Figure 1 shown, the method includes the following steps:

[0046] Step S101, receive an initial flowchart and a logical orchestration request, where the logical orchestration request carries at least: an operation behavior executed by an external terminal.

[0047] Step S102, based on a preset syntax tree policy, convert the initial flowchart into an initial syntax tree structure.

[0048] Step S103, perform a logical check on the operation behavior to obtain a check result, and update the initial syntax tree structure to obtain a target syntax tree structure when the check result indicates that the operation behavior passes the logical check.

[0049] Step S104, based on the target syntax tree structure, adopt a preset generation policy to generate target code, where the preset generation policy includes: a mapping relationship between keywords in the syntax tree structure and code representation forms.

[0050] Through the above steps, an initial flowchart and a logical orchestration request can be received, the initial flowchart can be converted into an initial syntax tree structure based on a preset syntax tree policy, a logical check is performed on the operation behavior to obtain a check result, and when the check result indicates that the operation behavior passes the logical check, the initial syntax tree structure is updated to obtain a target syntax tree structure, and based on the target syntax tree structure, a preset generation policy is adopted to generate target code. In the embodiment of the present invention, the operation behavior in the logical orchestration request can be logically checked first. When the check passes, the initial syntax tree structure is updated, and based on the updated target syntax tree structure, a preset generation policy is adopted to generate target code, thereby realizing the function of automatically generating business interaction logic code, improving the development efficiency, enhancing the maintainability of the code, and further solving the technical problem in the related art that the logical code of interaction events needs to be manually input, resulting in low development efficiency.

[0051] The embodiments of the present invention will be described in detail below in combination with the above steps.

[0052] In an embodiment of the present invention, optionally, before receiving the initial flowchart and the logic orchestration request, it further includes: creating a logic orchestration interface, where the logic orchestration interface at least includes: a logic method definition area, a logic orchestration canvas, a logic component library, and an attribute configuration area. The logic method definition area is used to create and delete logic methods. The logic orchestration canvas is used to draw the flowchart of the logic method. The logic component library is used to define and display logic components. The attribute configuration area is used to display and modify the component attributes of the logic components; based on the logic method definition area, listen for logic creation requests.

[0053] In an embodiment of the present invention, the logic orchestration interface (i.e., a visual logic orchestration interface is displayed on the low-code platform) can be created first. The logic orchestration interface includes: a logic method definition area, a logic orchestration canvas, a logic component library, an attribute configuration area, etc. Among them,

[0054] The logic method definition area is an area for defining front-end business logic methods (a logic method corresponds to a function process). This logic method definition area supports the creation and deletion of logic methods, and the display of defined logic methods. In this embodiment, when creating a logic method, the definition process of a logic method includes: defining the logic method name, defining input parameters, defining output parameters, defining local variables, etc. In addition, the logic method definition area also provides a reference search function for logic methods, that is, to find which logic methods or interface UI components reference a logic method.

[0055] The logic orchestration canvas is an area for drawing the internal flowchart of the front-end business logic method. In this logic orchestration canvas, draw the connection lines between logic components and logic components to form the flowchart of the logic method, display the logic orchestration effect, and automatically generate the description structure of the logic method (i.e., the corresponding AST syntax tree structure).

[0056] The logic component library is an area for defining and displaying logic components. This logic component library can display logic components in a visual form. Drag logic components from this logic component library to the logic orchestration canvas to implement the drawing of the logic method flowchart.

[0057] The attribute configuration area is an area for displaying and modifying the attributes of logic components.

[0058] In this embodiment, the behavior of creating a logic method can be listened for in the logic method definition area of the low-code platform (i.e., based on the logic method definition area, listen for logic creation requests).

[0059] Optionally, after the logic creation request is monitored, it further includes: when the logic creation request is monitored, receiving the logic creation request, where the logic creation request at least includes: logic data, and the logic data at least includes: logic name, input parameters, output parameters, preset variables; based on the logic data, determining a start node and an end node; based on the start node and the end node, controlling the logic orchestration canvas to draw an initial flow chart.

[0060] In an embodiment of the present invention, when a behavior of creating a logic method is monitored in the logic method definition area of the low-code platform (i.e., when the logic creation request is monitored), the low-code platform receives the logic method initialization data through a visual interaction window (i.e., receives the logic creation request, and the logic creation request at least includes: logic data, and the logic data at least includes: logic name, input parameters, output parameters, preset variables, etc.). After the low-code platform obtains the logic data, it can perform an initialization operation to generate and initialize the flow chart of the logic method. Specifically, it can first determine the start node and the end node based on the logic data, and then, based on the start node and the end node, control the logic orchestration canvas to draw the initial flow chart. The initial flow chart includes two logic nodes: the start node and the end node, and the start node and the end node are connected by a connection line.

[0061] Optionally, before receiving the initial flow chart and the logic orchestration request, it further includes: binding preset mouse events to the logic nodes in the logic orchestration canvas, where the preset mouse events include at least one of the following: mouse click event, mouse press event, mouse move event, mouse release event; based on the preset mouse events, capturing operation behaviors, where the operation behaviors include at least one of the following: logic node moving in, logic node modification, logic node deletion; combining all the operation behaviors to obtain a logic orchestration request.

[0062] In an embodiment of the present invention, preset mouse events (the preset mouse events include: mouse click event, mouse press event, mouse move event, mouse release event, etc.) can be first bound to the logic nodes in the logic orchestration canvas (in this embodiment, when a logic element is dragged into the logic orchestration canvas, the logic element can be represented as a logic node). Through these preset mouse events, the operation behaviors of the user (the operation behaviors of the user include: logic node moving in, logic node modification, logic node deletion, etc.) are captured, and then, all the operation behaviors are combined to obtain a logic orchestration request.

[0063] Step S101, receiving the initial flow chart and the logic orchestration request, where the logic orchestration request at least carries: the operation behaviors executed by an external terminal.

[0064] In an embodiment of the present invention, an initial flowchart and a logic orchestration request may be received first. The logic orchestration request carries at least: operation behaviors executed by an external terminal (such as a computer, a mobile terminal, etc.).

[0065] Optionally, before converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy, it further includes: determining a first syntax tree attribute of a logic method, where the first syntax tree attribute at least includes: a first syntax tree identifier, a logic method name, logic method input parameters, logic method output parameters, logic method preset variables, a logic method body, a logic method identifier; determining a second syntax tree attribute of a logic element, where the second syntax tree attribute includes: an element attribute and an element extension attribute, and the element attribute at least includes: a second syntax tree identifier, a logic element identifier, a parent node identifier, a logic element subtype, and the element extension attribute includes at least one of the following: a preset condition, a logic block, an identifier of a called logic method, input parameters of the called logic method, an operation symbol, an expression on the left side of the operation symbol, an expression on the right side of the operation symbol, a parameter type identifier, a parameter value; determining a preset syntax tree strategy based on the first syntax tree attribute and the second syntax tree attribute.

[0066] In an embodiment of the present invention, an AST syntax tree is a data structure in a preset form (such as a JSON form). Both a logic method and a logic element can be represented by a preset object (such as a JSON object). In this embodiment, the preset object is a data structure enclosed in a pair of curly braces and containing multiple key-value pairs. The key-value pairs of the preset object are used to represent the attribute values of the logic method or the logic element. In the AST syntax tree, the key of the key-value pair of the preset object is represented by a string, and the value (val) is represented by a preset object, an array, a number, a string, or other literals (such as a boolean value, a null value, etc.). Moreover, the key can be used to represent the attribute name of the logic method or the logic element, and the value can be used to represent the specific attribute value (the attribute value can be an internal preset object).

[0067] In an embodiment of the present invention, the first syntax tree attribute of the logical method (i.e., the AST syntax tree attribute of the logical method) may be determined first. The first syntax tree attribute at least includes: (1) AST syntax tree identifier (i.e., the first syntax tree identifier), which can be represented by the string "logic" to indicate that this AST syntax tree is a syntax tree representing a logical method; (2) logical method name, which can be represented by the name string of the logical method; (3) logical method input parameters: the input parameters of a logical method can be zero or more, represented by an array, and a preset object can be used to represent a custom input parameter type; (3) logical method output parameters: the output parameters of a logical method can be zero or more, represented in an array form, and a preset object can be used to represent a custom output parameter type; (5) logical method preset variables (i.e., logical method local variables): the local variables of a logical method can be zero or more, represented in an array form, and a preset object can be used to represent a custom local variable type; (6) logical method body: a logical method is composed of multiple logical elements, represented in an array form, and the array elements correspond to the AST syntax trees of the logical elements; (7) logical method identifier ID: the unique identifier of the logical method; (8) other attributes: the logical method may also include other attributes, such as trigger type (click, double-click, etc.), creation time, whether it is editable, etc.

[0068] In an embodiment of the present invention, the AST syntax tree of a logical element is an abstraction of code expression statements. The expressions include: logical expressions (such as conditional judgment, loop, routing jump, logical call, interface call, assignment, message prompt, log output, code block (such as JS code block), etc.), atomic terms (such as boolean value, number, string, variable, built-in function (such as tool functions implemented by the platform), etc.), arithmetic operations (addition, subtraction, multiplication, division, remainder, etc.), comparison operations (equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to, etc.), logical operations (and, or, not, etc.).

[0069] Embodiments of the present invention can determine the second syntax tree attribute of a logic element (i.e., the attribute of the AST syntax tree of the logic element), and the second syntax tree attribute includes: element attributes (i.e., the basic attributes of the element) and element extension attributes. The basic attributes of the AST syntax tree of the logic element include: (1) AST syntax tree identifier (i.e., the second syntax tree identifier), which can be represented by the string "logicUnit" to indicate that this AST syntax tree is a syntax tree representing a logic element; (2) Logic element identifier ID: The unique identifier of the logic element; (3) Parent node identifier ID: In the flowchart of the logic method, generally, there is another logic element in the previous position of a logic element (except for the logic element at the start position), and it is connected to it, which is called the parent node of the logic element, and the parent node identifier ID is recorded here; (4) Logic element subtype: Used to distinguish different types of logic elements, and the types of logic elements include conditional judgment, loop, comparison operation, etc.; (6) Other attributes: including logic element name, whether it is editable, position coordinates (coordinates in the logic layout canvas), etc.

[0070] In this embodiment, the element extension attributes include: preset conditions (such as judgment conditions, loop conditions, etc.), logic blocks, called logic method identifiers, called logic method input parameters, operation symbols, expressions on the left side of the operation symbol, expressions on the right side of the operation symbol, parameter type identifiers, parameter values, etc. The following will illustrate the extended attributes of the AST syntax tree of logic elements in terms of types such as conditional judgment, loop, call logic, assignment, arithmetic operation, comparison operation, and logical operation:

[0071] The extended attributes of the AST syntax tree of the conditional judgment logic element include: (1) Judgment condition: an atomic type of "true or false", or an expression with a value of "true or false"; (2) Logic block executed when the condition is "true" (an array of logic elements, and these logic elements are associated through the parent node identifier); (3) Logic block executed when the condition is "false".

[0072] The extended attributes of the AST syntax tree of the loop expression logic element include: (1) Loop condition, used to control the loop; (2) Logic block executed within the loop.

[0073] The extended attributes of the AST syntax tree of the call expression logic element include: (1) Logic method identifier of the called logic method; (2) Input parameter of the called logic method.

[0074] The extended attributes of the AST syntax tree of assignment expressions, arithmetic operations, comparison operations, and logical operation logic elements include: (1) operation symbols: assignment (=), arithmetic operations (addition (+), subtraction (-), multiplication (*), division ( / ), remainder (%)), comparison operations (equal (==), not equal (!=), greater than (>), greater than or equal to (>=), less than (<), less than or equal to (<=)), logical operations (and (&&), or (||), not (!)), etc.; (2) the expression on the left side of the operation symbol; (3) the expression on the right side of the operation symbol.

[0075] The extended attributes of the AST syntax tree of numeric type logic elements include: (1) type identifiers: integer type, floating point type, etc.; (2) specific parameter values.

[0076] Then, based on the first syntax tree attribute and the second syntax tree attribute, a preset syntax tree strategy can be determined (for example, converting logical data into a syntax tree representation according to the corresponding syntax tree attributes).

[0077] Step S102, convert the initial flowchart into an initial syntax tree structure based on the preset syntax tree strategy.

[0078] Optionally, the step of converting the initial flowchart into an initial syntax tree structure based on the preset syntax tree strategy includes: determining the first syntax tree representation corresponding to each parameter in the logical data based on the first syntax tree attribute; inserting the start node and the end node into the logical element array of the logical method body; determining the second syntax tree representation of the start node and the third syntax tree representation of the end node based on the second syntax tree attribute; pointing the parent node identifier in the third syntax tree representation to the logical element identifier in the second syntax tree representation; combining the first syntax tree representation, the second syntax tree representation, and the third syntax tree representation based on the initial flowchart to obtain the initial syntax tree structure.

[0079] In the embodiments of the present invention, the first syntax tree representation corresponding to each parameter in the logical data can be determined based on the first syntax tree attribute, and the start node and the end node can be inserted into the logical element array of the logical method body. After that, the second syntax tree representation of the start node and the third syntax tree representation of the end node can be determined based on the second syntax tree attribute, and the parent node identifier of the end node is pointed to the logical element identifier of the start node (that is, the parent node identifier in the third syntax tree representation is pointed to the logical element identifier in the second syntax tree representation). Then, the first syntax tree representation, the second syntax tree representation, and the third syntax tree representation can be combined to obtain the initial syntax tree structure.

[0080] Figure 2 is a schematic diagram of an optional initialization of a logical method to an initial syntax tree structure according to an embodiment of the present invention, as Figure 2As shown, it includes: a logic method flow chart and an initialized logic method AST syntax tree. Among them, the logic method flow chart includes: two nodes, start and end. The logic method flow chart can be converted into an initialized logic method AST syntax tree. Specifically, first construct an initialized AST syntax tree for the logic method. This initialized AST syntax tree for the logic method includes, within a pair of curly braces: AST syntax tree identifier: 'logic', ID identifier: XXX, logic method name: XXX, logic method input parameters: [XXX], logic method output parameters: [XXX], logic method local variables: [XXX], logic method body: [start logic node AST syntax tree, end logic node AST syntax tree], etc. Among them, the start logic node AST syntax tree includes, within a pair of curly braces: AST syntax tree identifier: 'logicUnit', ID identifier: XXX, parent node ID identifier: '', logic component subtype:'start', etc. The end logic node AST syntax tree includes, within a pair of curly braces: AST syntax tree identifier: 'logicUnit', ID identifier: XXX, parent node ID identifier: XXX, logic component subtype: 'end', etc.

[0081] In an embodiment of the present invention, in the AST syntax tree of the logic method, multiple attributes are represented by key-value pairs kv. For example, the logic method name, logic method input parameters, logic method output parameters, etc. It may also include a key attribute: the logic method body. The logic method body contains two nodes: a start node and an end node, which can be represented by a preset object inside. The start node and the end node use kv to represent their respective attribute contents.

[0082] Step S103: Perform a logic check on the operation behavior to obtain a check result. And when the check result indicates that the operation behavior passes the logic check, update the initial syntax tree structure to obtain a target syntax tree structure.

[0083] Optionally, the step of updating the initial syntax tree structure to obtain a target syntax tree structure when the check result indicates that the operation behavior passes the logic check includes: executing a logic orchestration request to draw a target flow chart; listening for the coordinate position obtained from the operation behavior based on a preset mouse event; when the coordinate position coincides with the connection position in the target flow chart, perform a semantic check on the operation behavior. Among them, the semantic check includes at least one of the following: checking whether the logic node types of the left and right operators of the logic nodes dragged to the assignment logic node, comparison operation logic node, and logical operation logic node are consistent, checking whether the judgment condition logic component of the logic node dragged to the conditional judgment logic node is a logic node of a true result or a false result, checking whether the logic node dragged to a preset process is a logic node of an expression type; when the semantic check of the operation behavior passes, update the initial syntax tree structure based on the target flow chart to obtain a target syntax tree structure.

[0084] In an embodiment of the present invention, a logical orchestration request can be executed, a target flow chart can be drawn, and the coordinate positions obtained by listening to operation behaviors can be monitored based on preset mouse events. For example, for the movement of a logical node in a logical orchestration request, within the area where the logical component library is located, when a user clicks on a logical component icon with the mouse, when the logical component detects a mouse press event, the logical node is created and its AST syntax tree is initialized. Then, as the user drags the logical node to the area where the logical orchestration canvas is located, the real-time coordinate position of the mouse is monitored through a mouse movement event. At the real-time coordinate position of the logical orchestration canvas, a virtual portrait of the logical node is drawn. Thus, the corresponding target flow chart can be drawn according to the operation behaviors in the logical orchestration request, and the coordinate positions obtained by listening to the operation behaviors can be monitored through preset mouse events. After that, when the mouse is released, the release behavior is monitored through a mouse release event for logical verification. The content of the logical verification includes: (1) detecting whether the current mouse coordinate position coincides with the connection position in the logical flow chart (i.e., the target flow chart); (2) in the case where the coordinate position coincides with the connection position in the target flow chart, semantic checking is performed on the operation behavior (i.e., checking whether the nested logical semantics of the operation behavior is legal). The process of checking the legality of nested semantics is as follows:

[0085] (1) Check whether the logical node types of the left and right operators dragged to the assignment logical node, comparison operation logical node, and logical operation logical node are consistent. For example, for the assignment logical node: a = 1, the right side of the "=" operator is of the numeric type. If the logical node a is of the numeric type, it is legal; if the logical node a is of the string type, it is illegal. For the comparison operation logical node: 3 > 2, both sides of the ">" operator are of the numeric type, so it is legal; for 'a' > 1, the left side of the ">" operator is of the string type and the right side is of the numeric type, so it is illegal.

[0086] (2) The judgment condition logical component dragged to the condition judgment logical node must be a logical node with a result of "true" or "false" (i.e., checking whether the judgment condition logical component dragged to the condition judgment logical node is a logical node with a true result or a false result). For example, dragging a boolean value logical node, comparison operation logical node, or logical operation logical node to the judgment condition position of the condition judgment logical node is legal; dragging a loop logical node or condition judgment logical node, etc., to the judgment condition position of the condition judgment logical node is illegal.

[0087] (3) The logic node dragged to the main flow of the logic method must be an expression type logic node (i.e., check whether the logic node dragged to the preset flow is an expression type logic node, and the preset flow is the main flow). For example, it is legal to drag a conditional judgment logic node, a loop logic node, or a call expression logic node to the main flow of the logic method; it is illegal to drag a Boolean logic node, a digital logic node, or a string logic node to the main flow of the logic method.

[0088] When the semantic check of the operation behavior passes, a visualization graph corresponding to the logic node can be drawn at the mouse position, and based on the target flow chart, the initial syntax tree structure is updated to obtain the target syntax tree structure.

[0089] Alternatively, moving the logic node includes at least one of the following: inserting the logic node into the main process, inserting the logic node into the branch process, wherein inserting the logic node into the main process is inserting the syntax tree representation of the logic node into the array of the logic method body of the syntax tree structure, and inserting the logic node into the branch process is inserting the syntax tree representation of the logic node into the branch attribute of the branch syntax tree structure corresponding to the current logic node.

[0090] In this embodiment, there are two insertion scenarios in the process of moving the logic node: (1) inserting the logic node into the main process of the logic method flowchart; (2) inserting the logic node into the branch process of the logic flowchart, where:

[0091] The main process of inserting into the logic flow chart is: if the logic node is dragged into the main process of the logic method flow chart, the AST syntax tree of the logic node is inserted into the logic method body array of the logic method AST syntax tree.

[0092] Figure 3 is a schematic diagram of a main process optionally inserted into a logic flow chart according to an embodiment of the present invention, such as Figure 3As shown in the figure, it includes a logic flow chart and a logical method AST syntax tree. Among them, the logic flow chart includes two nodes: start and end, and conditional branch nodes (including two conditions: yes and no) inserted into the main process. The logic flow chart can be converted into a logical method AST syntax tree. Specifically, first construct a logical method AST syntax tree, which includes in a pair of curly braces: AST syntax tree identifier: 'logic', ID identifier: XXX, logical method name: XXX, logical method input parameters: [XXX], logical method output parameters: [XXX], logical method local variables: [XXX], logical method body: [start logic node AST syntax tree,..., conditional judgment logic node AST syntax tree,..., end logic node AST syntax tree], etc. Among them, the conditional judgment logic node AST syntax tree includes in a pair of curly braces: judgment condition: {XXX}, logical block executed when the condition is "true": {XXX}, logical block executed when the condition is "false": {XXX}, type identifier: "ifStatement", etc.

[0093] In this embodiment, if the conditional judgment logic node is dragged into the main process of the logic method flow chart, the AST syntax tree of the conditional branch logic node is inserted into the logical method body array of the logical method AST syntax tree. The logical method body contains three nodes: start node, conditional judgment node, and end node. Among them, the conditional judgment can be represented by a preset object inside, and the attribute content is represented in the kv form.

[0094] The branch process inserted into the logic flow chart is as follows: If the logic node is dragged onto a logic node with a branch in the logic method flow chart, the AST syntax tree of the dragged logic node is inserted into the corresponding branch attribute of the current branch logic node AST syntax tree.

[0095] Figure 4 It is a schematic diagram of an optional branch process inserted into the logic flow chart according to an embodiment of the present invention, as Figure 4As shown, it includes: a logic flow chart and a logic method AST syntax tree. Among them, the logic flow chart includes: two nodes, start and end, and in the inserted branch process (that is, the assignment expression when the conditional judgment "1 == 3" is true, and the call expression when it is false), the logic flow chart can be converted into a logic method AST syntax tree. Specifically, first construct a logic method AST syntax tree. This logic method AST syntax tree includes in a pair of curly braces: AST syntax tree identifier: 'logic', ID identifier: XXX, logic method name: XXX, logic method input parameters: [XXX], logic method output parameters: [XXX], logic method local variables: [XXX], logic method body: [start logic node AST syntax tree,..., conditional judgment logic node AST syntax tree,..., end logic node AST syntax tree], etc. Among them, the conditional judgment logic node AST syntax tree includes in a pair of curly braces: judgment condition: {XXX}, logic block executed when the condition is "true": assignment expression logic node AST, logic block executed when the condition is "false": call expression logic node AST, type identifier: "ifStatement", etc. The assignment expression logic node AST syntax tree includes in a pair of curly braces: operator: "=", expression on the left side of the operator: {XXX}, expression on the right side of the operator: {XXX}, type identifier: "BinaryExpression", etc. The call expression logic node AST syntax tree includes in a pair of curly braces: ID identifier of the called logic method: {XXX}, input parameters of the called logic method: {XXX}, etc.

[0096] In this embodiment, if the assignment expression logic node is dragged to the branch where the judgment condition of the conditional judgment logic node in the logic method flow chart is "true", then insert the AST syntax tree of the assignment expression logic node into the attribute of the logic block executed when the condition of the conditional judgment AST syntax tree is "true". Among them, the assignment expression can be represented by a preset object inside, and the attribute content is represented in the kv form. If the call expression logic node is dragged to the branch where the judgment condition of the conditional judgment logic node in the logic method flow chart is "false", then insert the AST syntax tree of the call expression logic node into the attribute of the logic block executed when the condition of the conditional judgment AST syntax tree is "false". Among them, the call expression can be represented by a preset object inside, and the attribute content is represented in the kv form.

[0097] In this embodiment, when the operation behavior is a logic node modification behavior, in the logic orchestration canvas area, when the logic node detects a mouse click event, display the logic component attribute configuration area interface. The user can modify the attribute values of the logic node on this interface. When an attribute value is changed, the platform internally modifies the attribute value corresponding to the current logic node AST syntax tree in the logic method AST syntax tree.

[0098] In this embodiment, when the operation behavior is a logical node deletion behavior, in the logical orchestration canvas area, when a logical node detects a mouse click event, a delete button is displayed. The delete button is bound to a delete event listening method. When the user clicks to delete, the delete event detects the deletion behavior, and then the platform will internally delete the AST syntax tree of the logical node from the AST syntax tree of the logical method.

[0099] In this embodiment, according to the user's operation behavior, an AST syntax tree of a logical method can be generated, and while the AST syntax tree is updated, it is persistently stored.

[0100] Step S104: Based on the target syntax tree structure, adopt a preset generation strategy to generate target code, where the preset generation strategy includes: the mapping relationship between the keywords in the syntax tree structure and the code representation form.

[0101] Optionally, the step of generating target code based on the target syntax tree structure and adopting a preset generation strategy includes: scanning the target syntax tree structure to obtain a scanning result; adopting the preset generation strategy to convert each key-value pair corresponding to a keyword in the scanning result into a code sub-fragment corresponding to the code representation form of the keyword; and generating target code based on all the code sub-fragments.

[0102] In the embodiment of the present invention, after the logical orchestration is completed, an AST syntax tree of a complete logical method (i.e., the target syntax tree structure) is obtained. The attributes of the AST syntax tree of the logical method completely describe the definition of a method in a preset programming language (such as JavaScript) (such as method name, method input parameters, method output parameters, local variables, method body), etc. The logical method body contains multiple logical nodes. The following is an illustration through an example:

[0103] The following is an AST syntax tree generated through visual logical orchestration on a low-code platform. It contains a logical method (a method named "compare") and a logical node (conditional judgment type). There is an input parameter "a" of type "int" and a return variable "b" of type "Boolean" in the logical method. "test" represents the judgment condition of the conditional judgment logical node (represented by a preset object), and "conse" and "alter" respectively represent the expressions executed when the conditional judgment is "false" (represented by an array of preset objects) and the expressions executed when the conditional judgment is "true" (represented by an array of preset objects).

[0104] In an embodiment of the present invention, a preset generation strategy can be adopted (the preset generation strategy includes: the mapping relationship between keywords in the syntax tree structure and the code representation form, where the keywords include: "level", "name", "variables", "returns", "body", "type", "test", "conse", etc., and each keyword corresponds to a code representation form), to convert the target syntax tree structure into target code. Specifically: The AST syntax tree can be scanned from top to bottom (i.e., scan the target syntax tree structure to obtain the scan result). When "level": "logic" is read during the scan, it indicates that this AST is a logical method, and "function(){}" is generated. Continuing to read "name": "compare", it indicates that the name of this logical method is "compare", and "function compare(){}" is generated. Continuing to read the attribute "variables": [{"value": a, "valueType": "int"}], according to "variables", it is determined that the attribute value [{"value": a, "valueType": "int"}] is the definition of the input parameters of the logical method, and the code "function compare(a){}" is generated. Continuing to read the attribute "returns": [{"value": b, "valueType": "Boolean", "default": null}], according to "returns", it is determined that the attribute value [{"value": b, "valueType": "Boolean", "default": null}] is the definition of the output parameters of the logical method, and the code "function compare(a){return b = null}" is generated. Continuing to read the value of the attribute "body", according to "body", it is determined that the attribute value is the body of the logical method, which contains the logical nodes that make up the logical method. Traverse the logical nodes in the body attribute value. When "level": "logicUnit" is read, it indicates that this AST is a logical node. When "type": "IfStatement" is read, it indicates that this logical node is an IF conditional judgment logical node, and "function compare(a){if(){}else{}return b = null}" is generated. Continuing to read the attribute "test": {"......"}, it indicates that this attribute value is the conditional judgment statement of the conditional judgment logical node, and "function compare(a){if(a>12){}else{}return b = null}" is generated. Continuing to read the attribute "conse": ["......"], indicating that the attribute value is the IF branch code block of the conditional judgment logic node, generating "function compare(a){b = null; if(a > 12){b = false}else{}return b}", and continue to read the attribute "conse": ["......"], indicating that the attribute value is the IF branch code block of the conditional judgment logic node, generating "function compare(a){b = null; if(a > 12){b = false}else{b = true}return b}". After scanning the "body" array of the logical method, the preset programming language (e.g., javaScript) function generation is completed (i.e., converting each key-value pair corresponding to the keyword in the scanning result into a code sub-fragment corresponding to the keyword in the code representation form, and generating the target code based on all code sub-fragments).

[0105] The following will be described in detail in conjunction with another optional specific implementation manner.

[0106] Figure 5 It is a schematic diagram of an optional visual logic orchestration method in a low-code platform according to an embodiment of the present invention, as Figure 5 shown, including the following steps:

[0107] Step 1: The low-code platform visual logic orchestration interface is displayed. The logic orchestration interface includes: a logic method definition area, a logic orchestration canvas, a logic component library, an attribute configuration area, etc.

[0108] Step 2: The AST syntax tree representation of the logic method and logic components.

[0109] Step 3: Logic orchestration initialization. First, a logic can be created, and an initialization logic flow chart can be drawn in the logic orchestration canvas area to generate a logic initialization AST syntax tree.

[0110] Step 4: Logic orchestration interactive execution. First, respond to user UI interaction operations, execute logic orchestration, draw the flow chart of the logic method, and update the logic method AST syntax tree.

[0111] Step 5: Convert the AST syntax tree to JavaScript code. The obtained complete AST syntax tree of the logic method can be converted into JavaScript code.

[0112] Step 6: Logic preview.

[0113] In this embodiment, the low-code platform can provide visual UI interface orchestration capabilities, be able to drag and generate an application UI interface, and the generated logic method code can be bound to the interface UI component events to achieve the preview effect of logic orchestration.

[0114] In the embodiments of the present invention, it can fully support the generation of business logic code, improve the development efficiency of the low-code platform, and can perform legal checks on the user's operation behavior, reduce the threshold for developers to use, further improve the developer's usage efficiency, and avoid misoperations.

[0115] Embodiment Two

[0116] A code generation device based on a syntax tree provided in this embodiment includes multiple implementation units, and each implementation unit corresponds to each implementation step in the first embodiment above.

[0117] Figure 6 It is a schematic diagram of an optional code generation device based on a syntax tree according to an embodiment of the present invention, as Figure 6 shown. The generation device may include: a receiving unit 60, a conversion unit 61, an updating unit 62, and a generating unit 63, where

[0118] The receiving unit 60 is configured to receive an initial flowchart and a logic orchestration request, where the logic orchestration request carries at least: the operation behavior executed by an external terminal;

[0119] The conversion unit 61 is configured to convert the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy;

[0120] The updating unit 62 is configured to perform logical verification on the operation behavior to obtain a verification result, and update the initial syntax tree structure to obtain a target syntax tree structure when the verification result indicates that the operation behavior passes the logical verification;

[0121] The generating unit 63 is configured to generate target code based on the target syntax tree structure by using a preset generation strategy, where the preset generation strategy includes: the mapping relationship between the keywords in the syntax tree structure and the code representation form.

[0122] The above-mentioned generation device can receive an initial flowchart and a logic orchestration request through a receiving unit 60, convert the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy through a conversion unit 61, perform a logical check on the operation behavior through an updating unit 62 to obtain a check result, and update the initial syntax tree structure to obtain a target syntax tree structure when the check result indicates that the operation behavior passes the logical check, and generate target code based on the target syntax tree structure through a generating unit 63 using a preset generation strategy. In the embodiment of the present invention, the operation behavior in the logic orchestration request can be logically checked first. When the check passes, the initial syntax tree structure is updated, and target code is generated through the updated target syntax tree structure using a preset generation strategy, thereby realizing the function of automatically generating business interaction logic code, improving the development efficiency, enhancing the maintainability of the code, and further solving the technical problem in the related art that the logical code of interaction events needs to be manually input, resulting in low development efficiency.

[0123] Optionally, the generation device further includes: a first creation module, configured to create a logic orchestration interface before receiving the initial flowchart and the logic orchestration request, where the logic orchestration interface at least includes: a logic method definition area, a logic orchestration canvas, a logic component library, and an attribute configuration area. The logic method definition area is used to create and delete logic methods, the logic orchestration canvas is used to draw the flowchart of the logic method, the logic component library is used to define and display logic components, and the attribute configuration area is used to display and modify the component attributes of the logic components; a first listening module, configured to listen for a logic creation request based on the logic method definition area.

[0124] Optionally, the generation device further includes: a first receiving module, configured to receive a logic creation request when the logic creation request is monitored after monitoring the logic creation request, where the logic creation request at least includes: logic data, and the logic data at least includes: a logic name, input parameters, output parameters, and preset variables; a first determination module, configured to determine a start node and an end node based on the logic data; a first drawing module, configured to control the logic orchestration canvas to draw an initial flowchart based on the start node and the end node.

[0125] Optionally, the generating device further includes: a second determination module, configured to determine a first syntax tree attribute of the logical method before converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy, where the first syntax tree attribute at least includes: a first syntax tree identifier, a logical method name, logical method input parameters, logical method output parameters, logical method preset variables, a logical method body, and a logical method identifier; a third determination module, configured to determine a second syntax tree attribute of the logical element, where the second syntax tree attribute includes: an element attribute and an element extension attribute, and the element attribute at least includes: a second syntax tree identifier, a logical element identifier, a parent node identifier, and a logical element subtype, and the element extension attribute includes at least one of the following: a preset condition, a logical block, an identifier of the called logical method, input parameters of the called logical method, an operation symbol, an expression on the left side of the operation symbol, an expression on the right side of the operation symbol, a parameter type identifier, and a parameter value; a fourth determination module, configured to determine the preset syntax tree strategy based on the first syntax tree attribute and the second syntax tree attribute.

[0126] Optionally, the conversion unit includes: a fifth determination module, configured to determine a first syntax tree representation corresponding to each parameter in the logical data based on the first syntax tree attribute; a first insertion module, configured to insert a start node and an end node into the logical element array of the logical method body; a sixth determination module, configured to determine a second syntax tree representation of the start node and a third syntax tree representation of the end node based on the second syntax tree attribute; a first pointing module, configured to point the parent node identifier in the third syntax tree representation to the logical element identifier in the second syntax tree representation; a first combination module, configured to combine the first syntax tree representation, the second syntax tree representation, and the third syntax tree representation based on the initial flowchart to obtain an initial syntax tree structure.

[0127] Optionally, the generating device further includes: a first binding module, configured to bind a preset mouse event to a logical node in the logical orchestration canvas before receiving the initial flowchart and the logical orchestration request, where the preset mouse event includes at least one of the following: a mouse click event, a mouse press event, a mouse move event, and a mouse release event; a first capture module, configured to capture an operation behavior based on the preset mouse event, where the operation behavior includes at least one of the following: a logical node moving in, a logical node modification, and a logical node deletion; a second combination module, configured to combine all the operation behaviors to obtain a logical orchestration request.

[0128] Optionally, the update unit includes: a first execution module for executing a logic orchestration request and drawing a target flow chart; a second monitoring module for monitoring the coordinate position obtained from an operation behavior based on a preset mouse event; a first checking module for performing semantic checking on the operation behavior when the coordinate position coincides with the connection position in the target flow chart, where the semantic checking includes at least one of the following: checking whether the logical node types of the left and right operators dragged to an assignment logic node, a comparison operation logic node, and a logical operation logic node are consistent, checking whether the judgment condition logic element dragged to a conditional judgment logic node is a logical node of a true result or a false result, and checking whether the logical node dragged to a preset process is a logical node of an expression type; a first update module for updating the initial syntax tree structure based on the target flow chart to obtain a target syntax tree structure when the semantic checking of the operation behavior passes.

[0129] Optionally, the generation unit includes: a first scanning module for scanning the target syntax tree structure to obtain a scanning result; a first conversion module for converting each key-value pair corresponding to a keyword in the scanning result into a code sub-fragment corresponding to the keyword in a code representation form by using a preset generation strategy; a first generation module for generating target code based on all the code sub-fragments.

[0130] The above-mentioned generation device may further include a processor and a memory. The above-mentioned receiving unit 60, conversion unit 61, update unit 62, generation unit 63, etc. are all stored in the memory as program units, and the corresponding functions are implemented by the processor executing the above program units stored in the memory.

[0131] The above-mentioned processor includes a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels may be set, and by adjusting the kernel parameters, target code is generated based on the target syntax tree structure by using a preset generation strategy.

[0132] The above-mentioned memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of, for example, read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.

[0133] The present application further provides a computer program product, which when executed on a data processing device, is adapted to execute a program initialized with the following method steps: receiving an initial flow chart and a logic orchestration request, converting the initial flow chart into an initial syntax tree structure based on a preset syntax tree strategy, performing logical verification on an operation behavior to obtain a verification result, and updating the initial syntax tree structure to obtain a target syntax tree structure when the verification result indicates that the operation behavior passes the logical verification, and generating target code based on the target syntax tree structure by using a preset generation strategy.

[0134] According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including one or more processors and a memory. The memory is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the above-mentioned code generation method based on a syntax tree.

[0135] Figure 7 FIG. 5 is a hardware structural block diagram of an electronic device (or mobile device) for a code generation method based on a syntax tree according to an embodiment of the present invention. As Figure 7 shown, the electronic device may include one or more processors 702 (shown as 702a, 702b,..., 702n in the figure) (the processor 702 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 704 for storing data. In addition, it may further include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply, and / or a camera. Those of ordinary skill in the art can understand that Figure 7 the structure shown in FIG. 5 is only schematic and does not limit the structure of the above-mentioned electronic device. For example, the electronic device may further include more or fewer components than those Figure 7 shown in FIG. 5, or have a different configuration from that Figure 7 shown in FIG. 5.

[0136] The serial numbers of the above-mentioned embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0137] In the above embodiments of the present invention, the descriptions of the respective embodiments have their own emphases. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.

[0138] In the several embodiments provided by the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the couplings or direct couplings or communication connections shown or discussed with each other can be through some interfaces. The indirect couplings or communication connections of the units or modules can be in an electrical or other form.

[0139] The unit described as a separation component may or may not be physically separated. The component shown as a unit may or may not be a physical unit, that is, it may be located in one place or distributed over multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0140] In addition, each functional unit in various embodiments of the present invention may be integrated in a processing unit, may exist separately as individual physical units, or two or more units may be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.

[0141] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The foregoing storage medium includes: USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical discs and other various media that can store program codes.

[0142] The above description is only a preferred embodiment of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.

Claims

1. A code generation method based on a syntax tree, characterized in that, Including: Receiving an initial flowchart and a logic orchestration request, where the logic orchestration request carries at least: operation behaviors performed by an external terminal; Based on a preset syntax tree strategy, converting the initial flowchart into an initial syntax tree structure; Performing logic verification on the operation behaviors to obtain a verification result, and updating the initial syntax tree structure to obtain a target syntax tree structure when the verification result indicates that the operation behaviors pass the logic verification; Based on the target syntax tree structure, using a preset generation strategy to generate target code, where the preset generation strategy includes: the mapping relationship between keywords in the syntax tree structure and code representation forms; Determining a first syntax tree attribute of a logic method indicated by the initial flowchart; determining a second syntax tree attribute of a logic element indicated by the logic orchestration request; based on the first syntax tree attribute and the second syntax tree attribute, determining the preset syntax tree strategy, where the preset syntax tree strategy refers to the strategy of converting the logic data indicated by the initial flowchart into a syntax tree representation according to the first syntax tree attribute and the second syntax tree attribute; Wherein, based on the first syntax tree attribute, determining a first syntax tree representation corresponding to each parameter in the logic data; inserting a start node and an end node into the logic element array of the logic method body; based on the second syntax tree attribute, determining a second syntax tree representation of the start node and a third syntax tree representation of the end node; pointing the parent node identifier in the third syntax tree representation to the logic element identifier in the second syntax tree representation; based on the initial flowchart, combining the first syntax tree representation, the second syntax tree representation, and the third syntax tree representation to obtain the initial syntax tree structure.

2. The generation method according to claim 1, wherein Before receiving the initial flowchart and the logic orchestration request, it further includes: Creating a logic orchestration interface, where the logic orchestration interface at least includes: a logic method definition area, a logic orchestration canvas, a logic element library, and an attribute configuration area. The logic method definition area is used to create and delete logic methods. The logic orchestration canvas is used to draw the flowchart of the logic method. The logic element library is used to define and display logic elements. The attribute configuration area is used to display and modify the element attributes of the logic elements; Based on the logic method definition area, listening for a logic creation request.

3. The generation method according to claim 2, wherein After listening for the logic creation request, it further includes: When the logic creation request is monitored, receiving the logic creation request, where the logic creation request at least includes: logic data, and the logic data at least includes: a logic name, input parameters, output parameters, and preset variables; Based on the logic data, determining a start node and an end node; Based on the start node and the end node, controlling the logic orchestration canvas to draw the initial flowchart.

4. The generation method according to claim 1, characterized in that The first syntax tree attributes at least include: the first syntax tree identifier, the logical method name, the logical method input parameters, the logical method output parameters, the logical method preset variables, the logical method body, and the logical method identifier; the second syntax tree attributes include: component attributes and component extension attributes. The component attributes at least include: the second syntax tree identifier, the logical component identifier, the parent node identifier, and the logical component subtype. The component extension attributes include at least one of the following: preset conditions, logical blocks, the called logical method identifier, the called logical method input parameters, operation symbols, the expression on the left side of the operation symbol, the expression on the right side of the operation symbol, the parameter type identifier, and the parameter value.

5. The generation method according to claim 2, wherein Before receiving the initial flowchart and the logical orchestration request, it further includes: Binding preset mouse events to the logical nodes in the logical orchestration canvas, where the preset mouse events include at least one of the following: mouse click event, mouse press event, mouse move event, and mouse release event; Based on the preset mouse events, capturing operation behaviors, where the operation behaviors include at least one of the following: logical node moving in, logical node modification, and logical node deletion; Combining all the operation behaviors to obtain the logical orchestration request.

6. The generation method according to claim 5, characterized in that In the case where the verification result indicates that the operation behavior passes the logical verification, the step of updating the initial syntax tree structure to obtain the target syntax tree structure includes: Executing the logical orchestration request to draw the target flowchart; Based on the preset mouse events, listening for the coordinate positions obtained from the operation behaviors; In the case where the coordinate position coincides with the connection position in the target flowchart, performing semantic checks on the operation behavior, where the semantic checks include at least one of the following: checking whether the logical node types of the left and right operators dragged to the assignment logical node, comparison operation logical node, and logical operation logical node are consistent, checking whether the judgment condition logical component dragged to the conditional judgment logical node is a logical node of the true result or false result, and checking whether the logical node dragged to the preset process is a logical node of the expression type; In the case where the semantic check of the operation behavior passes, updating the initial syntax tree structure based on the target flowchart to obtain the target syntax tree structure.

7. The generation method according to claim 1, characterized in that, The step of generating target code based on the target syntax tree structure using a preset generation strategy includes: Scanning the target syntax tree structure to obtain a scan result; Using a preset generation strategy to convert each key-value pair corresponding to the keyword in the scan result into a code sub-fragment corresponding to the keyword in the form of code representation; Generating the target code based on all the code sub-fragments.

8. A code generation device based on a syntax tree, characterized in that It includes: A receiving unit for receiving the initial flowchart and the logical orchestration request, where the logical orchestration request at least carries: the operation behaviors executed by the external terminal; A conversion unit for converting the initial flowchart into an initial syntax tree structure based on a preset syntax tree strategy; An update unit for performing a logical check on the operation behavior to obtain a check result, and updating the initial syntax tree structure to obtain a target syntax tree structure when the check result indicates that the operation behavior passes the logical check; A generation unit for generating target code based on the target syntax tree structure by using a preset generation strategy, where the preset generation strategy includes: the mapping relationship between keywords in the syntax tree structure and code representation forms; The generation device further includes: a second determination module for determining the first syntax tree attribute of the logical method indicated by the initial flowchart; a third determination module for determining the second syntax tree attribute of the logical element indicated by the logical orchestration request; a fourth determination module for determining the preset syntax tree strategy based on the first syntax tree attribute and the second syntax tree attribute, where the preset syntax tree strategy refers to a strategy for converting the logical data indicated by the initial flowchart into a syntax tree representation according to the first syntax tree attribute and the second syntax tree attribute; The conversion unit includes: a fifth determination module for determining the first syntax tree representation corresponding to each parameter in the logical data based on the first syntax tree attribute; a first insertion module for inserting a start node and an end node into the logical element array of the logical method body; a sixth determination module for determining the second syntax tree representation of the start node and the third syntax tree representation of the end node based on the second syntax tree attribute; a first pointing module for pointing the parent node identifier in the third syntax tree representation to the logical element identifier in the second syntax tree representation; a first combination module for combining the first syntax tree representation, the second syntax tree representation, and the third syntax tree representation based on the initial flowchart to obtain the initial syntax tree structure.

9. An electronic device, characterized in that, Comprising one or more processors and a memory, the memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the syntax tree-based code generation method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Flow chart editor implementation method based on Angular

    CN110750254A

  • Method and device for updating code content in non-coverage mode

    CN112286557A

  • Front-end code generation method and device, computer equipment and storage medium

    CN112685036A

  • Low-code page development method and device, equipment and storage medium

    CN113918151A