A command parsing processing method and device

By building a command tree and using a tree structure to parse commands, the problem of unstandard command parsers and inconvenient addition of commands in the existing technology is solved, efficient parsing and associating functions are realized, and the friendship of human-computer interaction is improved.

CN114489594BActive Publication Date: 2025-02-11CHINA TELECOM CLOUD TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111617513.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2025-02-11
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

In the prior art, the command parser is not standard, it is inconvenient to add commands, and the command execution efficiency is not high, and the lack of associative functions leads to inconvenience in developers.

Method used

The command tree is built by defining keyword nodes, value nodes and end nodes, and the tree structure is used to analyze commands step by step, supporting associative functions, and improving human-computer interaction friendliness.

Benefits of technology

It realizes the standardization and simplification of the command parser, improves the convenience and execution efficiency of command addition, supports the association function, and improves the friendliness of human-computer interaction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114489594B_ABST
    Figure CN114489594B_ABST
Patent Text Reader

Abstract

The present invention discloses a command parsing method and device. The command parsing method receives an input command to be parsed and uses a command tree framework constructed in a command parser to parse the command. During parsing, nodes at all levels defined in the command tree are matched to finally complete the parsing process. As a result, the command parsing method does not backtrack, thereby achieving efficient parsing of commands. In addition, the command parsing method also supports association, thereby improving the friendliness of human-computer interaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software development, and in particular to a command parsing processing method and device. Background Art

[0002] The command parser is used to receive commands (from the controller or the user), parse them, pass the parsed results to each functional module to obtain the final result, and finally return the result.

[0003] The command parser is a part of human-computer interaction (such as Linux shell). Users can interact with the system by entering commands. The most important thing in the process of interaction (or management) between the controller and the next-generation cloud wall is the processing of various commands. Most parsers are inconvenient to add commands, the methods are not standard, the command execution efficiency is low, or there is a lack of association and other functions, which makes it inconvenient for developers to use. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a command parsing processing method and device to solve the technical problems in the prior art that the command parser is non-standard and it is inconvenient to add commands.

[0005] The technical solution proposed by the present invention is as follows:

[0006] A first aspect of an embodiment of the present invention provides a method for constructing a command parser, comprising: constructing a pre-set level of a command tree in the command parser based on keyword nodes, wherein the keyword nodes are used to distinguish different branches of the same terminal node; constructing an intermediate level of the command tree based on value nodes; constructing a last level of the command tree based on the terminal node, wherein a processing function is defined in the terminal node, and any two levels of nodes in the command tree are connected using child pointers, and nodes at the same level of the command tree are connected using sibling pointers.

[0007] Optionally, the command tree further includes: a cutoff replacement node, the cutoff replacement node is used to identify the last node of the sibling pointer, and when a new keyword node is added to the command tree, the cutoff replacement node is replaced with the new keyword node, and a new cutoff replacement node is added.

[0008] Optionally, the command tree further includes: a reuse node, and when the subsequent connection nodes of the first-level keyword node of the command tree are an asymmetric structure, the reuse node is configured at an asymmetric position.

[0009] The second aspect of an embodiment of the present invention provides a command parsing processing method, including: receiving an input command to be parsed; parsing the command to be parsed using a command parser constructed using the command parser construction method described in the first aspect of the embodiment of the present invention and any one of the first aspects; and calling a processing function according to an end node in the parsing result to obtain a processing result.

[0010] Optionally, a command parser is used to parse the command to be parsed, including: matching the command to be parsed with the first level of the command tree in the command parser; matching the node connected with the command to be parsed according to the child pointer of the keyword node in the first level matching result; when the node connected with the child pointer is matched successfully, determining whether the current matching node is a terminal node; if it is a terminal node, the parsing is completed.

[0011] Optionally, a command parser is used to parse the command to be parsed, and the method further includes: when a match with a child pointer connection node is not successful, determining a sibling pointer connection node according to the child pointer connection node; matching the command to be parsed according to the sibling pointer connection node; if a match with the sibling pointer connection node is not successful, determining whether the current node is a cutoff replacement node; and when the current node is a cutoff replacement node, parsing fails.

