Method for realizing functional function, interpreter and computer readable storage medium

By extracting function names and parameters in function strings and building and executing instance objects of function functions, the problem of high programming difficulties in existing high-level programming languages ​​for professional purposes is solved, and the effect of simplifying the programming process and improving programming efficiency is achieved.

CN113535139BActive Publication Date: 2025-02-11BEIJING A&E TECH
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010297372.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-04-15
Publication Date
2025-02-11
Estimated Expiration
2040-04-15

AI Technical Summary

Technical Problem

In some professional application scenarios, existing high-level programming languages ​​have complex syntax and high flexibility, resulting in increased programming difficulty, and simple syntax rules are required to design to form a customized interpreter.

Method used

By extracting the function name and function parameters in the input function string, build an instance object of the function and execute the instance object to simplify the programming process and improve programming efficiency.

Benefits of technology

It realizes that function functions are directly executed by inputting function strings that conform to preset formats without using high-level programming languages, which reduces the programming threshold, simplifies the programming process, and improves programming efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113535139B_ABST
    Figure CN113535139B_ABST
Patent Text Reader

Abstract

The present application discloses a method for implementing a function, an interpreter and a computer-readable storage medium, the method comprising: obtaining an input function, the function function being input in the form of a function string; parsing the function string, and extracting a function name and function parameters of the function from the function string; creating an instance object of the function according to the function name and function parameters; and executing the instance object. The method provided by the present application can simplify the programming process, improve programming efficiency, and reduce the requirements for programmers.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of programming technology, and in particular to a method for implementing a functional function, an interpreter, and a computer-readable storage medium. Background Art

[0002] General high-level programming languages, such as C, C++, and Java, have complex syntax and rich semantics. When programming in these languages, operators are required to have basic professional knowledge.

[0003] However, for some professional application scenarios, in order to realize the software design of certain specific functions, complex grammar and flexible rules are not required. Therefore, in order to reduce the difficulty of programming, it is necessary to design some simple grammar rules based on the general high-level programming language to form a customized interpreter. Summary of the invention

[0004] The present application provides a method for implementing a function function, which constructs an instance object of the function function by extracting the function name and function parameters in an input function string, and executes the instance object, and then executes the function function, which can ultimately simplify the programming process and improve programming efficiency.

[0005] The first aspect of the present application provides an implementation method of an interpreter, the implementation method comprising: obtaining an input function, the function function being input in the form of a function string; parsing the function string, and extracting a function name and function parameters of the function function from the function string; creating an instance object of the function function according to the function name and the function parameters; and executing the instance object.

[0006] Based on the first aspect of the present application, the first implementation manner of the first aspect of the present application, before creating the instance object of the function function according to the function name and the function parameters, the method also includes: determining whether the function name exists in a preset function library; if the function name exists in the function library, checking through a preset checker whether the function type and / or the number of parameters of the function parameters conform to the function description corresponding to the function name; if the function type and / or the number of parameters of the function parameters conform to the function description corresponding to the function name, executing the step of creating the instance object of the function function according to the function name and the function parameters; if the function type and / or the number of parameters of the function parameters do not conform to the function description corresponding to the function name, performing an error processing.

[0007] By checking the extracted function name and function parameters, it can be ensured that the correct instance object is subsequently established.

[0008] Based on the first aspect of the present application to the first implementation method of the first aspect, the second implementation method of the first aspect of the present application, the determining whether the function name exists in a preset function library includes: determining whether there is a standard function name in the function library whose similarity with the function name exceeds a similarity threshold; if it is determined that the function library contains a standard function name whose similarity with the function name exceeds a similarity threshold, determining that the function name exists in the function library; if it is determined that the function library does not contain a standard function name whose similarity with the function name exceeds a similarity threshold, determining that the function name does not exist in the function library.

[0009] When the similarity between the extracted function name and the standard function name in the function library exceeds the similarity threshold, it is determined that the extracted function name exists in the function library, which can avoid the phenomenon that the user cannot successfully create an instance object due to incorrect function name input when entering the function string.

[0010] Based on the first aspect of the present application to the first implementation method and the second implementation method of the first aspect, the third implementation method of the first aspect of the present application, the extracting the function name of the functional function from the function string includes: starting from the character at the beginning of the function string, traversing the characters in the function string in sequence until the current traversed character is the first specific character; intercepting the characters from the beginning of the function string to the left of the first specific character as the function name.

