Automatic machine construction method and device and electronic equipment

By constructing a hybrid DFA with a two-layer structure, the problem of exponential explosion of the number of DFA states in regular expression matching is solved, improving performance and reducing resource consumption.

CN118797110APending Publication Date: 2024-10-18CHINA MOBILEHANGZHOUINFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410004858.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-02
Publication Date
2024-10-18

AI Technical Summary

Technical Problem

The existing regular expression matching method will cause an exponential explosion in the number of states when constructing a DFA, resulting in reduced performance and excessive resource consumption.

Method used

By constructing a hybrid DFA with a two-layer structure, the global NFA is first generated and bounded repeated nodes are determined, and then sub-automata are constructed based on these nodes, and the preset algorithm is used to convert and merge sub-NFAs/DFAs to reduce the number of states.

Benefits of technology

It effectively avoids the exponential explosion of DFA status numbers, improves the running performance of DFA, and reduces the consumption of computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118797110A_ABST
    Figure CN118797110A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and provides an automatic machine construction method and device and electronic equipment. The method comprises the following steps: acquiring a regular expression set to be processed, and generating an abstract syntax tree based on the regular expression set; the abstract syntax tree is converted into a global NFA, and bounded repetitive nodes of the global NFA are determined; and constructing a global DFA based on the global NFA, and constructing a sub-automaton of the global DFA based on the bounded repetitive nodes. According to the method, the hybrid DFA of a two-layer structure is constructed, the bounded repetition nodes corresponding to the bounded repetition parts in the regular expression are constructed into the sub-automaton under the global DFA, index explosion of the state number of the DFA in the process of determining the NFA is effectively avoided, compression of the state number of the global DFA is achieved, the performance of the DFA during operation is improved, and consumption of computing power resources is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to an automatic machine construction method, device and electronic equipment. Background Art

[0002] In the field of computer technology applications, regular expression matching is widely used in network traffic deep detection, firewalls, intrusion detection and intrusion prevention, and the mainstream method for implementing regular expression matching is automaton technology. At present, the implementation method of automaton for implementing regular expression matching is to parse the regular expression into an abstract syntax tree based on regular grammar, then construct NFA (Non-Deterministic Finite Automata) based on the abstract syntax tree, and finally construct DFA (Deterministic Finite Automata) based on NFA for matching regular expressions.

[0003] The existing DFA construction method performs NFA expansion on bounded repetitive grammars in regular expressions and further constructs DFA using the expanded NFA, which will lead to an exponential explosion in the number of DFA states, which in turn will significantly reduce the performance of the DFA at runtime and rapidly consume available memory and other computing resources. Summary of the invention

[0004] The embodiments of the present application provide an automaton construction method, device and electronic device to solve the technical problem that when constructing DFA based on NFA, the existing construction method will cause an exponential explosion in the number of DFA states, affect the performance of DFA runtime, and rapidly consume computing resources.

[0005] In a first aspect, an embodiment of the present application provides an automatic machine construction method, comprising:

[0006] Obtaining a set of regular expressions to be processed, and generating an abstract syntax tree based on the set of regular expressions;

[0007] Converting the abstract syntax tree into a global NFA and determining bounded repeating nodes of the global NFA;

[0008] A global DFA is constructed based on the global NFA, and a sub-automaton of the global DFA is constructed based on the bounded repeated nodes.

[0009] In one embodiment, constructing a global DFA based on the global NFA, and constructing a sub-automaton of the global DFA based on the bounded repeated nodes, comprises:

[0010] Using a preset first construction algorithm to transform the global NFA to construct a global DFA;

[0011] Obtain a target repeated node corresponding to the bounded repeated node in the global DFA;

[0012] The grammatical complexity of the target repeated node is obtained, and based on the grammatical complexity, a preset second construction algorithm is used to construct the target repeated node as a sub-automaton of the global DFA.

[0013] In one embodiment, based on the grammatical complexity, constructing the target repeated node as a sub-automaton of the global DFA using a preset second construction algorithm includes:

[0014] Using the second construction algorithm, constructing the syntax tree in the target repeated node into a sub-NFA;

[0015] Determine whether there are multiple sub-NFAs in any of the target repeated nodes, and if so, merge the multiple sub-NFAs in the target repeated nodes;

[0016] Based on the grammatical complexity, determining the number of states of the sub-NFA in the target repetition node;

[0017] A sub-automaton of the global DFA is constructed according to the number of states.

[0018] In one embodiment, the sub-automaton includes a sub-DFA, an accelerated sub-DFA, and an accelerated sub-NFA; the sub-automaton of the global DFA constructed according to the number of states includes:

[0019] If the number of states is greater than a first preset threshold, converting the sub-NFA in the target repetitive node into a sub-DFA;

[0020] If the number of states is less than or equal to a first preset threshold and greater than a second preset threshold, converting the sub-NFA in the target repetitive node into an accelerated sub-NFA; the first preset threshold is greater than the second preset threshold;

[0021] If the number of states is less than or equal to a second preset threshold, a DFA conversion analysis is performed on the sub-NFA in the target repetitive node to convert the sub-NFA into an accelerated sub-DFA or an accelerated sub-NFA.

[0022] In one embodiment, performing DFA conversion analysis on the sub-NFA in the target repetitive node to convert the sub-NFA into an accelerated sub-DFA or an accelerated sub-NFA includes:

[0023] Performing DFA conversion analysis on the sub-NFA in the target repetitive node to determine the number of target states after the sub-NFA is DFA converted;

[0024] If the number of target states is less than or equal to a second preset threshold, converting the sub-NFA into an accelerated sub-DFA;

[0025] If the target state quantity is greater than a second preset threshold, the sub-NFA is converted into an accelerated sub-NFA.

[0026] In one embodiment, converting the sub-NFA in the target repetition node into an accelerated sub-NFA includes:

[0027] Obtaining state parameters of the sub-NFA in the target repetitive node; the state parameters include a state set, a state transition character, an acceptance state, and a state transition table;

[0028] Divide the restricted number of states of the sub-NFA in the target repetitive node into bytes, and establish a subsequent state mask set for each byte after the division based on the state parameter;

[0029] The sub-NFA in the target repetition node is converted into an accelerated sub-NFA based on the successor state mask set.

[0030] In one embodiment, converting the sub-NFA in the target repetitive node into an accelerated sub-DFA includes:

[0031] Convert the sub-NFA in the target repetition node into a sub-DFA;

[0032] Obtaining an alphabet of the sub-DFA and an input vector of a query instruction of the sub-DFA; the input vector includes a source vector and a control code;

[0033] Constructing a source code query mask table of the alphabet based on the input vector;

[0034] The sub-DFA is converted into an accelerated sub-DFA according to the source code query mask table.

