Finite-state machine generation method and device, electronic equipment and storage medium
By building definition files and event handling functions of finite state machines, and generating and verifying finite state machines, the problem of difficulty in maintaining finite state machines in the existing technology is solved, and the scalability of the system is improved.
Patent Information
- Application Number
- CN202510063642.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-05-13
Smart Images

Figure CN119987906A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of computer compilation technology, and in particular to a finite state machine generation method, device, electronic device and storage medium. Background Art
[0002] Finite state machine is a software design pattern widely used in the field of computer software science. It is a tool for modeling object behavior, used to describe the sequence of states that an object goes through during its life cycle, and how to respond to various events from the outside world in different states.
[0003] Generally speaking, to implement a finite state machine in a program, programmers need to define data structures such as states and jumps, as well as processing functions for responding to events in the code. These all need to be implemented manually by the programmer, and when the state machine changes, the programmer needs to continuously change the code. If the state machine is complex enough, then the implementation and maintenance of this part of the code is quite difficult. In addition, if there are multiple state machines in a system, then each state machine needs to manually maintain a similar code, resulting in low scalability of the system.
[0004] Therefore, how to construct and maintain a finite state machine is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention
[0005] The embodiments of the present invention provide a finite state machine generation method, device, electronic device and storage medium, so that when the state of the finite state machine changes, the finite state machine definition file and event processing function can be maintained accordingly, thereby reducing the difficulty of maintaining the finite state machine.
[0006] In a first aspect, an embodiment of the present invention provides a finite state machine generation method, comprising:
[0007] Constructing a finite state machine definition file according to the requirements of the event to be processed; the finite state machine definition file includes a state definition, a state transition action definition and a state transition definition;
[0008] Construct an event processing function based on the event to be processed, and save the event processing function in the event processing index;
[0009] A finite state machine is generated according to the finite state machine definition file, and the generated finite state machine is verified according to the event processing function.
[0010] In a second aspect, an embodiment of the present invention further provides a finite state machine generating device, comprising:
[0011] A finite state machine definition file construction module is used to construct a finite state machine definition file according to the requirements of the event to be processed; the finite state machine definition file includes a state definition, a state transition action definition and a state transition definition;
[0012] An event processing function building module is used to build an event processing function according to the event to be processed, and save the event processing function in the event processing index;
[0013] The finite state machine generation module is used to generate a finite state machine according to the finite state machine definition file, and verify the generated finite state machine according to the event processing function.
[0014] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:
[0015] one or more processors;
[0016] A storage device for storing one or more programs;
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the finite state machine generation method described in any embodiment of the present invention.
[0018] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the finite state machine generation method described in any embodiment of the present invention.
[0019] In a fifth aspect, an embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the finite state machine generation method as described in any embodiment of the present invention.
[0020] The embodiment of the present invention provides a finite state machine generation method, device, electronic device and storage medium, which constructs the state definition, state transition action definition and state transition definition of the finite state machine according to the requirements of the event to be processed; constructs the event processing function according to the event to be processed, and saves the event processing function in the event processing index; generates the finite state machine according to the finite state machine definition file, and verifies the generated finite state machine according to the event processing function. By adopting the technical solution of the embodiment of the present invention, when the state of the finite state machine changes, the finite state machine definition file and the event processing function can be maintained accordingly, without the need to maintain the code of the finite state machine in each state, thereby reducing the difficulty of maintaining the finite state machine. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Other features, objects and advantages of the present invention will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings. The drawings are only for the purpose of illustrating preferred embodiments and are not to be considered as limiting the present invention. Also, the same reference symbols are used throughout the drawings to represent the same parts. In the drawings:
[0022] Figure 1 is a flow chart of a finite state machine generation method provided in an embodiment of the present invention;
[0023] Figure 2 is a flow chart of another finite state machine generation method provided in an embodiment of the present invention;
[0024] Figure 3 It is a flow chart of reading a finite state machine definition file to generate a finite state machine provided in an embodiment of the present invention;
[0025] Figure 4 It is a schematic diagram of a flow chart of finite state machine verification provided in an embodiment of the present invention;
[0026] Figure 5 is a structural schematic diagram of a finite state machine generating device provided in an embodiment of the present invention;
[0027] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0028] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0029] Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the operations (or steps) as sequential processes, many of the operations (or steps) therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0030] Among them, the acquisition, storage, use and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations. It should be noted that in the embodiments of this application, some existing solutions in the industry such as certain software, components or models may be mentioned, which should be considered as exemplary, and their purpose is only to illustrate the feasibility of the implementation of the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution.
[0031] 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 are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein.
[0032] Embodiment 1
[0033] Figure 1 1 is a flow chart of a finite state machine generation method provided in an embodiment of the present invention. This embodiment is applicable to the case of finite state machine generation. The method of this embodiment can be executed by a finite state machine generation device, and the device can be implemented in hardware and / or software. The device can be configured in a server for finite state machine generation. The method specifically includes the following steps:
[0034] S110. Construct a finite state machine definition file according to the requirements of the event to be processed.
[0035] Among them, the finite-state machine (FSM), also known as the finite state automaton, or state machine for short, is a mathematical model that represents a finite number of states and the transitions and transition actions between these states. A state can refer to the current state of an object, a state transition refers to the state of an object at the next moment, and a state transition action refers to the behavior of an object when it transfers from the current state to the state at the next moment. For example, taking a light as an example, the current state is that the light is on, and after the state transition, the state of the light is off, then the corresponding state transition is that the light is off, and the state transition acts as an off switch.
[0036] The finite state machine definition file may refer to a definition file constructed according to the requirements of the event to be processed, and the finite state machine definition file includes a state definition, a state transition action definition, and a state transition definition. The file format of the finite state machine definition file may be expressed as:
[0037] Plain Text
[0038] begin_state
[0039] State 1
[0040] State 2
[0041] end_state
[0042] begin_change_flag
[0043] State transition action 1
[0044] State transition action 2
[0045] end_change_flag
[0046] begin_transition
[0047] State before transfer State transfer action State after transfer
[0048] end_transition
[0049] Optionally, a finite state machine can generally be defined as a five-element FSM = (S, A, T, F), where S = (s1, s2, ...) is a finite state set; A = (a1, a2, ...) is a state transition action set; T = (t1, t2, ...) is a state transition set, where t i = pre ,a,s after >,s pre is the state before transfer, s after is the state after transfer, a is the state transfer action; F = (f1, f2, ...) is the set of event processing functions, where f i = <s,f p >, s is the state, f p To process function pointers.
[0050] S120: construct an event processing function according to the event to be processed, and save the event processing function in the event processing index.
[0051] The event processing function may refer to an event processing function called in response to an event to be processed. In the embodiment of the present invention, an event processing function is constructed according to the needs of the event to be processed, and the event processing function is stored in the time processing index.
[0052] S130: Generate a finite state machine according to the finite state machine definition file, and verify the generated finite state machine according to the event processing function.
[0053] Among them, after constructing a finite state machine definition file according to the requirements of the event to be processed, a finite state machine language is generated according to the finite state machine definition file, and the finite state machine is defined using the finite state machine language; and the finite state machine is used to automatically generate a program that can be compiled and run.
[0054] Optionally, after the executable program is compiled, the compiled program is run and the compiled program is verified using the event processing function to determine whether the generated finite state machine has any abnormality.
[0055] In an optional scheme of an embodiment of the present invention, there are multiple state machines in a system. Corresponding finite state machine definition files can be constructed on demand for different event requirements to be processed, and the corresponding event processing functions can be used to verify the newly generated finite state machine definition files without the need to maintain the code for each finite state machine.
[0056] The embodiment of the present invention provides a method for generating a finite state machine, by constructing a finite state machine definition file according to the requirements of the event to be processed; the finite state machine definition file includes a state definition, a state transition action definition, and a state transition definition; an event processing function is constructed according to the event to be processed, and the event processing function is saved in an event processing index; a finite state machine is generated according to the finite state machine definition file, and the generated finite state machine is verified according to the event processing function. By adopting the technical solution of the embodiment of the present invention, when the state of the finite state machine changes, the finite state machine definition file and the event processing function can be maintained accordingly, without the need to maintain the code of the finite state machine in each state, thereby reducing the difficulty of maintaining the finite state machine.
[0057] Embodiment 2
[0058] Figure 2 Flowchart of a finite state machine generation method provided in an embodiment of the present invention. The embodiment of the present invention further optimizes the above embodiment on the basis of the above embodiment, and the embodiment of the present invention can be combined with various optional solutions in one or more of the above embodiments. Figure 2 As shown, the finite state machine generation method provided in the embodiment of the present invention may include the following steps:
[0059] S210, constructing a finite state machine definition file according to the requirements of the event to be processed.
[0060] S220: Construct an event processing function according to the event to be processed, and save the event processing function in the event processing index.
[0061] Wherein, a corresponding event processing function is constructed according to the event to be processed, and the event processing function is stored in the event processing index.
[0062] As an optional but non-limiting implementation, the process of constructing an event processing function according to the event to be processed and storing the event processing function in the event processing index includes but is not limited to steps A1-A2:
[0063] Step A1: Construct a corresponding event processing function according to the events to be processed in each state.
[0064] Step A2: Save the event processing function in an event processing index, and construct a corresponding event processing function set; wherein the event processing index is represented as <state, function pointer>.
[0065] Among them, an event processing function is constructed according to the state of the event to be processed, and the event processing function is saved in the event processing index and a corresponding event processing function set is constructed. The event processing index can be expressed as <state, function pointer>. For example, if the event to be processed is to turn off the light, then the state of the event to be processed is that the light is turned on, and the event processing function is to turn off the light switch. The event processing index can be expressed as <light is turned on, switch is turned off>. In the embodiment of the present invention, the event processing function is called to process the event to be processed to realize the transfer of the state of the event to be processed.
[0066] S230: Generate a finite state machine according to the finite state machine definition file.
[0067] Wherein, a finite state machine is automatically generated according to the finite state machine definition file, and the finite state machine can automatically generate a corresponding running program to process the event to be processed.
[0068] As an optional but non-limiting implementation, the generating of the finite state machine according to the finite state machine definition file includes but is not limited to steps B1-B2:
[0069] Step B1: Read the finite state machine definition file, and automatically generate a definition index and a definition set for each definition file.
[0070] Step B2: Automatically generate a finite state machine according to the definition index and definition set of each definition file.
[0071] Among them, a finite state machine definition file is constructed according to the requirements of the event to be processed, and the corresponding definition index and definition set are automatically generated; according to the definition index and definition set of each definition file, a finite state machine is automatically generated. The finite state machine can automatically generate a running program for the event to be processed to process the event to be processed.
[0072] As an optional but non-limiting implementation, the reading of the finite state machine definition file and automatically generating the definition index and definition set of each definition file includes but is not limited to steps C1-C3:
[0073] Step C1: Read the state definition in the finite state machine definition file, and automatically generate a state index and a corresponding state set.
[0074] Step C2: Read the state transition action definition in the finite state machine definition file, and automatically generate a state transition action index and a corresponding state transition action set.
[0075] Step C3: Read the state transition definition in the finite state machine definition file, and automatically generate a state transition index and a corresponding state transition set.
[0076] Among them, see Figure 3 After building the finite state machine definition file, read the state definition in the finite state machine definition file and automatically generate the state index and state set; read the state transition action definition, automatically generate the state transition action index and the corresponding state transition action set A. Read the state transition definition, automatically generate the state transition index and the corresponding state transition set.
[0077] S240: Verify the generated finite state machine according to the event processing function.
[0078] The generated finite state machine is verified according to the event processing function, and timely maintenance is performed when it is determined that the finite state machine is abnormal.
[0079] As an optional but non-limiting implementation, the verification of the generated finite state machine according to the event processing function includes but is not limited to steps D1-D4:
[0080] Step D1: According to the current state of the event to be processed, query in the event processing function whether there is a target event processing function corresponding to the current state.
[0081] Step D2: If the target event processing function exists, event processing is performed according to the target event processing function; otherwise, it is determined that the generated finite state machine is incorrect.
[0082] Step D3: calling the target event processing function to determine the state transition action, and querying the corresponding target state transition index from the event processing index according to the current state and the state transition action.
[0083] Step D4: If there is a corresponding target state transfer index, point to the state transfer and modify the finite state machine state; if there is no corresponding target state transfer index, determine that the generated finite state machine is incorrect.
[0084] In each decision cycle of the finite state machine, first find the corresponding function pointer from the event function index according to the current state, call the function to process the event, make a state transfer decision, that is, calculate the state transfer action to be executed. Then, according to the current state and state transfer action, check whether there is a defined state transfer in the state transfer index. If there is, transfer to the new state according to the definition. If not, it means that the transfer is illegal, print the corresponding error log, exit the state transfer, and keep the original state.
[0085] For details, see Figure 4 , loop and wait for a certain period of time to check whether the event processing message is received; if the event processing message is received, enter the event processing, otherwise continue to wait. Query the corresponding event processing function f according to the current state s. If the corresponding event processing function can be queried in the <state, function pointer> event processing index, call f to process the event; otherwise, print the error log and return to continue waiting for the event message to be processed. Call the event processing function f, calculate the state transition action a, and query the state transition index according to the current state s and the state transition action a; if the corresponding state transition index t can be queried, pre ,a,s after >, then execute state transfer and change the state machine state to s after , and returns to continue waiting for the event message to be processed; if the corresponding state transfer index cannot be found, the error log is printed and the process returns to continue waiting for the event message to be processed.
[0086] As an optional but non-limiting implementation, the method further includes but is not limited to steps E1-E2:
[0087] Step E1: When it is determined that the generated finite state machine is incorrect, the constructed finite state machine definition file and event processing function are verified.
[0088] Step E2: Generate a target finite state machine according to the verified finite state machine definition file and event processing function.
[0089] When it is determined that the generated finite state machine is incorrect, the constructed finite state machine definition file and event processing function are verified according to the printed error log; and the target finite state machine is generated according to the verified finite state machine definition file and event processing function.
[0090] The embodiment of the present invention provides a finite state machine generation method, by constructing a finite state machine definition file according to the requirements of the event to be processed; constructing an event processing function according to the event to be processed, and saving the event processing function in the event processing index; generating a finite state machine according to the finite state machine definition file, and verifying the generated finite state machine according to the event processing function. The technical solution of the embodiment of the present invention is adopted to construct a finite state machine definition file according to the requirements of the event to be processed, and automatically generate a running program for the event to be processed according to the finite state machine definition file; construct an event processing function according to the needs of the event to be processed, and use the event processing function to verify the finite state machine. When an abnormality occurs in the finite state machine, the finite state machine definition file and the event processing function are corrected to avoid modifying the running program automatically generated by the finite state machine, so that the maintenance operation of the finite state machine is simple and the maintenance cost is reduced; in different states, only the corresponding finite state machine definition file and event processing function need to be constructed, and no other files need to be constructed, which improves the scalability of the system.
[0091] Embodiment 3
[0092] Figure 5 : is a schematic diagram of the structure of a finite state machine generation device provided in an embodiment of the present invention. The technical solution of this embodiment can be applied to the case of finite state machine generation. The device can be implemented by software and / or hardware and is generally integrated on any electronic device with network communication function, including but not limited to: servers, computers, personal digital assistants and other devices. Figure 5 As shown, the finite state machine generating device provided in this embodiment may include: a finite state machine definition file building module 510, an event processing function building module 520 and a finite state machine generating module 530; wherein,
[0093] A finite state machine definition file construction module 510 is used to construct a finite state machine definition file according to the requirements of the event to be processed; the finite state machine definition file includes a state definition, a state transition action definition and a state transition definition;
[0094] An event processing function construction module 520 is used to construct an event processing function according to the event to be processed, and save the event processing function in the event processing index;
[0095] The finite state machine generation module 530 is used to generate a finite state machine according to the finite state machine definition file, and verify the generated finite state machine according to the event processing function.
[0096] Based on the above embodiment, optionally, the event processing function construction module is specifically used to:
[0097] Construct corresponding event processing functions according to the events to be processed in each state of the pending events;
[0098] The event processing function is stored in an event processing index, and a corresponding event processing function set is constructed; wherein the event processing index is represented as <state, function pointer>.
[0099] Based on the above embodiment, optionally, the finite state machine generation module is specifically used to:
[0100] Read the finite state machine definition file, and automatically generate a definition index and a definition set of each definition file;
[0101] Automatically generate a finite state machine based on the definition index and definition set of each definition file.
[0102] Based on the above embodiment, optionally, the finite state machine generation module is further specifically used for:
[0103] Read the state definition in the finite state machine definition file, and automatically generate a state index and a corresponding state set;
[0104] Read the state transition action definition in the finite state machine definition file, and automatically generate a state transition action index and a corresponding state transition action set;
[0105] The state transition definition in the finite state machine definition file is read, and a state transition index and a corresponding state transition set are automatically generated.
[0106] Based on the above embodiment, optionally, the finite state machine generation module is further specifically used for:
[0107] According to the current state of the event to be processed, query in the event processing function whether there is a target event processing function corresponding to the current state;
[0108] If the target event processing function exists, then the event processing is performed according to the target event processing function; otherwise, it is determined that the generated finite state machine is incorrect;
[0109] Call the target event processing function to determine the state transition action, and query the corresponding target state transition index from the event processing index according to the current state and the state transition action;
[0110] If there is a corresponding target state transfer index, the state transfer is pointed to and the finite state machine state is modified; if there is no corresponding target state transfer index, it is determined that the generated finite state machine is incorrect.
[0111] Based on the above embodiment, optionally, the finite state machine generation module is further specifically used for:
[0112] When it is determined that the generated finite state machine is incorrect, the constructed finite state machine definition file and event processing function are verified;
[0113] Generate a target finite state machine based on the verified finite state machine definition file and event processing function.
[0114] The finite state machine generation device provided in the embodiment of the present invention can execute the finite state machine generation method provided in any embodiment of the present invention mentioned above, and has the corresponding functions and beneficial effects of executing the finite state machine generation method. For detailed process, please refer to the relevant operations of the finite state machine generation method in the aforementioned embodiment.
[0115] Embodiment 4
[0116] Figure 6 1 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0117] like Figure 6 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0118] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0119] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a finite state machine generation method.
[0120] In some embodiments, the finite state machine generation method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the finite state machine generation method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the finite state machine generation method in any other appropriate manner (e.g., by means of firmware).
[0121] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0122] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0123] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0124] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0125] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0126] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0127] Embodiment 5
[0128] An embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements a finite state machine generation method as provided in any embodiment of the present application.
[0129] In the process of implementation, the computer program product can be written in one or more programming languages or a combination thereof to perform the computer program code of the present invention, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0130] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0131] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A finite state machine generation method, characterized in that: The method comprises: Constructing a finite state machine definition file according to the requirements of the event to be processed; the finite state machine definition file includes a state definition, a state transition action definition and a state transition definition; Construct an event processing function based on the event to be processed, and save the event processing function in the event processing index; A finite state machine is generated according to the finite state machine definition file, and the generated finite state machine is verified according to the event processing function.
2. The method according to claim 1, characterized in that The step of constructing an event processing function according to the event to be processed and storing the event processing function in the event processing index includes: Construct corresponding event processing functions according to the events to be processed in each state of the pending events; The event processing function is stored in an event processing index, and a corresponding event processing function set is constructed; wherein the event processing index is represented as <state, function pointer>.
3. The method according to claim 1, characterized in that The generating of the finite state machine according to the finite state machine definition file comprises: Read the finite state machine definition file, and automatically generate a definition index and a definition set of each definition file; Automatically generate a finite state machine based on the definition index and definition set of each definition file.
4. The method according to claim 3, characterized in that The reading of the finite state machine definition file and automatically generating a definition index and a definition set of each definition file includes: Read the state definition in the finite state machine definition file, and automatically generate a state index and a corresponding state set; Read the state transition action definition in the finite state machine definition file, and automatically generate a state transition action index and a corresponding state transition action set; The state transition definition in the finite state machine definition file is read, and a state transition index and a corresponding state transition set are automatically generated.
5. The method according to claim 1, characterized in that The verifying the generated finite state machine according to the event processing function includes: According to the current state of the event to be processed, query in the event processing function whether there is a target event processing function corresponding to the current state; If the target event processing function exists, then the event processing is performed according to the target event processing function; otherwise, it is determined that the generated finite state machine is incorrect; Call the target event processing function to determine the state transition action, and query the corresponding target state transition index from the event processing index according to the current state and the state transition action; If there is a corresponding target state transfer index, the state transfer is pointed to and the finite state machine state is modified; if there is no corresponding target state transfer index, it is determined that the generated finite state machine is incorrect.
6. The method according to claim 5, characterized in that The method further comprises: When it is determined that the generated finite state machine is incorrect, the constructed finite state machine definition file and event processing function are verified; Generate a target finite state machine based on the verified finite state machine definition file and event processing function.
7. A finite state machine generating device, characterized in that: The device comprises: A finite state machine definition file construction module is used to construct a finite state machine definition file according to the requirements of the event to be processed; the finite state machine definition file includes a state definition, a state transition action definition and a state transition definition; An event processing function building module is used to build an event processing function according to the event to be processed, and save the event processing function in the event processing index; The finite state machine generation module is used to generate a finite state machine according to the finite state machine definition file, and verify the generated finite state machine according to the event processing function.
8. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the finite state machine generation method described in any one of claims 1-6.
9. A storage medium containing computer executable instructions, characterized in that: When the computer executable instructions are executed by a computer processor, they are used to perform the finite state machine generation method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the finite state machine generation method according to any one of claims 1 to 6.