[0012] A third aspect of an embodiment of the present invention provides a device for constructing a command parser, comprising: a first construction module, used to construct a front preset level of a command tree in the command parser based on keyword nodes, wherein the keyword nodes are used to distinguish different branches of the same terminal node; a second construction module, used to construct an intermediate level of the command tree based on value nodes; a third construction module, used to construct the last level of the command tree based on the terminal node, wherein a processing function is defined in the terminal node, and any two levels of nodes in the command tree are connected by child pointers, and nodes at the same level of the command tree are connected by sibling pointers.

[0013] The fourth aspect of an embodiment of the present invention provides a command parsing processing device, including: a command receiving module, used to receive an input command to be parsed; a parsing module, used to parse the command to be parsed using a command parser constructed by the construction method of the command parser described in the first aspect of the embodiment of the present invention and any one of the first aspects; a processing module, used to call a processing function according to the terminal node in the parsing result to obtain a processing result.

[0014] A fifth aspect of an embodiment of the present invention provides a computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the command parser construction method as described in the first aspect of the embodiment of the present invention and any one of the first aspects, or the command parsing processing method as described in the second aspect of the embodiment of the present invention and any one of the second aspects.

[0015] A sixth aspect of an embodiment of the present invention provides an electronic device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to execute the command parser construction method as described in the first aspect of the embodiment of the present invention and any one of the first aspects, or the command parsing processing method as described in the second aspect of the embodiment of the present invention and any one of the second aspects.

[0016] The technical solution provided by the present invention has the following effects:

[0017] The command parser construction method and device provided by the embodiment of the present invention constructs a command tree in the command parser by defining keyword nodes, value nodes and terminal nodes, so that the construction of the command parser is simple and standardized. In addition, since the command parser adopts the framework of the command tree, when the command parser is subsequently used for parsing, the command is parsed level by level using a tree structure, and backtracking does not occur.

[0018] The command parsing processing method and device provided by the embodiment of the present invention receives an input command to be parsed, and uses the command tree framework constructed in the command parser to parse the command. During the parsing, the nodes at all levels defined in the command tree are matched, and the parsing process is finally completed. As a result, the command parsing processing method does not backtrack, thereby achieving efficient parsing of the command. In addition, the command parsing processing method also supports association, which improves the friendliness of human-computer interaction. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 is a flowchart of a method for constructing a command parser according to an embodiment of the present invention;

[0021] Figure 2 is a schematic diagram of a command tree architecture constructed according to a method for constructing a command parser according to an embodiment of the present invention;

[0022] Figure 3 is a flowchart of a command parsing method according to an embodiment of the present invention;

[0023] Figure 4 is a flowchart of a command parsing method according to another embodiment of the present invention;

[0024] Figure 5 is a structural block diagram of a device for constructing a command parser according to an embodiment of the present invention;

[0025] Figure 6 is a structural block diagram of a command parsing processing device according to an embodiment of the present invention;

[0026] Figure 7 is a schematic diagram of the structure of a computer-readable storage medium provided according to an embodiment of the present invention;

[0027] Figure 8 is a schematic diagram of the structure of an electronic device provided according to an embodiment of the present invention. DETAILED DESCRIPTION

[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0029] The terms "first", "second", "third", "fourth", 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 data used in this way can be interchanged where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0030] According to an embodiment of the present invention, a method for constructing a command parser is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0031] In this embodiment, a method for constructing a command parser is provided, which can be used in electronic devices such as computers, mobile phones, tablet computers, etc. Figure 1 is a flowchart of a method for constructing a command parser according to an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:

[0032] Step S101: constructing a pre-set level of a command tree in a command parser according to keyword nodes, wherein the keyword nodes are used to distinguish different branches of the same terminal node.

[0033] Specifically, the keyword node is recorded as KW_NODE / KW_NODE_WHICH. The keyword node can be pre-set based on different application scenarios to facilitate the command parser to parse commands in different scenarios. For example, when the command parser is applied to a cloud firewall, Figure 2 As shown, the keyword nodes include: set, unset, debug, undebug, show, interface, ffilter, src-ip and dst-port, etc.