[0011] The above method for extracting the function name can conform to the rule that users usually input function character strings.

[0012] Based on the first aspect of the present application to the first implementation method of the first aspect to the third implementation method of the first aspect, the fourth implementation method of the first aspect of the present application, the extracting the function parameter of the functional function from the function string includes: traversing the target characters between the first specific character and the second specific character in the function string, and using the target characters as the function parameters

[0013] Based on the first aspect of the present application to the first implementation method of the first aspect to the fourth implementation method, in the fifth implementation method of the first aspect of the present application, a third specific character is also included between the first specific character and the second specific character, which is located between the first specific character and the second specific character, and the adjacent character located on the left side of the third specific character is the function parameter.

[0014] The above method of extracting function parameters can conform to the rule that users usually input function character strings.

[0015] Based on the first aspect of the present application to the first implementation method of the first aspect to the fifth implementation method of the first aspect, in the sixth implementation method of the first aspect of the present application, the first specific character is a left bracket, the second specific character is a right bracket, and the third specific character is a comma.

[0016] By setting the first specific character to be a left bracket, the second specific character to be a right bracket, and the third specific character to be a comma, the rule of a function character string usually input by a user can be further met.

[0017] Based on the first aspect of the present application to the first implementation method of the first aspect to the sixth implementation method of the first aspect, the seventh implementation method of the first aspect of the present application, the creating an instance object of the function function according to the function name and the function parameters includes: using C++ programming language or Java programming language to create an instance object of the function function according to the function name and the function parameters.

[0018] Using C++ programming language or Java programming language to create instance objects of function can improve execution efficiency.

[0019] A second aspect of the present application provides an interpreter, comprising a processing circuit and a communication circuit coupled to each other, wherein the processing circuit and the communication circuit implement any of the methods of the first aspect mentioned above when in operation.

[0020] A third aspect of the present application provides a computer-readable storage medium, comprising instructions, which, when executed on a computer, enable the computer to execute any method of the first aspect.

[0021] The beneficial effect of the present application is: the present application establishes an instance object of a function by extracting the function name and function parameters in a function string, and executes the instance object. Obviously, in the embodiment of the present application, when the user needs to implement certain function functions, he only needs to input a function function that conforms to a preset format and includes a function name and a function string of function parameters. There is no need to use a high-level programming language to write it, which can ultimately simplify the programming process, improve programming efficiency, and reduce the requirements for programmers. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:

[0023] Figure 1 It is a flowchart of a method for implementing a function of the present application;

[0024] Figure 2 It is a flowchart of another implementation method of the method for realizing the functional function of the present application;

[0025] Figure 3 It is a structural schematic diagram of an implementation method of an interpreter of the present application;

[0026] Figure 4 It is a structural schematic diagram of another embodiment of the interpreter of the present application;

[0027] Figure 5 It is a structural schematic diagram of an implementation method of a computer-readable storage medium of the present application. DETAILED DESCRIPTION

[0028] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0029] See also Figure 1 , Figure 1 It is a flowchart of a method for implementing a function of the present application, and the method includes:

[0030] S110: Obtain an input function, where the function is input in the form of a function string.

[0031] When the user needs to execute a function, he can directly enter the function string on the corresponding interface.

[0032] When the user inputs a function string, he / she shall input it according to the preset rules. The input function string must include the function name and function parameters.

[0033] S120: Parse the function string, and extract the function name and function parameters of the functional function from the function string.

[0034] Decompose the function string input by the user and extract the function name and function parameters in the function string according to the preset regulations.

[0035] S130: Create an instance object of the functional function according to the function name and function parameters.

[0036] S140: Execute the instance object.

[0037] An instance object of a function is created according to the function name and function parameters. The instance object is in the form of a function expression. Executing the instance object can obtain the result of the function, and ultimately realize the function that the user wants to achieve. That is, this implementation method converts the function string input by the user into a function expression to realize the function, thereby realizing an interpreter for a function expression.

[0038] In one application scenario, the implementation method of the interpreter in this embodiment is suitable for the needs of visual system table programming and can complete visual tasks.

[0039] From the above content, it can be seen that the method in this embodiment only requires the user to input the corresponding function string, and no high-level programming language is needed to write it. This not only lowers the programming threshold, but also simplifies the programming process and improves programming efficiency for use in an industrial assembly line environment.