[0035] In one embodiment, after constructing a global deterministic finite automaton DFA based on the global NFA and constructing a sub-automaton of the global DFA based on the bounded repeated nodes, the method further includes:

[0036] Analyze the first matching times of the i-th regular expression that the subautomaton can match being matched continuously in the successor node of the bounded repetition node;

[0037] When the sub-automaton completes a maximum number of hits of the i-th sub-regular expression for a preset number of times, calculating the difference between the preset number of times and the first number of matches;

[0038] If the difference is within a preset value range, obtaining an offset corresponding to the difference, and using the input corpus character at the position corresponding to the offset to perform a subsequent match of the bounded repeated node;

[0039] If the difference is not within the preset value range, a target value is calculated based on the value range; wherein the target value is the maximum value in the value set; and the difference between the preset number of times and any value in the value set is within the value range;

[0040] An offset corresponding to the target value is obtained, and the offset and the input corpus character at a position corresponding to the offset are used to perform a subsequent match of the bounded repeated node.

[0041] In a second aspect, an embodiment of the present application provides an automatic machine construction device, comprising:

[0042] A first building module is used to obtain a set of regular expressions to be processed, and generate an abstract syntax tree based on the set of regular expressions;

[0043] A second building module, configured to convert the abstract syntax tree into a global NFA and determine bounded repeating nodes of the global NFA;

[0044] The third building module is used to build a global DFA based on the global NFA, and to build a sub-automaton of the global DFA based on the bounded repeated nodes.

[0045] In a third aspect, an embodiment of the present application provides an electronic device, comprising a processor and a memory storing a computer program, wherein when the processor executes the program, the steps of the automatic machine construction method described in the first aspect are implemented.

[0046] In a fourth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the automatic machine construction method described in the first aspect are implemented.

[0047] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the automatic machine construction method described in the first aspect.

[0048] The automaton construction method, device and electronic device provided in the embodiments of the present application, by constructing a two-layer hybrid DFA, constructs the bounded repeated nodes corresponding to the bounded repeated part in the regular expression as a sub-automaton under the global DFA, effectively avoiding the exponential explosion of the number of DFA states in the process of determining the NFA, achieving the compression of the number of global DFA states, improving the performance of the DFA runtime, and reducing the consumption of computing resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] In order to more clearly illustrate the technical solutions in the present application or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0050] Figure 1 It is a flowchart of the automatic machine construction method provided in the embodiment of the present application;

[0051] Figure 2 It is one of the global NFA schematic diagrams provided in the embodiments of the present application;

[0052] Figure 3 This is the second global NFA schematic diagram provided in the embodiment of the present application;

[0053] Figure 4 It is a schematic diagram of the construction process of the sub-automaton provided in the embodiment of the present application;

[0054] Figure 5 It is a functional diagram of the PSHUFB instruction provided in an embodiment of the present application;

[0055] Figure 6 It is a schematic diagram of the automatic mechanism construction process provided by the embodiment of the present application;

[0056] Figure 7 is a schematic diagram of a hybrid DFA provided in an embodiment of the present application;

[0057] Figure 8 is a schematic diagram of the structure of the automatic machine construction device provided in the embodiment of the present application;

[0058] Fig. 9 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0059] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0060] It should be noted that automata are also called state machines, including deterministic finite automata (DFA) and non-deterministic finite automata (NFA).

[0061] For a deterministic finite automaton DFA, it usually includes:

[0062] A finite set of states, denoted by Q;

[0063] A finite number of input symbols, denoted by ∑;

[0064] A transition function takes a state and an input symbol as arguments and returns a state. The transition function is usually denoted by δ. In informal automaton graphs, δ is represented by arrows between states and labels on the arrows. If q is a state and a is an input symbol, then δ(q,a) is a state p such that there is an arrow from q to p labeled with a;

[0065] An initial state q0, which is one of the states in the set Q;

[0066] A set F of terminal states, or accepting states, where F is a subset of Q;

[0067] Usually a deterministic finite automaton is represented by a five-tuple as shown in the following formula 1:

[0068] A=(Q,∑,δ,q0,F); (1)

[0069] Among them, A is the name of the constructed DFA, Q is the state set of DFA, ∑ is the input symbol, δ is the transition function, and F is the set of accepting states.

[0070] The language L(A) accepted by a DFA A is denoted as:

[0071]

[0072] in, is the extended state transition function, which represents the states that a DFA can reach from the initial state q0 accepting the input string w. Formula 2 shows that the language accepted by a DFA is the set of strings w that allow the initial state q0 to lead to one of the accepting states.

[0073] Compared with DFA, NFA has the ability to be in several states at the same time, so NFA has the ability to handle non-determinism. Like DFA, an NFA usually has a finite state set Q, a finite input symbol set ∑, an initial state q0, a set of accepting states F, and a transition function δ. The difference between NFA and DFA lies in the type of δ. For NFA, its δ is the same as the transition function of DFA, which is a function with states and input symbols as variables, but it returns a state set, which can include 0, 1 or more states, while DFA returns at most one state.

[0074] Similarly, a language L(A) accepted by NFAA can be written as:

[0075]

[0076] In formula 3, is the extended state transition function of NFA, which represents the set of states that NFA can reach from the initial state q0 accepting the input string w. Formula 3 shows that the language accepted by an NFA is the set of strings w that allow the initial state q0 to lead to a state set that contains at least one accepting state.

[0077] The embodiment of the present application provides an automaton construction method that can be used to construct a deterministic finite automaton DFA. Compared with the traditional method of using a single DFA automaton as an engine for regular expression matching, the automaton construction method proposed in the embodiment of the present application can construct a hybrid DFA automaton with a two-layer structure. The two-layer DFA structure consists of a global DFA that contains all regular expressions in the regular rule set, and a plurality of sub-NFA / DFAs that contain many local grammars in the regular rule set. Among them, the matching entry for the regular expression of the input corpus is entered by the global DFA, and the global DFA is used to be responsible for the matching process of the entire regular expression, and determines whether the next matching process needs to call the sub-NFA / DFA for matching based on the current character of the input corpus and the current global DFA state. Once the sub-NFA / DFA is called by the global DFA, the next matching process will run on the sub-NFA / DFA. After the sub-NFA / DFA runs, it returns the running result to the global DFA. The global DFA decides whether to perform further matching or end matching based on the return result of the sub-NFA / DFA running, and returns the result of whether the regular expression match is successful or not.

[0078] Specifically, Figure 1 This is a flow chart of the automatic machine construction method provided in the embodiment of the present application. Figure 1 The automatic machine construction method provided in the embodiment of the present application may include:

[0079] Step 100, obtaining a set of regular expressions to be processed, and generating an abstract syntax tree based on the set of regular expressions;