[0034] When the above keyword nodes are used to set the pre-preset level of the command tree, the number of pre-preset levels can be determined based on actual conditions. For example, in the cloud firewall, the pre-preset level of the command tree includes the first three levels, among which set, unset, debug, undebug, and show are set at the first level of the command tree, interface and ffilter are set at the second level of the command tree, and src-ip and dst-port are set at the third level of the command tree. In addition, in addition to the above keyword nodes, other keyword nodes can also be set at the first level, second level, and third level of the command tree according to actual needs.

[0035] When setting the previous preset level of the command tree, the keyword nodes between the previous level and the next level are connected by child pointers, for example, the first-level keyword node set and the second-level keyword node interface are connected by child pointers. The keyword nodes at the same level are connected by sibling pointers, for example, the first-level keyword node set and the first-level keyword node unset are connected by sibling pointers.

[0036] Step S102: Construct the middle level of the command tree according to the value node. Specifically, the value node is recorded as VALUE_NODE, and the value node can be a string or a number type, which is used to represent the specific value in the command. For example, the value node includes name, id, ip, value, and number, etc. Among them, when the value node is set in the command tree, it is usually set after the keyword node. Therefore, the value node is set at the middle level of the command tree, or after the keyword node, and is connected to the keyword node using a child pointer.

[0037] Step S103: Construct the last level of the command tree according to the terminal node, define a processing function in the terminal node, connect any two levels of nodes in the command tree with child pointers, and connect the nodes at the same level of the command tree with brother pointers. The processing function will be called at the end of the command parser parsing, so the terminal node is defined at the last level of the command tree, and the processing function is defined in the terminal node, and the terminal node is recorded as EOL_NODE. In addition, other keyword nodes can be set between the last level and the middle level according to actual needs to facilitate the parsing of the command parser. For example, keyword nodes of other levels are also set between the middle level and the last level, such as promisc, link, up, and down.

[0038] In one implementation, for the keyword nodes, value nodes, and terminal nodes, the attributes of the nodes are as shown in Table 1 below:

[0039] Table 1

[0040] child Child pointer sibling Brother pointer type Node type (keyword / value / final) subtype Node Subtype index Value (or which keyword) node index value value (or which keyword) node tag value token Node keyword (value / end node no) help Node help information func Node processing function

[0041] For ease of use, the keyword nodes, value nodes, and terminal nodes are implemented in a static definition. Specifically, the following code is used to define the keyword nodes, value nodes, and terminal nodes:

[0042]

[0043]

[0044]

[0045] Specifically, for this command tree, the KW_NODE macro is used to define the node:

[0046] KW_NODE(interface, interface_name, none, "interface", "the specific interface");

[0047] VALUE_NODE(interface_name, interface_promisc, none, "interface name", 1, STR);

[0048] KW_NODE_WHICH(interface_promisc, interface_promisc_on, interface_kni, "promisc", "the promisc on the interface", 1, 1);

[0049] EOL_NODE(interface_eol,set_interface_cli);

[0050] KW_NODE_WHICH(interface_link_down,interface_eol,none,"down","make the interface link down",2,2);

[0051] KW_NODE_WHICH(interface_link_up,interface_eol,interface_link_down,"up","make the interface link up",2,1);

[0052] KW_NODE_WHICH(interface_kni_off,interface_eol,none,"off","forward2kni off",2,2);

[0053] KW_NODE_WHICH(interface_kni_on,interface_eol,interface_kni_off,"on","forward2kni on",2,1);

[0054] KW_NODE_WHICH(interface_promisc_off,interface_eol,none,"off","promisc off",2,2);

[0055] KW_NODE_WHICH(interface_promisc_on,interface_eol,interface_promisc_off,"on","promisc on",2,1);

[0056] KW_NODE_WHICH(interface_link,interface_link_up,none,"link","interface link state",1,3);

[0057] KW_NODE_WHICH(interface_kni, interface_kni_on, interface_link, "forward2kni", "make the interface forward2kni", 1, 2);