[0040] In this embodiment, in order to improve execution efficiency, the C++ programming language or the Java programming language is used to create an instance object of the function.

[0041] Specifically, the C++ programming language is the successor of the C programming language. It can perform both procedural programming of the C language and object-based programming characterized by abstract data function types, as well as object-oriented programming characterized by inheritance and polymorphism. While the C++ programming language is good at object-oriented programming, it can also perform procedural programming.

[0042] Java programming language is an object-oriented programming language. It not only absorbs various advantages of C++ language, but also abandons the difficult-to-understand concepts such as multiple inheritance and pointers in C++. Therefore, Java programming language has two characteristics: powerful functions and simple and easy to use. As a representative of static object-oriented programming language, Java programming language has excellently implemented object-oriented theory, allowing programmers to perform complex programming with an elegant way of thinking. Java programming language has the characteristics of simplicity, object-oriented, distributed, robust, secure, platform-independent and portable, multi-threaded, dynamic, etc.

[0043] Of course, in other implementations, other programming languages ​​may also be used to create instance objects of functions, which is not limited here.

[0044] See also Figure 2 , Figure 2 It is a flowchart of another implementation method of the implementation method of the interpreter of the present application. The method includes:

[0045] S210: Obtain an input function, where the function is input in the form of a function string.

[0046] S220: Parse the function string, and extract the function name and function parameters of the functional function from the function string.

[0047] Extracting the function name in the function string specifically includes: starting from the first character of the function string, traversing the characters in the function string in order until the current traversed character is the first specific character; intercepting the characters from the first character of the function string to the left of the first specific character as the function name.

[0048] Specifically, when the user inputs a function string, the user is required to write the function name at the beginning, and use the first specific character as a separator between the function name and other parts.

[0049] Extracting the function parameter from the function string specifically includes: traversing the target characters between the first specific character and the second specific character in the function string, and using the target characters as the function parameter.

[0050] Specifically, when the user inputs a function string, the user is required to write the function parameter between the first specific character and the second specific character. Therefore, when extracting the function parameter, the first specific character and the second specific character are directly searched, and then the found target character is used as the function parameter.

[0051] There may be more than one function parameter, so a parameter list may be created during the search process, and all the found function parameters may be added to the parameter list to obtain all the function parameters.

[0052] In an application scenario, a third specific character is further included between the first specific character and the second specific character, wherein an adjacent character between the first specific character and the second specific character and located on the left side of the third specific character is a function parameter.

[0053] That is, when the user inputs the function string, the function parameter is written between the first specific character and the second specific character and separated by the third specific character.

[0054] Usually, according to the habit of designers to write function strings, function strings generally include a left bracket and a right bracket. The function parameters are located between the left bracket and the right bracket, and two adjacent function parameters are separated by commas. The function name is from the beginning of the function string to the left side of the left bracket. Therefore, in this embodiment, in order to comply with the rules of users' usual input of function strings, the first specific character is set to a left bracket, the second specific character is set to a right bracket, and the third specific character is set to a comma.

[0055] Of course, in other implementations, the rules for user input function character strings may be re-regulated, and correspondingly, the first specific character, the second specific character, and the third specific character may be other characters, which are not limited here.

[0056] S230: Determine whether the function name exists in a preset function library.

[0057] If the judgment result is no, then go to step S270, if the judgment result is yes, then go to step S240.

[0058] Various standard function names are pre-stored in the preset function library. When the extracted function name exists in the preset function library, it means that the extracted function name is correct, and proceed to the next step. If the extracted function name does not exist in the preset function library, it means that the extracted function name is wrong. The reason may be that the function string input by the user itself is wrong, then execute step S270: perform error processing, wherein when performing error processing, the cause of the error can be displayed so that the user can correct it.

[0059] Among them, in other embodiments, in order to avoid the situation where the reason why the extracted function name does not exist in the preset function library is not that an error occurs in the function string input by the user itself, but an error occurs in the extraction process, therefore when it is determined that the function name does not exist in the preset function library, it is possible to return to step S220, that is, to re-extract the function name in the function string, and when the re-extracted function name still does not exist in the preset function library, an error processing is performed.