[0080] First, a set of regular expressions to be processed is obtained, which is a regular rule set, and includes regular expressions and rules for regular matching. The regular expressions in the regular expression set are parsed to generate an abstract syntax tree AST (Abstract Syntax Tree).

[0081] Preferably, when generating an abstract syntax tree, a regular grammar can be used to parse the regular expression set to generate an abstract syntax tree that is isomorphic to the regular grammar and can reflect the structural characteristics of the regular expression set. It can be understood that the regular expressions in the regular expression set have bounded repetition syntax, so the generated abstract syntax tree includes a sub-AST tree corresponding to the bounded repetition part.

[0082] Step 200, converting the abstract syntax tree into a global NFA, and determining bounded repeating nodes of the global NFA;

[0083] The constructed abstract syntax tree is converted into a global NFA, and the bounded repetition node of the global NFA is determined. The bounded repetition node is the node corresponding to the sub-AST tree in the abstract syntax tree. The sub-AST tree is the subtree corresponding to the bounded repetition part in the regular expression set in the abstract syntax tree.

[0084] Preferably, when converting the abstract syntax tree into a global NFA, a preset construction algorithm, such as a Thompson NFA construction algorithm, may be used for conversion, which is not specifically limited herein.

[0085] Step 300: construct a global DFA based on the global NFA, and construct a sub-automaton of the global DFA based on the bounded repeated nodes.

[0086] Based on the constructed global NFA, a global DFA is constructed, and then based on the bounded repeated nodes in the global NFA, a sub-automaton of the global DFA is constructed, the sub-automaton including the sub-NFA and the sub-DFA. The constructed global DFA and the sub-automaton form a hybrid DFA of a two-layer structure.

[0087] Preferably, the method of constructing a global DFA includes but is not limited to converting a global NFA. In a global NFA, for a bounded repetition grammar {a, b}, it is determined whether to expand the bounded repetition grammar {a, b} part into a global NFA, or to extract the sub-AST tree of the bounded repetition part, and construct a bounded repetition node belonging to the global NFA and containing the sub-AST tree of the repetition part from the sub-AST tree of the extracted part, and the sub-AST tree in the bounded repetition node is further constructed as a sub-NFA or a sub-DFA, based on the boundary values ​​of the grammar min=a, max=b, (ba) and the grammatical complexity of the bounded repetition part.

[0088] Taking the regular expression (a|b?){1,3} as a bounded repetition grammar part as an example, if it is expanded, the global NFA constructed using the Thompson NFA construction algorithm is as follows Figure 2 If the regular expression (a|b?){1,3} is not expanded, the regular expression (a|b?){1,3} will be constructed as a bounded repetition node in the global NFA, which contains a sub-syntax tree that records the information of the regular expression (a|b?), as well as the upper and lower bounds of the bounded repetition number, min=1 and max=3.

[0089] Take the regular expression A(a|b?){1,3}B as an example. If the bounded repeating part is not expanded, the regular expression A(a|b?){1,3}B will be constructed as follows: Figure 3 The global NFA shown contains a bounded repeating node. Figure 2 and Figure 3 It can be seen that when the bounded repetition grammar is not expanded in the global NFA, the bounded repetition part in the regular expression will be constructed as a bounded repetition node in the global NFA, which contains the regular expression (a|b?){1,3} information, that is, the sub-grammar tree corresponding to the regular expression (a|b?) and the upper and lower limit information of bounded repetition min=1 and max=3. It should be noted that the edge connecting the bounded repetition node to the successor node is neither any character in the alphabet nor an epsilon edge, but is marked by direct to distinguish between ordinary character edges and epsilon edges. When the global NFA is subsequently converted to DFA using the subset construction algorithm, the edges marked by direct can be used alone for subset construction to obtain a sub-NFA or sub-DFA.

[0090] In this embodiment, by constructing a two-layer hybrid DFA, the bounded repeated nodes corresponding to the bounded repeated parts in the regular expression are constructed as sub-automatons under the global DFA, which effectively avoids the exponential explosion of the number of DFA states in the process of determining the NFA, realizes the compression of the number of global DFA states, improves the performance of the DFA runtime, and reduces the consumption of computing resources.

[0091] Preferably, the construction of the global DFA, sub-NFA and sub-DFA is mainly to convert the global NFA into the global DFA through a subset construction algorithm, and convert the syntax tree in the repeated node into the corresponding sub-NFA or sub-DFA. Based on this, in step 300, the global DFA is constructed based on the global NFA, and the sub-automaton under the global DFA is constructed based on the bounded repeated nodes in the global NFA, which specifically includes:

[0092] Step 310, using a preset first construction algorithm to transform the global NFA to construct a global DFA;

[0093] Step 320, obtaining the target repeated node corresponding to the bounded repeated node in the global DFA;

[0094] Step 330 : Acquire the grammatical complexity of the target repeated node, and based on the grammatical complexity, use a preset second construction algorithm to construct the target repeated node as a sub-automaton of the global DFA.

[0095] The global NFA is converted using a preset first construction algorithm to construct a global DFA, wherein the first construction algorithm includes but is not limited to a subset construction algorithm. The target repeated node corresponding to the bounded repeated node in the global NFA is obtained in the global DFA, and the target repeated node is constructed as a sub-automaton under the global DFA using a preset second construction algorithm according to the grammatical complexity of the target repeated node. Wherein, when the constructed sub-automaton includes a sub-NFA, the second construction algorithm includes but is not limited to the Gluskov NFA construction algorithm.

[0096] Preferably, in one embodiment, for the global NFA, the Thompson NFA construction algorithm is used for construction, and for the sub-NFA, the Gluskov NFA construction algorithm is used for construction. The reason is that, compared with the Thompson NFA construction algorithm, the NFA constructed by the Gluskov NFA construction algorithm does not have an epsilon edge, and the number of states of the Gluskov NFA is equal to the number of characters in the regular expression plus one, which is conducive to the subsequent use of the CPU's SIMP instruction set to accelerate the operation of the sub-NFA. The reason why the global NFA is constructed using the Thompson NFA construction algorithm is that the global NFA needs to be converted into a DFA, and the DFAs that Thompson NFA and Gluskov NFA are finally converted into using the subset construction algorithm are equivalent, and Thompson NFA is more intuitive and vivid than Gluskov NFA, which is conducive to intuitive understanding and troubleshooting of problems. Therefore, in this embodiment, two different construction strategies are adopted for the global NFA and the sub-NFA.

[0097] Furthermore, in step 330, based on the grammatical complexity of the target repeated node, a preset second construction algorithm is used to construct the target repeated node as a sub-automaton of the global DFA, which may also include:

[0098] Step 331, using the second construction algorithm to construct the syntax tree in the target repeated node into a sub-NFA;

[0099] Step 332, determining whether there are multiple sub-NFAs in any of the target repeated nodes, and if so, merging the multiple sub-NFAs in the target repeated nodes;

[0100] Step 333, based on the grammatical complexity, determine the number of states of the sub-NFA in the target repetition node;

[0101] Step 334: construct a sub-automaton of the global DFA according to the number of states.

[0102] When constructing a sub-automaton, first, a preset second construction algorithm is used to construct a syntax tree in a target repetition node as a sub-NFA, and then it is determined whether there are multiple sub-NFAs in any target repetition node. If so, the multiple sub-NFAs in the target repetition node are merged. Based on the grammatical complexity of the target repetition node, the number of states of the sub-NFA of the target repetition node is determined, and a sub-automaton of the global DFA is constructed according to the number of states of the sub-NFA, including determining whether to convert the sub-NFA into a sub-DFA according to the number of states of the sub-NFA.

[0103] In the process of constructing a global DFA using the subset construction algorithm, there will be a situation where multiple global NFA repeated nodes are merged into one global DFA repeated node. For example, when the regular expression host(a|b){2,10} and the regular expression host(abc){10,20} are compiled into a global Thompson NFA containing repeated nodes, and the global DFA is constructed using the subset construction algorithm, the repeated nodes corresponding to the (a|b) and (abc) parts of the regular expression will be merged into a sub-NFA repeated node, and there are two sub-NFAs corresponding to the regular expressions (a|b) and (abc) in the sub-NFA repeated node. Therefore, before determining whether to convert the Gluskov NFA into a DFA, it is necessary to first merge the multiple sub-NFAs that may exist in the global DFA repeated node.

[0104] Preferably, in step 334, when constructing the sub-automaton of the global DFA according to the number of states of the sub-NFA in the global DFA, it may also include:

[0105] Step 301, if the number of states is greater than a first preset threshold, convert the sub-NFA in the target repeated node into a sub-DFA;

[0106] Step 302: If the number of states is less than or equal to a first preset threshold and greater than a second preset threshold, convert the sub-NFA in the target repetitive node into an accelerated sub-NFA; the first preset threshold is greater than the second preset threshold;

[0107] Step 303: If the number of states is less than or equal to a second preset threshold, perform DFA conversion analysis on the sub-NFA in the target repetitive node to convert the sub-NFA into an accelerated sub-DFA or an accelerated sub-NFA.

[0108] Furthermore, in step 303, performing DFA conversion analysis on the sub-NFA in the target repetitive node to convert the sub-NFA into an accelerated sub-DFA or accelerated sub-NFA further includes:

[0109] Step 304, performing DFA conversion analysis on the sub-NFA in the target repetitive node to determine the number of target states after the sub-NFA is DFA converted;

[0110] Step 305, if the number of target states is less than or equal to a second preset threshold, converting the sub-NFA into an accelerated sub-DFA;

[0111] Step 306: If the number of target states is greater than a second preset threshold, convert the sub-NFA into an accelerated sub-NFA.

[0112] Preferably, the constructed sub-automaton of the global DFA includes a sub-DFA, a sub-NFA, an accelerated sub-DFA and an accelerated NFA. When constructing the sub-automaton, a judgment is made based on the number of states of the sub-NFA in the global DFA. Specifically, if the number of states of the sub-NFA is greater than the first preset threshold, the sub-NFA in the target repeated node is converted into a sub-DFA using a subset construction algorithm; if the number of states of the sub-NFA is less than or equal to the first preset threshold, and greater than the second preset threshold, the sub-NFA in the target repeated node is converted into an accelerated sub-NFA; if the number of states of the sub-NFA is less than or equal to the second preset threshold, the sub-NFA in the target repeated node is subjected to a DFA conversion analysis to determine the target number of states of the sub-NFA in the target repeated node after conversion to the sub-DFA. If the target number of states is less than or equal to the second preset threshold, the sub-NFA in the target repeated node is converted into an accelerated sub-DFA; if the target number of states is greater than the second preset threshold, the sub-NFA in the target repeated node is converted into an accelerated sub-NFA. It can be seen that the first preset threshold is greater than the second preset threshold.

[0113] Preferably, when determining whether to perform Gluskov NFA->DFA conversion, the core determination basis is the state data of NFA and DFA, the advantage of NFA in space efficiency, the advantage of DFA in running speed, and the number of states that the CPU SIMD instruction supports NFA / DFA bit-parallel state transition table query. In this embodiment, Intel's SSE3 instruction set is used as an example for explanation. Since the SSE3 instruction set supports a maximum of 128-bit bit vectors, the SSE3 instruction set can support a maximum of 128-state NFA bit-parallel acceleration and a 16-bit DFA bit-parallel acceleration.

[0114] Furthermore, in the decision process of whether to convert Gluskov NFA into DFA, if the number of states of the sub-Gluskov NFA is greater than 128, the SIMD instruction set cannot be directly used to accelerate the operation of NFA at this time, so the sub-NFA is directly converted into a sub-DFA to obtain higher operation efficiency. When the number of states of the sub-Gluskov NFA is less than 128, it is further determined whether the number of states of DFA is less than or equal to 16 when Gluskov NFA is converted into DFA. If it is less than or equal to 16, a SIMD instruction set accelerated sub-DFA accelerated by SIMD instruction set is constructed, otherwise, an accelerated sub-NFA accelerated by SIMD instruction set is constructed. Because when the number of states of DFA is greater than 16, the operation efficiency of ordinary DFA cannot exceed the operation efficiency of NFA accelerated by SIMD instruction set, and NFA accelerated by SIMD instruction set has better space efficiency and can effectively reduce CPU cache misses.

[0115] In one embodiment, referring to Figure 4 The schematic diagram of the construction process of the sub-automaton shown in the figure, when constructing the sub-automaton, firstly merge multiple sub-NFAs for repeated nodes with multiple sub-NFAs in the global DFA, and then calculate the number of states of the sub-NFA in the repeated nodes in the global DFA, if it is greater than the first preset threshold, the sub-NFA is converted into a sub-DFA; otherwise, if the number of states of the sub-NFA is less than the first preset threshold but greater than the second preset threshold, the sub-NFA is converted into an accelerated sub-NFA; if the number of states of the sub-NFA is less than or equal to the second preset threshold, the sub-NFA is subjected to DFA conversion analysis to determine whether the number of states after the sub-NFA is converted into DFA is less than or equal to the second preset threshold, if so, the sub-NFA is converted into an accelerated sub-DFA, otherwise, the sub-NFA is converted into an accelerated sub-NFA. The first preset threshold is 128, for example, and the second preset threshold is 16.