[0058] The command parser construction method provided by the embodiment of the present invention constructs a command tree in the command parser by defining keyword nodes, value nodes and terminal nodes, so that the construction of the command parser is simple and standardized. In addition, since the command parser adopts the framework of the command tree, when the command parser is subsequently used for parsing, the command is parsed level by level using a tree structure, and backtracking does not occur.

[0059] The command parser construction method provided by the embodiment of the present invention can construct the framework of the command tree in the command parser by standardizing the static definition of keyword nodes, value nodes and terminal nodes. At the same time, the child pointer of the upper node points to the first lower node, and other child nodes are obtained through the sibling pointer of the first lower node.

[0060] In one embodiment, the command tree also includes: a cutoff replacement node, which is used to identify the last node of the sibling pointer. When a new keyword node is added to the command tree, the cutoff replacement node is replaced with the new keyword node, and a new cutoff replacement node is added.

[0061] Specifically, Figure 2 As shown, a cut-off replacement node is also defined in the command tree, which is recorded as the none node. The none node can be used as the last node of any level, indicating that there are no other nodes after this level. For example, if the second-level keyword node only sets two nodes, interface and ffilter, the brother pointer of the ffilter node is also connected to the none node. In the command tree, only one none node can be set, which is globally unique. In addition, if a new command node needs to be added in the command tree, such as a new keyword node needs to be added, the terminal node corresponding to the new keyword node can be determined first, and then the new keyword node can be replaced by the none node, and then a new none node can be set.

[0062] In one embodiment, the command tree further includes: a reuse node, and when the subsequent connection nodes of the first-level keyword nodes of the command tree are an asymmetric structure, the reuse node is configured at an asymmetric position.

[0063] Specifically, in the constructed command tree framework, most of them are symmetrical structures. For example, set and unset are addition and deletion. Symmetry means that the subsequent nodes added are the same as the subsequent nodes deleted, such as adding configuration set interfaceeth0link up and deleting configuration unset interface eth0link up. In this way, the subsequent nodes added and deleted can be set to the same one, that is, the child pointers of set and unset both point to interface. However, in this command tree framework, it is not a completely symmetrical structure. For example, adding configuration set ffilter src-ip 1.1.1.1dst-port 23 and the corresponding deleting configuration unset ffilter<id> are asymmetric structures. At this time, if the two structures are defined separately, the command tree will be relatively large. Therefore, if Figure 2 As shown, a reuse node can be defined in the command tree, which is recorded as a TEST_UNSET node. The reuse node is defined in an asymmetric structure, such as the above asymmetric structure, where the TEST_UNSET node is set between the ffilter node and the id. The TEST_UNSET node represents the reuse of the previous node, namely setffilter and unset ffilter.

[0064] At the same time, in the command tree framework, except for the none node and the terminal node, all nodes have child pointers and sibling pointers. Each node can be regarded as a tree structure with the node as the root.

[0065] Moreover, the command parser constructed by the construction method of the command parser is a lightweight (regardless of the complexity of the code or the difficulty of developers to add and modify), efficient, and associative command parser that can not only connect to the commands issued by the management control plane, but also provide a direct, simple and friendly user command execution interface. Developers can also quickly add new commands through standardized interfaces to improve development efficiency, thereby making the cloud firewall more standardized, modular, and easy to use. In addition, the constructed command parser has complete functions and efficient implementation, and can be applied to both the nvf mode and the bare metal mode; the control plane function is simplified and the execution is efficient; it can be easily connected to the controller configuration and issued to achieve standard unification, and the user can use it simply and intuitively; it has strong scalability, simple and clear code, and it is convenient for developers to add new commands.

[0066] The command parser construction method provided by the embodiment of the present invention, through the setting of the cut-off replacement node, when adding a new command, only needs to first define the processing function corresponding to the new command, and then add the new command to the command tree, and replace the cut-off replacement node. Therefore, the construction method makes the addition of new commands more convenient, and the definition of the reused node also makes the command tree framework in the command parser more concise. In addition, after the cloud firewall is started, the control plane will issue commands to configure various features of the cloud firewall. Therefore, the command parser constructed by the construction method can standardize and simplify the control plane configuration, reduce the error rate, and various cloud products can also be managed through the command parser by issuing configurations through the control plane.