[0060] Meanwhile, in this embodiment, when determining whether the extracted function name exists in the preset function library, a search is performed in the preset function library using the extracted function name as a keyword.

[0061] At the same time, in this embodiment, step S230 also specifically includes: determining whether there is a standard function name in the preset function library whose similarity with the function name exceeds a similarity threshold; if the judgment result is yes, determining that the function name exists in the preset function library; if the judgment result is no, determining that the function name does not exist in the preset function library.

[0062] Among them, the similarity threshold can be set to 100%, 80%, etc. It can be understood that when the similarity threshold is set to 100%, only when the extracted function name is completely consistent with the standard function name in the function library, the extracted function name is determined to exist in the preset function library. When the similarity threshold is set to less than 100%, even if the extracted function name is not completely consistent with the standard function name in the function library, the extracted function name is also determined to exist in the function library. In this case, it can be avoided that the user enters the wrong function name when entering the function string, resulting in the failure to successfully establish an instance object. That is to say, at this time, the user is allowed to make a small range of errors when entering the function name, for example, the order of the two front and back letters of the function name is wrong, one or two letters in the function name are omitted, etc. At the same time, in this case, when the similarity between the extracted function name and the standard function name exceeds the similarity threshold, the extracted function name is updated to the standard function name.

[0063] S240: Determine, by a preset checker, whether the function type and / or the number of parameters of the function parameter conform to the function description corresponding to the function name.

[0064] If the function type and / or the number of parameters of the function parameters pass the check of the checker, the process proceeds to step S250 ; if the function type and / or the number of parameters of the function parameters do not pass the check of the checker, the process proceeds to step S270 .

[0065] When a function name exists in a function library, there must be a function description corresponding to the function name, and the function description is used to standardize the corresponding function expression, wherein the function description specifically includes the function type and / or number of parameters of the input function parameters.

[0066] Therefore, the checker is used to check whether the function type and / or parameter quantity of the function parameters conform to the corresponding function description. If so, the subsequent steps are executed. If not, error processing is performed. Similar to the above steps, when error processing is performed, the cause of the error can be displayed so that the user can correct it.

[0067] At the same time, similar to the above steps, in order to avoid the reason that the function parameter function type and / or parameter number do not conform to the function description is not due to incorrect user input, but an error occurred during the extraction process, when the checker fails the check, it can return to step S220 to extract the function parameters again. If the function parameters extracted again do not conform to the function description, error processing will be performed again.

[0068] S250: Create an instance object of the functional function according to the function name and function parameters.

[0069] S260: Execute the instance object.

[0070] Before executing the instance object, it is necessary to ensure that the created instance object is correct. Specifically, it is determined whether the function type and parameter quantity of the function parameters in the established instance object correspond to the function type and parameter quantity of the function parameters extracted previously. If they are the same, the instance object is executed to obtain the result of the function. If they are not the same, return to step S250 to create the instance object again. If the instance object created again still cannot pass the check, an error is reported.

[0071] S270: Perform error reporting processing.

[0072] It should be noted that, in other implementations, the function parameters may not be extracted first, but only when it is determined that the extracted function name exists in the function library, the function parameters are extracted.

[0073] See also Figure 3 , Figure 3 300 is a schematic diagram of the structure of an embodiment of the interpreter of the present application. The interpreter 300 includes an acquisition module 310 and a processing module 320 coupled to the acquisition module 310.

[0074] The acquisition module 310 is used to acquire an input function, where the function is input in the form of a function string.

[0075] The processing module 320 is used to parse the function string, and extract the function name and function parameters of the function from the function string; create an instance object of the function according to the function name and function parameters; and execute the instance object.

[0076] In another optional implementation, the processing module 320 is also used to determine whether the function name exists in a preset function library; if the function name exists in the function library, the processing module 320 checks through a preset checker whether the function type and / or parameter quantity of the function parameters conform to the function description corresponding to the function name; if the function type and / or parameter quantity of the function parameters conform to the function description corresponding to the function name, the processing module 320 executes the step of creating an instance object of the function function according to the function name and function parameters; if the function type and / or parameter quantity of the function parameters do not conform to the function description corresponding to the function name, the processing module 320 performs error processing.