[0116] Furthermore, in step 302 and step 305, when converting the sub-NFA into an accelerated sub-NFA, the steps specifically include:

[0117] Step 001, obtaining the state parameters of the sub-NFA in the target repetitive node; the state parameters include a state set, a state transition character, an acceptance state and a state transition table;

[0118] Step 002, dividing the restricted state number of the sub-NFA in the target repetitive node into bytes, and establishing a subsequent state mask set for each byte after the division based on the state parameter;

[0119] Step 003: Convert the sub-NFA in the target repetitive node into an accelerated sub-NFA based on the successor state mask set.

[0120] When constructing an accelerated sub-NFA, first obtain the state parameters of the sub-NFA of the target repetition node, which include a state set, a state transition character, an acceptance state, and a state transition table. Then, divide the limited character digits of the sub-NFA in the target repetition node into bytes, and establish a successor state mask set for each byte after division based on the obtained state parameters. According to the established successor state mask set, convert the sub-NFA in the target repetition node into an accelerated sub-NFA.

[0121] Preferably, taking the implementation of the CPU SIMD instruction set accelerated sub-NFA as an example, assuming that the Gluskov NFA is represented as NFA (Q = {s0 ... s |Q|-1},∑,I=s0,F,Δ), where Q is the state set of the sub-NFA, ∑ is the state transition character of the sub-NFA, and I is the initial state (I n =0 |Q|-1 1), is the accepting state, and Δ is the state transition table.

[0122] Let B[σ] represent the state that can be reached by character σ in Gluskov NFA, and SUCC[S] represent all the successor states of Gluskov NFA state set S. Here, an important property of Gluskov NFA is used, that is, the characters of the edges pointing to the same state in Gluskov NFA are the same. Therefore, the reachable state of Gluskov NFA state set S under input character σ can be expressed as SUCC[S]&B[σ]. Since the state limit of Gluskov NFA is 128 and the number of character sets is finite, B[σ] can be queried using a table with |∑| entries, each of which is a 128-bit vector data. The calculation of the successor state of state set S adopts the following method:

[0123] Divide 128 bits into 16 bytes, and create a subsequent state mask set for each byte (i.e., 8 states), so there are a total of 16×2 8 During the regular matching operation, 16 table lookups will be performed, and all the query results of the 16 table lookups will be ORed to obtain the reachable states of the state set S under the action of the input character σ, realizing the acceleration of the state transfer process based on the SIMD instruction set.

[0124] In one embodiment, the state transfer process of Gluskov NFA based on SIMD acceleration is as follows:

[0125] Define variables:

[0126] __m128i state; / / Current state mask;

[0127] vector<__m128i>table; / / successor state mask table;

[0128] table.resize(256*resize(state));

[0129] vector<__m128i>reach; / / reachable state mask table;

[0130] reach.resize(alpha_size); / / alpha_size is the size of the DFA character set;

[0131] Initialize the successor state mask table and the reachable state mask table;

[0132] function GetNextStates(__m128i state,const__m128i table[],char c / *input character* / );

[0133] u8 s[sizeof(state)];

[0134] memcpy(s,&state,sizeof(state));

[0135] __m128i succ:=table[s[0]]

[0136] for i=1to size sizeof(state)-1do

[0137] if s[i]then

[0138] succ:=or128(rv,table[256*i+s[i]]);

[0139] end if

[0140] s:=and128(succ,reach[c]);

[0141] retrun s;

[0142] end function

[0143] The operations "or128" and "and128" can be accelerated by the CPU instructions "_mm_and_si128" and "_mm_or_si128".

[0144] Preferably, in step 304, converting the sub-NFA in the target repetitive node into an accelerated sub-DFA may also include:

[0145] Step 010, converting the sub-NFA in the target repeated node into a sub-DFA;

[0146] Step 020, obtaining the alphabet of the sub-DFA and the input vector of the query instruction of the sub-DFA; the input vector includes a source vector and a control code;

[0147] Step 030, constructing a source code query mask table of the alphabet based on the input vector;

[0148] Step 040: query the mask table according to the source code, and convert the sub-DFA into an accelerated sub-DFA.

[0149] When constructing an accelerated sub-DFA, first convert the sub-NFA in the target repetition node into a sub-DFA, obtain the alphabet of the sub-DFA, and the input vector of the query instruction of the sub-DFA, the input vector includes a source vector and a control code, wherein the query instruction of the DFA is a state query instruction used for state transfer during regular matching. Based on the input vector, a source code query mask table of the alphabet is constructed, and finally, according to the constructed source code query mask table, the sub-DFA is converted into an accelerated sub-DFA.

[0150] Taking SIMD accelerated sub-DFA as an example, the CPU SIMD instruction set accelerates the sub-DFA by using the CPU PSHUFB instruction. Figure 5 The PSHUFB instruction function shown in the figure has two inputs and one output. Usually, the two 16-byte input vectors are called source vector (src) and control code (ctl). When the highest bit of each byte of the control code is 0, the PSHUFB instruction uses the lower 4 bits of each byte of the control code as the index to address a byte in the source vector and saves its value to the corresponding position of the 16-byte output vector (dst). If the highest bit of each byte of the control code is 1, 0 is saved to the corresponding position of the 16-byte output vector. Based on the characteristics of the PSHUFB instruction, the source code query mask table of the PSHUFB instruction is constructed by the alphabet table of the sub-DFA. When performing regular matching, the current activation state number of the DFA is broadcast to the 16-byte vector to obtain the control code. According to the current state value of the DFA and the input character, the PSHUFB instruction can be used to complete a DFA state transfer operation within one CPU clock cycle, thereby accelerating the state transfer process of the sub-DFA.

[0151] In one embodiment, let the 16-byte source code be variable a, the 16-byte control code be variable b, and the output result of PSHUFB be stored in the 16-byte variable dst. The function of PSHUFB can be expressed as follows:

[0152] FOR j:=0to15;

[0153] i:=j*8;

[0154] IF b[i+7] == 1;

[0155] dst[i+7:i]:=0;

[0156] ELSE

[0157] index[3:0]:=b[i+3:i];

[0158] dst[i+7:i]:=a[index*8+7:index*8];

[0159] FI

[0160] ENDFOR;

[0161] Based on the characteristics of the PSHUFB instruction, the source code query mask table of the PSHUFB instruction is constructed for the alphabet table of the sub-DFA automaton, and the current activation state number of the sub-DFA is broadcast to a 16-byte vector to obtain the control code. According to the current state value of the sub-DFA and the input character, the PSHUFB instruction can be used to complete a state transfer operation of the sub-DFA within one CPU clock cycle. Among them, the construction of the PSHUFB source code query table is the key, and its construction process is as follows:

[0162] Source code query mask table construction process of PSHUFB instruction:

[0163] vector <array<u8,sizeof(m128)> >mask_table; / / Define the source code query mask table that needs to be built;

[0164] masks.resize(info.alpha_size); / / where alpha_size is the alphabet size of DFA;

[0165] FOR i:=0to(alpha_size-1);

[0166] auto&mask=mask_table[i];

[0167] for(dfa_state_id id=0; id <id_end-1;id++)

[0168] {dfa_state_id_t next_id=id.next[i];

[0169] if(next_id==DEAD_STATE_ID)

[0170] {next_id=id_end-1;}

[0171] else if(next_id <id_end)

[0172] {next_id--;}

[0173] mask[id] = u8(next_id);}

[0174] ENDFOR;

[0175] After the source code query mask table mask_table is constructed, the next state of the DFA accelerated by the PSHUFB instruction under the input character c and the current state s can be obtained within one CPU clock cycle using the following instructions:

[0176] next_state=_mm_shuffle_epi8(mask_table[c],_mm_set1_epi8(s));

[0177] Among them, "_mm_set1_epi8(s)" broadcasts the current state of the current byte to the 16-byte "_m128i" type variable to obtain the "_m128i" type control mask of the PSHUFB instruction "_mm_shuffle_epi8".

[0178] In one embodiment, referring to Figure 6 The schematic diagram of the construction process of the automaton shown in the figure builds an abstract syntax tree based on a set of regular expressions, then builds a global NFA based on the constructed abstract syntax tree, extracts the sub-AST tree (i.e., sub-syntax tree) corresponding to the repeated nodes in the global NFA, and converts the extracted sub-syntax tree into a sub-NFA. Then, a global DFA is built based on the global NFA, and a judgment is made as to whether the sub-NFA needs to be converted to DFA, and the sub-NFA that needs to be converted to DFA is converted to DFA, and a sub-DFA is built, and the sub-NFA that does not need to be converted is retained. When the regular matching is running, a SIMD-accelerated sub-NFA and a SIMD-accelerated sub-DFA are built based on the sub-NFA and the sub-DFA, thereby completing the construction of the motivation for matching regular expressions.

[0179] Preferably, for bounded repeating subexpressions like ((china)|(mobile)){10,20}, a sub-NFA / DFA is constructed for matching. When the sub-NFA / DFA is running, two main tasks are performed: using the sub-NFA / DFA loop to match the regular expression ((china)|(mobile)); recording the number of times the regular expression ((china)|(mobile)) is matched (the sub-NFA / DFA adopts a greedy matching mode to match as many times as possible, that is, it will try to obtain the maximum number of matches. Considering that the regular expression to be matched is ((china)|(mobile)){10,20}china or ((china)|(mobile)){10,20}chinachina, it is necessary to introduce a backtracking mechanism in the subsequent matching process after completing the sub-NFA / DFA matching, so that the regular expression ((china)|(mobile)) is matched as many times as possible. na)|(mobile)){10,20}chinachinachinachinachina or ((china)|(mobile)){10,20}chinachina can be successfully matched, but the introduction of the backtracking mechanism at runtime will seriously affect the matching performance of the overall automaton. Based on this, in the construction process of DFA, a backtracking avoidance mechanism based on regular expression analysis is introduced to avoid the introduction of too much backtracking causing a sharp drop in the overall performance of the hybrid DFA at runtime. In step 300, after constructing a global DFA based on the global NFA and constructing a sub-automaton of the global DFA based on the bounded repeated nodes of the global NFA, it can also include:

[0180] Step 401, analyzing the first matching times of the i-th sub-regular expression that the sub-automaton can match being matched continuously in the successor node of the bounded repetitive node;

[0181] Step 402, when the sub-automaton completes the maximum number of hits of the i-th sub-regular expression for a preset number of times, calculate the difference between the preset number of times and the first matching number;

[0182] Step 403: if the difference is within a preset value range, obtain an offset corresponding to the difference, and use the input corpus character at the position corresponding to the offset to perform a subsequent match of the bounded repeated node;

[0183] Step 404: if the difference is not within the preset value range, a target value is calculated based on the value range; wherein the target value is the maximum value in the value set; and the difference between the preset number of times and any value in the value set is within the value range;

[0184] Step 405: Obtain an offset corresponding to the target value, and use the offset to match the input corpus characters at the corresponding position to the successor of the bounded repeated node.

[0185] After the global DFA and sub-NFA / DFA are constructed, analyze the number of times each sub-regular expression that the sub-NFA / DFA can match can be matched continuously in the successor node of the bounded repeating node, and record it in the data structure of the bounded repeating node, which is recorded as the first matching number m i (The subscript i represents the serial number of the sub-regular expression that the sub-NFA / DFA matches.) The emphasis here on each sub-regular expression that can be matched is because the sub-NFA / DFA in the bounded repeating node of the global DFA may be formed by merging multiple sub-NFAs.

[0186] Furthermore, when using the sub-NFA / DFA for matching, the offset of the position after the end position of each successful sub-NFA / DFA match is recorded, denoted as p j , where j represents the jth successful match.

[0187] When the sub-NFA / DFA completes the preset number of times, such as the maximum number of hits of the sub-regular expression i n times, the difference between the preset number n and the first matching number is calculated, that is, nm i If the difference is within the preset range, it satisfies min≤nm i ≤max, then use the offset [p n-mi ,p n-0 ] The input corpus characters at the corresponding position are matched to the successor of the repeated node. If min≤nm is not satisfied i ≤max, then calculate the maximum value of x that satisfies min≤nx≤max, using the offset [p n-x ,p n-0 ] The input corpus characters at the corresponding position are matched to the successor of the repeated node. Where min is the minimum value in the preset value range, max is the maximum value in the preset value range, and p n-mi is the minimum offset corresponding to min, p n-0 The maximum offset corresponding to max.

[0188] Preferably, refer to Figure 7 The hybrid DFA schematic diagram shown in FIG. 1 is constructed by using the automaton construction method provided in the embodiment of the present application. Figure 7 In the hybrid DFA, there are two layers of structures. The first layer is a global DFA, and the second layer is an automaton under the repeated subnodes including a common sub-DFA, a SIMD accelerated Gluskov sub-NFA, and a SIMD accelerated sub-DFA.

[0189] In this embodiment, the constructed two-layer hybrid DFA can effectively solve the state explosion problem of the number of DFA states under bounded repetition grammar, greatly reduce the memory overhead required for the overall DFA compilation and operation, effectively improve the performance of the DFA runtime, and more effectively support parallel DFA matching of larger-scale regular expression rule sets.