[0067] The embodiment of the present invention also provides a command parsing method, such as Figure 3 As shown, the method comprises the following steps:

[0068] Step S201: receiving an input command to be parsed. After the command parser is constructed by the above construction method, the command parser can be used to parse the command. Specifically, the command to be parsed is input into the command parser, and the command parser parses the command by reading the command word by word.

[0069] Step S202: The command parser constructed by the command parser construction method in the above embodiment parses the command to be parsed. Specifically, when parsing the command to be parsed, the command read in word by word is matched with the nodes in the command tree defined in the naming parser step by step. The parsing process is completed until the corresponding terminal node is matched.

[0070] Step S203: Call the processing function according to the terminal node in the analysis result to obtain the processing result. When the final analysis matches the terminal node, call the processing function defined in the terminal node. The processing function performs processing according to the analysis result and the definition of the command. At the same time, there may be operations such as applying for memory and printing output during the processing process. Return after the execution is completed. Specifically, the processing function execution result is obtained through the processing of the processing function, and subsequent operations may be performed. Finally, return to wait for the user's next command input.

[0071] In one embodiment, in the constructed command parser, "tab" or "?" can also be recognized. When the user enters "tab" or "?" after entering a partial command, the command parser can also traverse the child pointer and the sibling pointer according to the currently parsed tree structure to provide matching options. If there is only one matching option and "tab" is used, the command is completed.

[0072] The command parsing processing method provided by the embodiment of the present invention receives an input command to be parsed, and uses the command tree framework constructed in the command parser to parse the command. During the parsing, the nodes at all levels defined in the command tree are matched, and the parsing process is finally completed. As a result, the command parsing processing method does not have backtracking, thereby achieving efficient parsing of the command. In addition, the command parsing processing method also supports association, which improves the friendliness of human-computer interaction.

[0073] In one embodiment, a command parser is used to parse a command to be parsed, including: matching the command to be parsed with the first level of the command tree in the command parser; matching the command to be parsed according to the child pointer connection node of the keyword node in the first level matching result; when the node connected to the child pointer is successfully matched, determining whether the current matching node is a terminal node; if it is a terminal node, parsing is completed. When the node connected to the child pointer is not successfully matched, determining its sibling pointer connection node according to the child pointer connection node; matching the command to be parsed according to the sibling pointer connection node; if the node connected to the sibling pointer is not successfully matched, determining whether the current node is a cut-off replacement node; when the current node is a cut-off replacement node, parsing fails.

[0074] Specifically, Figure 4 As shown, when the command parser is used for parsing, the command read word by word is first matched with the first-level keyword node of the command tree. For example, the first-level keyword node can be traversed to find the keyword node that matches the command; after the match is successful, the child pointer connection node of the successfully matched keyword node is traversed for matching. For example, if the command to be parsed is "set flow policy", the first-level matches the set node, and the command to be parsed becomes "flowpolicy". At this time, the current node to be matched points to the child node of the first-level matching node (that is, the child node of the keyword node set node) for matching. If the match is successful, the child pointer connection node is continued to be obtained until the end node is matched, or when the command to be parsed points to the end and the current matching node is already the end node, the parsing process is completed. For example, the command to be parsed is "set flow policy aaa permit". At this time, if the command to be parsed points to permit and the currently matched node aaa is already the end node, the match cannot be considered successful at this time; if the node aaa has a child end node that matches the command to be parsed permit, the parsing can be considered successful.

[0075] If the node connected to the child pointer fails to match, the node's sibling pointer connection node is obtained for matching. If the sibling pointer connection node fails to match the none node, the parsing failure is returned. Specifically, during matching, the command to be parsed and the current node are constantly changing. When the node connected to the child pointer fails to match, it means that the previous level matches successfully, the command to be parsed is moved back and updated, and the current node is updated to the child node of the previous level, and the current node starts to match the current command to be parsed.

[0076] If the parsing is successful, the result type (add / delete) of the command obtained by the parsing, the value of the number or string is stored in the structure shown in Table 2, and the processing function of the terminal node is obtained, and finally the parsing result is passed to the processing function and called.