[0077] In another optional implementation, the processing module 320 is also used to determine whether there is a standard function name in the function library whose similarity with the function name exceeds a similarity threshold; if it is determined that there is a standard function name in the function library whose similarity with the function name exceeds the similarity threshold, the processing module 320 determines that the function name exists in the function library; if it is determined that there is no standard function name in the function library whose similarity with the function name exceeds the similarity threshold, the processing module 320 determines that the function name does not exist in the function library.

[0078] In another optional implementation, the processing module 320 is also used to start from the character at the beginning of the function string, and traverse the characters in the function string in sequence until the current traversed character is the first specific character; and then the processing module 320 intercepts the characters from the beginning of the function string to the left of the first specific character as the function name.

[0079] In another optional implementation, the processing module 320 traverses the target characters between the first specific character and the second specific character in the function string, and uses the target characters as function parameters.

[0080] In another optional implementation, a third specific character is further included between the first specific character and the second specific character, and is located between the first specific character and the second specific character, and an adjacent character located on the left side of the third specific character is a function parameter.

[0081] In another optional implementation, the first specific character is a left bracket, the second specific character is a right bracket, and the third specific character is a comma.

[0082] In another optional implementation, the processing module 320 is further configured to use C++ programming language or Java programming language to create an instance object of the functional function according to the function name and function parameters.

[0083] See also Figure 4 , Figure 4 It is a structural diagram of another embodiment of the interpreter of the present application. The final interpreter 400 includes a processing circuit 410 and a communication circuit 420 coupled to each other, and the processing circuit 410 and the communication circuit 420 implement any of the above methods when working, wherein the detailed method can be referred to the above embodiment, and will not be repeated here.

[0084] See also Figure 5 , Figure 5 The computer-readable storage medium 500 includes instructions 510. When the instructions 510 are executed on a computer, the computer executes any of the above methods. The detailed methods can be found in the above embodiments and will not be described in detail here.

[0085] The computer-readable storage medium 500 may be a server, a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0086] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for implementing a functional function, characterized in that: The method comprises: Obtaining an input function, wherein the function is input in the form of a function string; Parsing the function string, and extracting the function name and function parameters of the functional function from the function string; Create an instance object of the function according to the function name and the function parameters; Execute the instance object; Before creating the instance object of the function according to the function name and the function parameters, the method further includes: Determine whether the function name exists in a preset function library; If the function name exists in the function library, checking whether the function type and / or the number of parameters of the function parameter conform to the function description corresponding to the function name by a preset checker; If the function type and / or the number of parameters of the function parameters conform to the function description corresponding to the function name, then executing the step of creating an instance object of the function function according to the function name and the function parameters; If the function type and / or the number of parameters of the function parameter do not conform to the function description corresponding to the function name, an error is reported; Wherein, determining whether the function name exists in a preset function library includes: Determine whether there is a standard function name in the function library whose similarity with the function name exceeds a similarity threshold; If it is determined that the function library contains a standard function name whose similarity with the function name exceeds a similarity threshold, then it is determined that the function name exists in the function library; If it is determined that the function library does not have a standard function name whose similarity with the function name exceeds a similarity threshold, it is determined that the function name does not exist in the function library.

2. The method according to claim 1, characterized in that: Extracting the function name of the functional function from the function string includes: Starting from the character at the beginning of the function string, traverse the characters in the function string in order until the current traversed character is the first specific character; The characters from the beginning of the function character string to the left of the first specific character are intercepted as the function name.

3. The method according to claim 2, characterized in that Extracting function parameters of the functional function from the function string includes: The target characters between the first specific character and the second specific character in the function string are traversed, and the target characters are used as the function parameters.

4. The method according to claim 3, characterized in that A third specific character is also included between the first specific character and the second specific character, wherein an adjacent character between the first specific character and the second specific character and located on the left side of the third specific character is the function parameter.

5. The method according to claim 4, characterized in that The first specific character is a left bracket, the second specific character is a right bracket, and the third specific character is a comma.

6. The method according to claim 1, characterized in that The step of creating an instance object of the function according to the function name and the function parameters includes: Using C++ programming language or Java programming language, create an instance object of the functional function according to the function name and the function parameters.

7. An interpreter, characterized in that The method comprises a processing circuit and a communication circuit coupled to each other, wherein the processing circuit and the communication circuit implement the method according to any one of claims 1 to 6 when in operation.

8. A computer-readable storage medium, characterized in that: The method comprises instructions, which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Remote function call method based on C++ and communication device

    CN106648935A