[0190] Furthermore, the existing DFA is limited by the number of DFA states and computer memory limitations, and lacks sufficient support for scenarios that require efficient, multi-rule parallel matching. In addition, most existing regular matching methods use a single DFA to match regular expressions, lacking local optimization for DFA graph features. In this embodiment, for scenarios of efficient, multi-regular rule parallel matching, a two-layer hybrid DFA is constructed that includes both a global DFA graph and a local sub-NFA / DFA graph. Under the limited memory constraints of computer devices, the number of DFA states can be effectively reduced to support parallel matching of larger regular expression rule sets. In addition, for the local features of the sub-NFA / DFA graph, the overall matching efficiency of the hybrid DFA is effectively improved by locally merging the sub-NFA in the repeated nodes, combining the backtracking avoidance mechanism for bounded repeated nodes, and SIMD instruction set acceleration and other optimizations.

[0191] Furthermore, when constructing sub-automata, based on the space advantage of NFA, the runtime advantage of DFA and the SIMD vector instruction characteristics, and the NFA / DFA characteristics (number of states) of bounded repeated nodes in the global DFA, sub-automata are selectively constructed based on sub-NFAs in bounded repeated nodes, thereby optimizing the comprehensive performance of sub-NFA / DFA. The backtracking avoidance mechanism effectively avoids unnecessary backtracking overhead during DFA runtime, thereby effectively improving the overall performance of DFA runtime.

[0192] The following is a description of an automatic machine construction device provided in an embodiment of the present application. The automatic machine construction device described below and the automatic machine construction method described above can be referenced to each other.

[0193] Reference Figure 8 , the automatic machine construction device provided in the embodiment of the present application includes:

[0194] A first construction module 10 is used to obtain a set of regular expressions to be processed, and generate an abstract syntax tree based on the set of regular expressions;

[0195] A second construction module 20, configured to convert the abstract syntax tree into a global NFA and determine bounded repeating nodes of the global NFA;

[0196] The third construction module 30 is used to construct a global DFA based on the global NFA, and to construct a sub-automaton of the global DFA based on the bounded repeated nodes.

[0197] In one embodiment, the third building block 30 is further used for:

[0198] Using a preset first construction algorithm to transform the global NFA to construct a global DFA;

[0199] Obtain a target repeated node corresponding to the bounded repeated node in the global DFA;

[0200] The grammatical complexity of the target repeated node is obtained, and based on the grammatical complexity, a preset second construction algorithm is used to construct the target repeated node as a sub-automaton of the global DFA.

[0201] In one embodiment, the third building block 30 is further used for:

[0202] Using the second construction algorithm, constructing the syntax tree in the target repeated node into a sub-NFA;

[0203] Determine whether there are multiple sub-NFAs in any of the target repeated nodes, and if so, merge the multiple sub-NFAs in the target repeated nodes;

[0204] Based on the grammatical complexity, determining the number of states of the sub-NFA in the target repetition node;

[0205] A sub-automaton of the global DFA is constructed according to the number of states.

[0206] In one embodiment, the sub-automaton includes a sub-DFA, an accelerated sub-DFA and an accelerated sub-NFA; the third building module 30 is further used to:

[0207] If the number of states is greater than a first preset threshold, converting the sub-NFA in the target repetitive node into a sub-DFA;

[0208] If the number of states is less than or equal to a first preset threshold and greater than a second preset threshold, converting the sub-NFA in the target repetitive node into an accelerated sub-NFA; the first preset threshold is greater than the second preset threshold;

[0209] If the number of states is less than or equal to a second preset threshold, a DFA conversion analysis is performed on the sub-NFA in the target repetitive node to convert the sub-NFA into an accelerated sub-DFA or an accelerated sub-NFA.

[0210] In one embodiment, the third building block 30 is further used for:

[0211] Performing DFA conversion analysis on the sub-NFA in the target repetitive node to determine the number of target states after the sub-NFA is DFA converted;

[0212] If the number of target states is less than or equal to a second preset threshold, converting the sub-NFA into an accelerated sub-DFA;

[0213] If the target state quantity is greater than a second preset threshold, the sub-NFA is converted into an accelerated sub-NFA.

[0214] In one embodiment, the third building block 30 is further used for:

[0215] Obtaining state parameters of the sub-NFA in the target repetitive node; the state parameters include a state set, a state transition character, an acceptance state, and a state transition table;

[0216] Divide the restricted number of states of the sub-NFA in the target repetitive node into bytes, and establish a subsequent state mask set for each byte after the division based on the state parameter;

[0217] The sub-NFA in the target repetition node is converted into an accelerated sub-NFA based on the successor state mask set.

[0218] In one embodiment, the third building block 30 is further used for:

[0219] Convert the sub-NFA in the target repetition node into a sub-DFA;

[0220] Obtaining an alphabet of the sub-DFA and an input vector of a query instruction of the sub-DFA; the input vector includes a source vector and a control code;

[0221] Constructing a source code query mask table of the alphabet based on the input vector;

[0222] The sub-DFA is converted into an accelerated sub-DFA according to the source code query mask table.

[0223] In one embodiment, the automaton construction device further includes a backtracking avoidance module, which is used to:

[0224] Analyze the first matching times of the i-th sub-regular expression that the sub-automaton can match being matched continuously in the successor node of the bounded repetition node;

[0225] When the sub-automaton completes a maximum number of hits of the i-th sub-regular expression for a preset number of times, calculating the difference between the preset number of times and the first number of matches;

[0226] If the difference is within a preset value range, obtaining an offset corresponding to the difference, and using the input corpus character at the position corresponding to the offset to perform a subsequent match of the bounded repeated node;

[0227] If the difference is not within the preset value range, a target value is calculated based on the value range; wherein the target value is the maximum value in the value set; and the difference between the preset number of times and any value in the value set is within the value range;

[0228] The offset corresponding to the target value is obtained, and the input corpus characters at the position corresponding to the offset are used to match the successor of the bounded repeated node.

[0229] Fig. 9 An example of a physical structure diagram of an electronic device is shown in FIG. Fig. 9 As shown, the electronic device may include: a processor 910, a communication interface 920, a memory 930 and a communication bus 940, wherein the processor 910, the communication interface 920 and the memory 930 communicate with each other through the communication bus 940. The processor 910 may call a computer program in the memory 930 to execute the steps of the automatic machine construction method, for example including:

[0230] Obtaining a set of regular expressions to be processed, and generating an abstract syntax tree based on the set of regular expressions;

[0231] Converting the abstract syntax tree into a global NFA and determining bounded repeating nodes of the global NFA;

[0232] A global DFA is constructed based on the global NFA, and a sub-automaton of the global DFA is constructed based on the bounded repeated nodes.

[0233] In addition, the logic instructions in the above-mentioned memory 930 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk.