[0077] Table 2

[0078] mode Parsing result type number_cnt The number of numeric value nodes detected number[] The detected number in the command which_cnt The number of which keyword nodes detected which[] The detected which value in the command string_cnt The number of string value nodes detected string[][] Detected string in command … Additional Information

[0079] The embodiment of the present invention also provides a device for constructing a command parser, such as Figure 5 As shown, the device comprises:

[0080] The first construction module is used to construct a pre-set level of the command tree in the command parser according to the keyword node, and the keyword node is used to distinguish different branches of the same terminal node; the specific content can be found in the corresponding part of the above method embodiment, which will not be repeated here.

[0081] The second construction module is used to construct the middle level of the command tree according to the value node; the specific content can be found in the corresponding part of the above method embodiment, which will not be repeated here.

[0082] The third construction module is used to construct the last level of the command tree according to the terminal node, the processing function is defined in the terminal node, any two levels of nodes in the command tree are connected by child pointers, and the nodes at the same level of the command tree are connected by sibling pointers. For details, please refer to the corresponding part of the above method embodiment, which will not be repeated here.

[0083] The command parser construction device provided by the embodiment of the present invention constructs a command tree in the command parser by defining keyword nodes, value nodes and terminal nodes, so that the construction of the command parser is simple and standardized. In addition, since the command parser adopts the framework of the command tree, when the command parser is subsequently used for parsing, the tree structure is used to parse the command level by level, and backtracking will not occur.

[0084] For a detailed description of the functions of the device for constructing the command parser provided in the embodiment of the present invention, please refer to the description of the method for constructing the command parser in the above embodiment.

[0085] The embodiment of the present invention also provides a command parsing and processing device, such as Figure 6 As shown, the device comprises:

[0086] The command receiving module is used to receive the input command to be parsed; the specific content can be found in the corresponding part of the above method embodiment, which will not be repeated here.

[0087] The parsing module is used to parse the command to be parsed by using the command parser constructed by the command parser construction method described in the above embodiment; the specific content can be found in the corresponding part of the above method embodiment, which will not be repeated here.

[0088] The processing module is used to call the processing function according to the terminal node in the parsing result to obtain the processing result. For the specific content, please refer to the corresponding part of the above method embodiment, which will not be repeated here.

[0089] The command parsing processing device provided by the embodiment of the present invention receives an input command to be parsed, and uses the command tree framework constructed in the command parser to parse the command. During the parsing, the nodes at all levels defined in the command tree are matched, and the parsing process is finally completed. Therefore, the command parsing processing method does not have backtracking, thereby achieving efficient parsing of the command. In addition, the command parsing processing method also supports association, which improves the friendliness of human-computer interaction.

[0090] For a detailed description of the functions of the command parsing and processing device provided in the embodiment of the present invention, please refer to the description of the command parsing and processing method in the above embodiment.

[0091] The embodiment of the present invention also provides a storage medium, such as Figure 7 As shown, a computer program 601 is stored thereon, and when the instruction is executed by the processor, the steps of the command parser construction method and the command parsing processing method in the above-mentioned embodiment are implemented. The storage medium also stores audio and video stream data, feature frame data, interaction request signaling, encrypted data, and preset data size, etc. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (Hard Disk Drive, abbreviated: HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.

[0092] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.

[0093] The embodiment of the present invention further provides an electronic device, such as Figure 8 As shown, the electronic device may include a processor 51 and a memory 52, wherein the processor 51 and the memory 52 may be connected via a bus or other means. Figure 8 The example of connecting through bus is taken in the following.

[0094] The processor 51 may be a central processing unit (CPU). The processor 51 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.

[0095] The memory 52 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as the corresponding program instructions / modules in the embodiments of the present invention. The processor 51 executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions and modules stored in the memory 52, that is, the command parser construction method and command parsing processing method in the above method embodiments are implemented.

[0096] The memory 52 may include a program storage area and a data storage area, wherein the program storage area may store an application required for operating the device and at least one function; the data storage area may store data created by the processor 51, etc. In addition, the memory 52 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 52 may optionally include a memory remotely arranged relative to the processor 51, and these remote memories may be connected to the processor 51 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0097] The one or more modules are stored in the memory 52 and when executed by the processor 51, perform the following steps: Figure 1 -4 shows the command parser construction method and command parsing processing method in the embodiment.