[0234] On the other hand, an embodiment of the present application further provides a computer program product, the computer program product including a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer can perform the steps of the automatic machine construction method provided in the above embodiments, for example, including:

[0235] Obtaining a set of regular expressions to be processed, and generating an abstract syntax tree based on the set of regular expressions;

[0236] Converting the abstract syntax tree into a global NFA and determining bounded repeating nodes of the global NFA;

[0237] A global DFA is constructed based on the global NFA, and a sub-automaton of the global DFA is constructed based on the bounded repeated nodes.

[0238] On the other hand, an embodiment of the present application further provides a processor-readable storage medium, wherein the processor-readable storage medium stores a computer program, wherein the computer program is used to enable the processor to execute the steps of the automaton construction method provided in the above embodiments, for example, including:

[0239] Obtaining a set of regular expressions to be processed, and generating an abstract syntax tree based on the set of regular expressions;

[0240] Converting the abstract syntax tree into a global NFA and determining bounded repeating nodes of the global NFA;

[0241] A global DFA is constructed based on the global NFA, and a sub-automaton of the global DFA is constructed based on the bounded repeated nodes.

[0242] The processor-readable storage medium can be any available medium or data storage device that can be accessed by the processor, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NANDFLASH), solid-state drive (SSD)), etc.

[0243] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0244] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0245] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for constructing an automatic machine, characterized in that: include: Obtaining a set of regular expressions to be processed, and generating an abstract syntax tree based on the set of regular expressions; Converting the abstract syntax tree into a global NFA and determining bounded repeating nodes of the global NFA; A global DFA is constructed based on the global NFA, and a sub-automaton of the global DFA is constructed based on the bounded repeated nodes.

2. The method for constructing an automatic machine according to claim 1, characterized in that: The step of constructing a global DFA based on the global NFA, and constructing a sub-automaton of the global DFA based on the bounded repeated nodes, comprises: Using a preset first construction algorithm to transform the global NFA to construct a global DFA; Obtain a target repeated node corresponding to the bounded repeated node in the global DFA; The grammatical complexity of the target repeated node is obtained, and based on the grammatical complexity, a preset second construction algorithm is used to construct the target repeated node as a sub-automaton of the global DFA.

3. The method for constructing an automatic machine according to claim 2, characterized in that: The method of constructing the target repeated node as a sub-automaton of the global DFA based on the grammatical complexity by using a preset second construction algorithm includes: Using the second construction algorithm, constructing the syntax tree in the target repeated node into a sub-NFA; Determine whether there are multiple sub-NFAs in any of the target repeated nodes, and if so, merge the multiple sub-NFAs in the target repeated nodes; Based on the grammatical complexity, determining the number of states of the sub-NFA in the target repetition node; A sub-automaton of the global DFA is constructed according to the number of states.

4. The method for constructing an automatic machine according to claim 3, characterized in that: The sub-automaton includes a sub-DFA, an accelerated sub-DFA and an accelerated sub-NFA; the sub-automaton of the global DFA is constructed according to the number of states, including: If the number of states is greater than a first preset threshold, converting the sub-NFA in the target repetitive node into a sub-DFA; If the number of states is less than or equal to a first preset threshold and greater than a second preset threshold, converting the sub-NFA in the target repetitive node into an accelerated sub-NFA; the first preset threshold is greater than the second preset threshold; If the number of states is less than or equal to a second preset threshold, a DFA conversion analysis is performed on the sub-NFA in the target repetitive node to convert the sub-NFA into an accelerated sub-DFA or an accelerated sub-NFA.

5. The method for constructing an automatic machine according to claim 4, characterized in that: The performing DFA conversion analysis on the sub-NFA in the target repetitive node to convert the sub-NFA into an accelerated sub-DFA or an accelerated sub-NFA includes: Performing DFA conversion analysis on the sub-NFA in the target repetitive node to determine the number of target states after the sub-NFA is DFA converted; If the number of target states is less than or equal to a second preset threshold, converting the sub-NFA into an accelerated sub-DFA; If the target state quantity is greater than a second preset threshold, the sub-NFA is converted into an accelerated sub-NFA.

6. The method for constructing an automatic machine according to claim 4, characterized in that: The converting the sub-NFA in the target repetitive node into an accelerated sub-NFA comprises: Obtaining state parameters of the sub-NFA in the target repetitive node; the state parameters include a state set, a state transition character, an acceptance state, and a state transition table; Divide the restricted number of states of the sub-NFA in the target repetitive node into bytes, and establish a subsequent state mask set for each byte after the division based on the state parameter; The sub-NFA in the target repetition node is converted into an accelerated sub-NFA based on the successor state mask set.

7. The method for constructing an automatic machine according to claim 4, characterized in that: The converting the sub-NFA in the target repetitive node into an accelerated sub-DFA comprises: Convert the sub-NFA in the target repetition node into a sub-DFA; Obtaining an alphabet of the sub-DFA and an input vector of a query instruction of the sub-DFA; the input vector includes a source vector and a control code; Constructing a source code query mask table of the alphabet based on the input vector; The sub-DFA is converted into an accelerated sub-DFA according to the source code query mask table.

8. The method for constructing an automatic machine according to claim 1, characterized in that: After constructing a global deterministic finite automaton DFA based on the global NFA and constructing a sub-automaton of the global DFA based on the bounded repeated nodes, the method further includes: Analyze the first matching times of the i-th sub-regular expression that the sub-automaton can match being matched continuously in the successor node of the bounded repetition node; When the sub-automaton completes a maximum number of hits of the i-th sub-regular expression for a preset number of times, calculating the difference between the preset number of times and the first number of matches; If the difference is within a preset value range, obtaining an offset corresponding to the difference, and using the input corpus character at the position corresponding to the offset to perform a subsequent match of the bounded repeated node; If the difference is not within the preset value range, a target value is calculated based on the value range; wherein the target value is the maximum value in the value set; and the difference between the preset number of times and any value in the value set is within the value range; The offset corresponding to the target value is obtained, and the input corpus characters at the position corresponding to the offset are used to perform a subsequent match of the bounded repeated node.

9. An automatic machine construction device, characterized in that: include: A first building module is used to obtain a set of regular expressions to be processed, and generate an abstract syntax tree based on the set of regular expressions; A second building block, configured to convert the abstract syntax tree into a global NFA and determine bounded repeating nodes of the global NFA; The third building module is used to build a global DFA based on the global NFA, and to build a sub-automaton of the global DFA based on the bounded repeated nodes.

10. An electronic device comprising a processor and a memory storing a computer program, characterized in that: When the processor executes the computer program, the steps of the automatic machine construction method according to any one of claims 1 to 8 are implemented.