[0098] For details of the above electronic equipment, please refer to Figures 1 to 4 The corresponding related descriptions and effects in the illustrated embodiments can be understood and will not be repeated here.

[0099] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A command parsing method, characterized in that: include: Constructing a pre-set level of a command tree in a command parser according to keyword nodes, wherein the keyword nodes are used to distinguish different branches of the same terminal node; constructing an intermediate level of the command tree according to the value nodes; The last level of the command tree is constructed according to the terminal node to obtain a command parser, wherein a processing function is defined in the terminal node, any two levels of nodes in the command tree are connected by child pointers, and the nodes at the same level of the command tree are connected by sibling pointers, and the command tree further comprises: a cutoff replacement node, wherein the cutoff replacement node is used to identify the last node of the sibling pointer, and when a new keyword node is added to the command tree, the cutoff replacement node is replaced by the new keyword node, and a new cutoff replacement node is added; Receive input commands to be parsed; Use a command parser to parse the command to be parsed; Call the processing function according to the terminal node in the parsing result to obtain the processing result; The command parser is used to parse the command to be parsed, including: Match the command to be parsed with the first level of the command tree in the command parser; Match the node with the command to be parsed according to the child pointer of the keyword node in the first-level matching result; When the child pointer connection node is not matched successfully, the sibling pointer connection node is determined according to the child pointer connection node; Matching the node with the command to be parsed according to the sibling pointer connection node; If the node connected to the sibling pointer does not match successfully, determine whether the current node is a cutoff replacement node; When the current node is a cutoff replacement node, parsing fails.

2. The command parsing method according to claim 1, characterized in that: The command to be parsed is parsed by a command parser, which also includes: When the node connected to the child pointer is successfully matched, determine whether the current matching node is the final node; If it is a terminal node, the parsing is complete.

3. The command parsing method according to claim 1, characterized in that: The command tree also includes: a multiplexing node, When the subsequent connection nodes of the first-level keyword nodes of the command tree are of an asymmetric structure, the multiplexing nodes are configured at asymmetric positions.

4. A command parsing and processing device, characterized in that: include: A first construction module is used to construct a pre-set level of a command tree in a command parser according to keyword nodes, wherein the keyword nodes are used to distinguish different branches of the same terminal node; A second construction module, configured to construct an intermediate level of the command tree according to a value node; A third construction module is used to construct the last level of the command tree according to the terminal node to obtain a command parser, wherein a processing function is defined in the terminal node, any two levels of nodes in the command tree are connected by child pointers, and the nodes at the same level of the command tree are connected by sibling pointers, and the command tree further includes: a cutoff replacement node, the cutoff replacement node is used to identify the last node of the sibling pointer, and when a new keyword node is added to the command tree, the cutoff replacement node is replaced by the new keyword node, and a new cutoff replacement node is added; A command receiving module, used for receiving input commands to be parsed; A parsing module, used for parsing the command to be parsed using a command parser; The processing module is used to call the processing function according to the terminal node in the parsing result to obtain the processing result; The command parser is used to parse the command to be parsed, including: Match the command to be parsed with the first level of the command tree in the command parser; Match the node with the command to be parsed according to the child pointer of the keyword node in the first-level matching result; When the child pointer connection node is not matched successfully, the sibling pointer connection node is determined according to the child pointer connection node; Matching the node with the command to be parsed according to the sibling pointer connection node; If the node connected to the sibling pointer does not match successfully, determine whether the current node is a cutoff replacement node; When the current node is a cutoff replacement node, parsing fails.

5. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the command parsing processing method according to any one of claims 1 to 3.

6. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the command parsing method according to any one of claims 1 to 3 by executing the computer instructions.

Citation Information

Patent Citations

  • Command construction and analysis method of command line interface

    CN102902547A

  • System and method for extended structure command line

    CN108228161A