Code evaluation method, apparatus, device, and storage medium
By acquiring basic and verification code text and performing compilation and static analysis checks, the problem of existing technologies being unable to comprehensively detect code logic errors is solved, thus improving the comprehensiveness and reliability of code evaluation.
Patent Information
- Application Number
- CN202210660634.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-13
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2042-06-13
AI Technical Summary
Existing technologies cannot fully detect logical errors when evaluating code text, which reduces the reliability of the evaluation results.
By obtaining the basic code and verification code text from the code text to be evaluated, compilation anomaly detection is performed. If no anomalies are found, the code is run and the original output result is verified using the verification code text. This is combined with static parsing to detect parsing anomalies, thereby improving the comprehensiveness of the evaluation.
It enables a comprehensive evaluation of code text, improves the reliability of evaluation results, can detect compilation and logical errors, and enhances evaluation efficiency.
Smart Images

Figure CN115080054B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and in particular, to a code evaluation method and device, equipment and storage medium. BACKGROUND
[0002] When a user finishes editing a piece of code text, the correctness of the code text usually needs to be evaluated.
[0003] In the prior art, when evaluating a code text to be evaluated, only the format compilation error or framework usage error in the code text to be evaluated can be detected. The above method makes the evaluation of the code text to be evaluated not comprehensive enough, so that the obtained evaluation result cannot accurately reflect whether there is a logical error in the code text to be evaluated, thereby reducing the reliability of the corresponding evaluation result. SUMMARY
[0004] The present application provides a code evaluation method, device, equipment and storage medium to improve the comprehensiveness of the evaluation of the code text to be evaluated and the reliability of the corresponding evaluation result.
[0005] In a first aspect, the present application provides a code evaluation method, which comprises:
[0006] obtaining a code text to be evaluated; wherein the code text to be evaluated comprises a basic code text and a verification code text for verifying the basic code text;
[0007] compiling the code text to be evaluated to determine whether there is a compilation exception in the basic code text;
[0008] if there is no compilation exception in the basic code text, running the code text to be evaluated;
[0009] verifying the original output result of the basic code text according to the verification code text.
[0010] In a second aspect, the present application provides a code evaluation device, which comprises:
[0011] a code text to be evaluated obtaining module, configured to obtain a code text to be evaluated; wherein the code text to be evaluated comprises a basic code text and a verification code text for verifying the basic code text;
[0012] a compilation exception determining module, configured to compile the code text to be evaluated to determine whether there is a compilation exception in the basic code text;
[0013] The code text to be evaluated running module is configured to run the code text to be evaluated if no compilation exception exists in the basic code text.
[0014] The original output result verification module is configured to verify the original output result of the basic code text according to the verification code text.
[0015] In a third aspect, an electronic device is provided, and the electronic device comprises:
[0016] at least one processor; and
[0017] a memory connected with the at least one processor; wherein
[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to perform the code evaluation method provided by any of the embodiments of the present application.
[0019] In a fourth aspect, a computer readable storage medium is provided, and the computer readable storage medium stores computer instructions for enabling a processor to perform the code evaluation method provided by any of the embodiments of the present application.
[0020] In the embodiments of the present application, the code text to be evaluated comprises a basic code text and a verification code text for verifying the basic code text, and accordingly, when no compilation exception exists in the basic code text, the corresponding code text to be evaluated can be run, so that when the code text to be evaluated is evaluated, the original output result of the corresponding basic code text can be verified based on the verification code included in the code text to be evaluated, to realize the judgment of whether a logic error exists in the code text to be evaluated, and thus the comprehensiveness of the evaluation of the code text to be evaluated and the reliability of the corresponding evaluation result are effectively improved.
[0021] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the present application, nor is it used to limit the scope of the present application. Other features of the present application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0023] Figure 1 is a flow chart of a code evaluation method according to an embodiment of the present application;
[0024] Figure 2 is a flow chart of a code evaluation method according to an embodiment of the present application;
[0025] Figure 3 is a flow chart of a code evaluation method according to an embodiment of the present application;
[0026] Figure 4 is a structural schematic diagram of a code evaluation device according to an embodiment of the present application;
[0027] Figure 5 is a structural block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the personnel in the art better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should belong to the scope of protection of the present application.
[0029] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily have to be used to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not have to be limited to only those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Embodiment one
[0031] Figure 1 A flow chart of a code evaluation method according to an embodiment of the present application is provided, the present embodiment can be applicable to the case of evaluating the correctness of the code text to be evaluated, the method can be executed by a code evaluation device, which can be realized in the form of software and / or hardware, and can be configured in an electronic device. Referring to Figure 1 , the method specifically includes the following steps:
[0032] S110, acquire the code text to be evaluated; wherein the code text to be evaluated comprises a basic code text and a verification code text for verifying the basic code text.
[0033] The code text to be evaluated can be a code that needs to be evaluated for correctness, for example, a code edited by a student according to course requirements. The basic code text can be a code input by an operator in the code text to be evaluated, for example, a code input by a student. The verification code text can be a fixed code preset for verifying the basic code text. The verification code text can be hidden or non-hidden, which is not limited here.
[0034] Specifically, when the code needs to be evaluated for correctness, the code can be considered as the code text to be evaluated. After the operator finishes editing the corresponding code text to be evaluated, the operator can start the code corresponding to the code text to be evaluated. Correspondingly, if it is detected that the code corresponding to the code text to be evaluated is started, the code text to be evaluated can be acquired, and the basic code text and the verification code text contained in the code text to be evaluated can be determined.
[0035] S120, compile the code text to be evaluated to determine whether there is a compilation exception in the basic code text.
[0036] The compilation exception can be an error in the compilation process.
[0037] Specifically, after the corresponding code text to be evaluated is acquired, the code text to be evaluated can be compiled. Correspondingly, if an error occurs in the process of compiling the code text to be evaluated, it can be determined that there is a compilation exception in the basic code text. If no error occurs in the process of compiling the code text to be evaluated, it means that the code text to be evaluated is compiled successfully, so it is determined that there is no compilation exception in the corresponding basic code text.
[0038] S130, if there is no compilation exception in the basic code text, run the code text to be evaluated.
[0039] Specifically, if it is determined that there is a compilation exception in the basic code text, the evaluation of the code text to be evaluated can be temporarily terminated. If it is determined that there is no compilation exception in the basic code text, it can be determined that the corresponding code text to be evaluated has a running condition. Correspondingly, the code text to be evaluated can be run to execute the specific logic contained in the code text to be evaluated.
[0040] S140, verify the original output result of the basic code text according to the verification code text.
[0041] The original output result can be a result output by running the basic code text.
[0042] Specifically, a mapping relationship library between the original output result and different basic code texts can be established in advance, and when the to-be-evaluated code text is run, the basic code text and the verification code text included in the to-be-evaluated code text are both in a running state. Accordingly, the verification code text can be run to re-execute the specific logic contained in the corresponding basic code text, and the result obtained is compared with the original output result generated by running the basic code text to determine whether the original output result is correct. Accordingly, if the result obtained by re-executing the specific logic contained in the corresponding basic code text is the same as the original output result, it is determined that the original output result is correct; if the result obtained by re-executing the specific logic contained in the corresponding basic code text is different from the original output result, it is determined that the original output result is incorrect.
[0043] The to-be-evaluated code text obtained in the embodiment of the application includes a basic code text and a verification code text that can verify the basic code text. Accordingly, when there is no compilation exception in the basic code text, the corresponding to-be-evaluated code text can be run, so that when the to-be-evaluated code text is evaluated, the original output result of the corresponding basic code text can be verified based on the verification code included in the to-be-evaluated code text itself, to realize the judgment of whether there is a logic error in the to-be-evaluated code text, thereby effectively improving the comprehensiveness of the evaluation of the to-be-evaluated code text and the reliability of the corresponding evaluation result.
[0044] Embodiment two
[0045] Figure 2 A flowchart of a code evaluation method provided by the embodiment two of the application is provided, and the embodiment is further optimized based on the above-mentioned embodiments.
[0046] Further, the step of "verifying the original output result of the basic code text according to the verification code text" is further refined as "inputting the original output result of the obtained basic code text into a target output function of the verification code text to obtain a target output result; the target output function is obtained by rewriting an output function in the basic code text; and verifying whether the original output result of the basic code text is correct according to the target output result", so as to improve the verification mechanism of the original output result.
[0047] Reference Figure 2 As shown in the figure, the method specifically includes the following steps:
[0048] S210, acquire the code text to be evaluated; wherein the code text to be evaluated comprises a basic code text and a verification code text for verifying the basic code text.
[0049] S220, compile the code text to be evaluated to determine whether there is a compilation exception in the basic code text.
[0050] S230, if there is no compilation exception in the basic code text, run the code text to be evaluated.
[0051] S240, input the original output result of the acquired basic code text into a target output function of the verification code text to obtain a target output result; wherein the target output function is obtained by rewriting an output function in the basic code text.
[0052] The target output function can be a function for verifying whether the original output result meets a preset condition, and is obtained by rewriting the output function in the basic code text. Rewriting the output function in the basic code text can be to retain the function name of the output function, and to modify the code contained in the function body of the output function according to requirements, so that the modified function body can be used to verify whether the original output result meets the preset condition. The function name can be the name of the function, and the function body can be the code that needs to be executed after the function is executed. For example, the output function in the basic code text can be a print function, and the code contained in the function body of the print function can be code for calculating any two numerical values and ensuring that the sum of the two calculated numerical values is c. When rewriting the print function, the function name print of the print function can be retained, and the code in the function body of the print function can be modified to code for verifying whether the sum of the numerical values a and b in the original output result is equal to c, so as to realize verification of the original output result. It should be noted that the output function in the basic code text can also be other function types other than the print function, which is not limited here.
[0053] The target output result can be a result representing whether the original output result is correct, for example, can be correct or incorrect, and can also be a result for comparing with the original output result to verify whether the original output result is correct.
[0054] Specifically, the output function in the basic code text can be rewritten in the verification code text in advance, and when the corresponding code text to be evaluated is in a running state, the verification code text can acquire the original output result generated by running the basic code text. Based on this, the original output result can be input into the target output function in the verification code text, and the output of the target output function can be taken as the target output result.
[0055] Illustratively, the verification code text can include pre-validation code text and post-validation code text; accordingly, the inputting the obtained original output result of the basic code text into a target output function of the verification code text to obtain a target output result includes: configuring the target output function by running the pre-validation code text; obtaining the original output result of the basic code text and calling the target output function by running the post-validation code text; taking the original output result as the input of the target output function to obtain the target output result.
[0056] The pre-validation code text can be a verification code text before the basic code text. The post-validation code text can be a verification code text after the basic code text. The pre-validation code text and the post-validation code text can be hidden or non-hidden, which is not specifically limited here.
[0057] Specifically, the output function of the basic code text can be rewritten in the pre-validation code text in advance to configure the corresponding target output function before the basic code text. Accordingly, when the corresponding to-be-evaluated code text is run, the pre-validation code text can be executed first to load the corresponding target output function. After the basic code text is executed, the post-validation code text is run to obtain the original output result generated by the running of the basic code text, and the target output function configured in the pre-validation code text is called. By taking the obtained original output result as the input of the called target output function, the corresponding target output result can be obtained to verify the corresponding original output result.
[0058] It can be understood that the corresponding target output function can be configured by running the pre-validation code text, and the original output result of the basic code text can be obtained based on the running of the post-validation code text, and the target output function is called, so that the original output result can be obtained and verified in the running process of the corresponding to-be-evaluated code text itself, without the need to additionally set an independent verification link to verify the original output result of the corresponding basic code text, thereby helping to improve the evaluation efficiency of the to-be-evaluated code text.
[0059] S250, verifying whether the original output result of the basic code text is correct according to the target output result.
[0060] Specifically, whether the corresponding original output result is correct can be characterized by the target output result. Accordingly, if the target output result is correct, it can be determined that the original output result is correct, so as to determine that there is no error in the corresponding code text to be evaluated; if the target output result is incorrect, it can be determined that the original output result is incorrect, so as to determine that there is an error in the corresponding code text to be evaluated.
[0061] Optionally, whether the original output result is correct can also be determined by comparing the target output result with the corresponding original output result. Specifically, if the target output result is the same as the original output result, it can be determined that the original output result is correct; if the target output result is different from the original output result, it can be determined that the original output result is incorrect.
[0062] The target output function obtained by rewriting the output function in the basic code text can obtain the corresponding target output result according to the original output result of the basic code text, and verify the correctness of the corresponding original output result according to the target output result, so that the acquisition and verification process of the original output result can be realized in the running process of the corresponding code text to be evaluated, without the need to additionally set up an independent verification link to verify the original output result of the basic code text, thereby helping to improve the evaluation efficiency of the code text to be evaluated.
[0063] Embodiment three
[0064] Figure 3 A flowchart of a code evaluation method provided by the third embodiment of the present application is further optimized based on the above-mentioned embodiments.
[0065] Further, the step of "performing static analysis on the code text to be evaluated to detect whether there is an analysis exception in the code text to be evaluated; if there is no analysis exception in the code text to be evaluated, selecting to compile the code text to be evaluated" is added to determine whether there is an analysis exception in the corresponding code text to be evaluated, and select the subsequent operation based thereon.
[0066] Reference Figure 3 As shown in the figure, the method specifically includes the following steps:
[0067] S310, obtaining a code text to be evaluated; wherein the code text to be evaluated includes a basic code text and a verification code text for verifying the basic code text.
[0068] S320, performing static analysis on the code text to be evaluated to detect whether there is an analysis exception in the code text to be evaluated.
[0069] The static analysis can be an analysis of content contained in the code text to be evaluated. The analysis exception can be an exception that occurs during the static analysis.
[0070] Specifically, a mapping relationship between code texts of different content and analysis exceptions can be established in advance, and a corresponding analysis exception database can be established based on the established at least one mapping relationship. The analysis exception database can be a database containing the mapping relationship between code texts of different content and analysis exceptions. When the code text to be evaluated is obtained, a static analysis operation can be performed on the code text to be evaluated first, and whether a corresponding analysis exception exists in the analysis exception database established in advance can be queried based on the code text to be evaluated after the static analysis. Correspondingly, if the corresponding analysis exception is queried, it is determined that the code text to be evaluated has an analysis exception; if the corresponding analysis exception is not queried, it is determined that the code text to be evaluated does not have an analysis exception.
[0071] Exemplarily, the code text to be evaluated includes a preset code text; the preset code text can be a fixed code of a framework of the basic code text; and the analysis exception can include a text exception of the preset code text. Correspondingly, the static analysis of the code text to be evaluated to detect whether the code text to be evaluated has an analysis exception can include: character matching of the code text to be evaluated and the preset code text; and determining, according to a matching result, whether the code text to be evaluated has a text exception.
[0072] The text exception of the preset code text can be an exception of the preset code text, for example, the preset code text can be modified. The preset code text can be presented to an operator who edits the basic code text. The character matching can be matching of characters in different code texts, which can include string strong matching.
[0073] Specifically, a corresponding fixed code can be preset to construct a framework of the basic code text, so that the operator edits the basic code text within the framework. The corresponding fixed code can be considered as a preset code text. Accordingly, the to-be-evaluated code text can be parsed, and the characters contained in the parsed to-be-evaluated code text are matched with the characters contained in the preset code text. According to the result of the matching operation, it can be determined whether there is a text anomaly in the to-be-evaluated code text. Specifically, if all the characters corresponding to the preset code text cannot be matched in the to-be-evaluated code text, it indicates that the preset code text in the to-be-evaluated code text is modified, and it can be determined that there is a text anomaly in the to-be-evaluated code text. If all the characters corresponding to the preset code text can be matched in the to-be-evaluated code text, it indicates that the preset code text in the to-be-evaluated code text is not modified, and it can be determined that there is no text anomaly in the to-be-evaluated code text.
[0074] It can be understood that, by matching the characters of the to-be-evaluated code text and the preset code text, and determining whether there is a text anomaly in the to-be-evaluated code text according to the matching result, when evaluating the to-be-evaluated code text, it can be detected whether the fixed code used to construct the framework of the basic code text is abnormal, so as to avoid the situation that the edited basic code text exceeds the set framework due to the modification of the preset code text by the operator, and further ensure that the editing of the basic code text by the operator is under the guidance of the set framework, which is of great significance for correctly guiding the operator to edit the code.
[0075] Exemplarily, after determining whether the to-be-evaluated code text has a text anomaly, if the to-be-evaluated code text has a text anomaly, a notification message of the text anomaly can be sent to prompt the operator that the preset code text cannot be modified.
[0076] Specifically, if it is determined that the to-be-evaluated code text has a text anomaly, it can be considered that the preset code text in the to-be-evaluated code text is modified. Based on this, a notification message of the corresponding text anomaly can be sent, and the operator is prompted in the notification message that the preset code text cannot be modified.
[0077] It can be understood that when it is determined that there is a text exception in the code text to be evaluated, a notification message of the text exception is sent to prompt the operator that the preset code text cannot be modified, so that the operator can be timely informed not to modify the preset code text in the process of evaluating the code text to be evaluated, thereby helping to avoid the situation that the edited basic code text exceeds the set framework due to self-modification of the preset code text in the subsequent editing process of the basic code text by the operator, and further helping to ensure that the editing of the basic code text by the operator is under the guidance of the set framework, and it is of great significance to correctly guide the operator to edit the code.
[0078] Exemplarily, the analysis exception can include a preset writing exception; and correspondingly, the static analysis on the code text to be evaluated to detect whether there is an analysis exception in the code text to be evaluated can include: matching the code text to be evaluated with a preset writing exception database established in advance according to a regular expression set in advance; and determining whether there is a preset writing exception in the code text to be evaluated according to a matching result.
[0079] The preset writing exception can be an editing error in the writing process set in advance, for example, a syntax error or a spelling error, etc. The regular expression can be a matching rule needed to be followed when matching the characters contained in the code text to be evaluated with the preset writing exception database.
[0080] Specifically, the matching rule between the code text to be evaluated and the preset writing exception database established in advance can be set in advance. According to the matching rule, each character contained in the code text to be evaluated can be matched with the code text corresponding to each preset compiling exception contained in the preset writing exception database, and whether there is a preset writing exception in the code text to be evaluated can be determined according to the corresponding matching result.
[0081] It can be understood that according to the regular expression set in advance, the code text to be evaluated is matched with the preset writing exception database established in advance, and whether there is a preset writing exception in the code text to be evaluated is determined according to the corresponding matching result, so that in the process of evaluating the code text to be evaluated, the code text to be evaluated can be detected according to the editing error that can occur in the writing process set by the operator, thereby avoiding the situation that the editing error existing in the code text to be detected is missed, and further improving the comprehensiveness of the evaluation of the code text to be evaluated.
[0082] According to the matching result, it is determined whether the preset writing exception exists in the code text to be evaluated. For example, if it is detected that the code text to be evaluated contains a statement that matches the preset exception regular expression, it is determined that the corresponding statement has the preset writing exception. In addition, if it is detected that the code text to be evaluated contains a statement that does not match the preset standard regular expression, it is determined that the corresponding statement has the preset writing exception.
[0083] The preset exception regular expression can be a preset matching rule for determining whether the characters contained in each statement in the code text to be evaluated are the same as the corresponding characters of each preset writing exception in the preset writing exception database. The preset standard regular expression can be a preset matching rule for determining whether the characters contained in each statement in the code text to be evaluated are different from the corresponding characters of each preset writing exception in the preset writing exception database.
[0084] Specifically, a matching rule for determining whether the characters contained in each statement in the code text to be evaluated are the same as the corresponding characters of each preset writing exception in the preset writing exception database can be preset, and the characters contained in each statement in the code text to be evaluated are matched with the corresponding characters of the preset writing exception database according to the matching rule. Correspondingly, if the matching is successful, it can be considered that the code text to be evaluated has the preset writing exception; if the matching fails, it can be considered that the code text to be evaluated does not have the preset writing exception. Optionally, a matching rule for determining whether the characters contained in each statement in the code text to be evaluated are different from the corresponding characters of each preset writing exception in the preset writing exception database can also be preset, and the characters contained in each statement in the code text to be evaluated are matched with the corresponding characters of the preset writing exception database according to the matching rule. Correspondingly, if the matching is successful, it can be considered that the code text to be evaluated does not have the preset writing exception; if the matching fails, it can be considered that the code text to be evaluated has the preset writing exception.
[0085] It can be understood that, by using the preset exception regular expression or the preset standard regular expression to match the characters contained in each statement in the code text to be evaluated with the preset writing exception database, the preset writing exception existing in each statement in the code text to be evaluated can be determined, thereby providing two different determination methods of the preset writing exception for selection, and thus enriching the determination mechanism of the preset writing exception and effectively improving the flexibility of the determination of the preset writing exception.
[0086] S330, if the parsing exception does not exist in the code text to be evaluated, the code text to be evaluated is compiled to determine whether a compilation exception exists in the basic code text.
[0087] Specifically, if it is determined that the to-be-evaluated code text has a parsing exception, the evaluation of the to-be-evaluated code text can be terminated; if it is determined that the to-be-evaluated code text has no parsing exception, a compiling operation can be continued on the to-be-evaluated code text. Correspondingly, the to-be-evaluated code text is compiled to determine whether the corresponding basic code text has a compiling exception according to the result of the compilation.
[0088] In an optional embodiment, if the to-be-evaluated code text has a preset code text exception and / or a preset writing exception, it can be determined that the to-be-evaluated code text has a parsing exception; if the to-be-evaluated code text has no preset code text exception or preset writing exception, it can be determined that the to-be-evaluated code text has no parsing exception.
[0089] Specifically, if the to-be-evaluated code text has at least one of the preset code text exception and the preset writing exception, it can be determined that the to-be-evaluated code text has a parsing exception; if the to-be-evaluated code text has no any one of the preset code text exception and the preset writing exception, it can be determined that the to-be-evaluated code text has no parsing exception.
[0090] It can be understood that the determination of whether the to-be-evaluated code text has a parsing exception is based on at least one type of possible parsing exception in the to-be-evaluated code text, which greatly enriches the determination mechanism of the parsing exception, so that the determination of the parsing exception is more comprehensive, and the reliability of the determination of the parsing exception is improved.
[0091] S340, if the basic code text has no compiling exception, the to-be-evaluated code text is run.
[0092] S350, the original output result of the basic code text is verified according to the verification code text.
[0093] The embodiment of the application detects whether the to-be-evaluated code text has a parsing exception by performing static parsing on the to-be-evaluated code text, and then selects to compile the to-be-evaluated code text if the to-be-evaluated code text has no parsing exception, so that whether the to-be-evaluated code text has a parsing exception is considered when the to-be-evaluated code text is evaluated, and the situation that the parsing exception is ignored when the to-be-evaluated code text is directly compiled is avoided, thereby effectively improving the comprehensiveness of the evaluation of the to-be-evaluated code text, and further improving the reliability of the obtained evaluation result.
[0094] Embodiment four
[0095] Figure 4A structural diagram of a code evaluation method provided for the fourth embodiment of the present application is shown in the figure. The embodiment can be applicable to the case of performing correctness evaluation on a code text to be evaluated. The device can be implemented in the form of software and / or hardware, and can be configured in an electronic device. Referring to Figure 4 The device includes:
[0096] A code text to be evaluated acquisition module 410 is configured to acquire a code text to be evaluated. The code text to be evaluated includes a basic code text and a verification code text for verifying the basic code text.
[0097] A compilation exception determination module 420 is configured to compile the code text to be evaluated to determine whether there is a compilation exception in the basic code text.
[0098] A code text to be evaluated running module 430 is configured to run the code text to be evaluated if there is no compilation exception in the basic code text.
[0099] An original output result verification module 440 is configured to verify an original output result of the basic code text according to the verification code text.
[0100] In the embodiment of the present application, the code text to be evaluated acquired includes a basic code text and a verification code text for verifying the basic code text. Correspondingly, when there is no compilation exception in the basic code text, the corresponding code text to be evaluated can be run. Thus, when the code text to be evaluated is evaluated, the original output result of the corresponding basic code text can be verified based on the verification code included in the code text to be evaluated, so as to determine whether there is a logical error in the code text to be evaluated, thereby effectively improving the comprehensiveness of the evaluation of the code text to be evaluated and the reliability of the corresponding evaluation result.
[0101] Optionally, the original output result verification module 440 can include:
[0102] A target output result determination unit is configured to input the original output result of the basic code text acquired to a target output function of the verification code text to obtain a target output result. The target output function is obtained by rewriting an output function in the basic code text.
[0103] An original output result verification unit is configured to verify whether the original output result of the basic code text is correct according to the target output result.
[0104] Optionally, the verification code text can include a pre-verification code text and a post-verification code text. Correspondingly, the target output result determination unit can include:
[0105] The target output function configuration sub-unit is configured to configure the target output function by running the pre-validation code text.
[0106] The target output function calling sub-unit is configured to obtain the original output result of the basic code text by running the post-validation code text, and call the target output function.
[0107] The target output result obtaining sub-unit is configured to take the original output result as the input of the target output function to obtain a target output result.
[0108] Optionally, the compilation exception determination module 420 can include:
[0109] The parsing exception detection unit is configured to perform static parsing on the code text to be evaluated to detect whether there is a parsing exception in the code text to be evaluated.
[0110] The parsing exception processing unit is configured to select to compile the code text to be evaluated if there is no parsing exception in the code text to be evaluated.
[0111] Optionally, the code text to be evaluated includes a preset code text; the preset code text is a fixed code of a framework of a basic code text; the parsing exception includes a text exception of the preset code text; accordingly, the parsing exception detection unit can include:
[0112] The character matching sub-unit is configured to perform character matching between the code text to be evaluated and the preset code text.
[0113] The text exception determination sub-unit is configured to determine whether there is a text exception in the code text to be evaluated according to the matching result.
[0114] Optionally, the parsing exception detection unit can further include:
[0115] The text exception notification sub-unit is configured to issue a notification message of the text exception to prompt an operator that the preset code text cannot be modified if there is a text exception in the code text to be evaluated.
[0116] Optionally, the parsing exception can include a preset writing exception; accordingly, the parsing exception detection module can include:
[0117] The preset writing exception matching unit is configured to match the code text to be evaluated with a preset writing exception database established in advance according to a regular expression set in advance.
[0118] The preset writing exception determination unit is configured to determine whether there is a preset writing exception in the code text to be evaluated according to the matching result.
[0119] Optionally, the preset writing exception determining unit can comprise:
[0120] The preset writing exception first determining sub-unit is configured to determine that a preset writing exception exists in a corresponding statement if it is detected that the statement in the code text to be evaluated contains a statement conforming to a preset exception regular expression.
[0121] And / or,
[0122] The preset writing exception second determining sub-unit is configured to determine that a preset writing exception exists in a corresponding statement if it is detected that the statement in the code text to be evaluated contains a statement not conforming to a preset standard regular expression.
[0123] The code evaluation device provided by the embodiments of the present application can execute the code evaluation method provided by any of the embodiments of the present application, and has the corresponding function modules and beneficial effects of executing each code evaluation method. The contents not described in detail in the embodiments of the present application can be referred to the description in any of the code evaluation method embodiments of the present application.
[0124] Embodiment five
[0125] Figure 5 A block diagram of an electronic device 10 that can be used to implement an embodiment of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices such as personal digital assistants, cellular telephones, smartphones, wearable devices (e.g., headsets, glasses, watches, etc.), and other similar computing devices. The components shown here, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the present application described and / or claimed in this document.
[0126] As shown in Figure 5 The electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is in communication with the at least one processor 11, wherein the memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0127] A plurality of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.
[0128] The processor 11 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs various methods and processes described above, such as the code evaluation method.
[0129] In some embodiments, the code evaluation method can be implemented as a computer program tangibly embodied in a computer readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded onto the RAM 13 and executed by the processor 11, one or more steps of the code evaluation method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the code evaluation method by any other appropriate means, such as by means of firmware.
[0130] The various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a programmable logic device (PLD), a computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
[0131] Computer programs for implementing the methods of the present application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer program, when executed, can cause instructions defined in the flow charts and / or block diagrams to be implemented. The computer program can be executed entirely on a machine, partially on a machine, partially on a machine as a stand-alone software package and partially on a remote machine or entirely on a remote machine or server.
[0132] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer-readable storage medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of a machine-readable storage medium will include one or more lines of a program of instructions in a transitory signal, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0133] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
[0134] The systems and techniques described herein can be implemented in a computing system that includes a back end component, e.g., as a data server, or that includes a middleware component, e.g., an application server, or that includes a front end component, e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described herein, or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication, e.g., a communication network. Examples of communication networks include a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0135] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. A server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and VPS service.
[0136] It should be understood that the various forms of flow shown above can be re-ordered, added to, or deleted from without departing from the scope of the present disclosure. For example, the steps recited in the present disclosure can be performed in parallel, in series, or in a different order, and the present disclosure is not limited in this regard.
[0137] The specific embodiments described above are not intended to limit the scope of the present disclosure. Those skilled in the art will understand that various modifications, combinations, sub-combinations, and alternatives can be made to the specific embodiments without departing from the spirit and principles of the present disclosure. Any further modifications, equivalents, and / or alternatives come within the scope of the present disclosure as recited by the claims.
Claims
1. A code evaluation method, applicable to situations where the correctness of code text to be evaluated is being assessed, characterized in that, The method comprises the following steps: acquiring a code text to be evaluated; wherein the code text to be evaluated comprises a basic code text and a verification code text for verifying the basic code text; compiling the code text to be evaluated to determine whether there is a compilation exception in the basic code text; if there is no compilation exception in the basic code text, running the code text to be evaluated; verifying the original output result of the basic code text according to the verification code text; wherein the step of verifying the original output result of the basic code text according to the verification code text comprises the following steps: inputting the original output result of the basic code text into a target output function of the verification code text to obtain a target output result; wherein the target output function is obtained by rewriting an output function in the basic code text; the target output function is used to re-execute specific logic contained in the corresponding basic code text; verifying whether the original output result of the basic code text is correct according to the target output result; wherein the step of compiling the code text to be evaluated comprises the following steps: performing static analysis on the code text to be evaluated to detect whether there is an analysis exception in the code text to be evaluated; if there is no analysis exception in the code text to be evaluated, compiling the code text to be evaluated; wherein the code text to be evaluated comprises a preset code text; the preset code text is a fixed code for constructing a framework of the basic code text; the analysis exception comprises a text exception of the preset code text; accordingly, the step of performing static analysis on the code text to be evaluated to detect whether there is an analysis exception in the code text to be evaluated comprises the following steps: matching the code text to be evaluated with the preset code text; determining whether there is a text exception in the code text to be evaluated according to the matching result; wherein the analysis exception comprises a preset writing exception; accordingly, the step of performing static analysis on the code text to be evaluated to detect whether there is an analysis exception in the code text to be evaluated comprises the following steps: matching the code text to be evaluated with a preset writing exception database established in advance according to a regular expression; wherein the regular expression refers to a matching rule required when matching characters contained in the code text to be evaluated with the preset writing exception database; the writing exception database comprises code texts corresponding to each preset compilation exception; determining whether there is a preset writing exception in the code text to be evaluated according to the matching result; wherein the preset writing exception refers to an editing error occurring in the writing process, including a syntax error and a spelling error.
2. The method of claim 1, wherein, the verification code text comprises a front verification code text and a rear verification code text; accordingly, the step of inputting the original output result of the basic code text into the target output function of the verification code text to obtain a target output result comprises the following steps: configuring the target output function by running the front verification code text; obtaining an original output result of the basic code text by running the post-validation code text, and calling the target output function; inputting the original output result as an input of the target output function to obtain a target output result.
3. The method of claim 1, wherein, The determining whether the preset writing exception exists in the code text to be evaluated according to the matching result comprises: if it is detected that the code text to be evaluated contains a statement conforming to the preset exception regular expression, it is determined that the preset writing exception exists in the corresponding statement; and / or, if it is detected that the code text to be evaluated contains a statement not conforming to the preset standard regular expression, it is determined that the preset writing exception exists in the corresponding statement.
4. A code evaluation device, suitable for evaluating the correctness of code text to be evaluated, characterized in that, The method comprises: a code text to be evaluated obtaining module configured to obtain a code text to be evaluated; wherein the code text to be evaluated comprises a basic code text and a validation code text for validating the basic code text; a compilation exception determining module configured to compile the code text to be evaluated to determine whether a compilation exception exists in the basic code text; a code text to be evaluated running module configured to run the code text to be evaluated if the compilation exception does not exist in the basic code text; an original output result validating module configured to validate an original output result of the basic code text according to the validation code text; The original output result validating module comprises: a target output result determining unit configured to input the obtained original output result of the basic code text into a target output function of the validation code text to obtain a target output result; wherein the target output function is obtained by rewriting an output function in the basic code text; and the target output function is configured to re-execute specific logic contained in the corresponding basic code text; an original output result validating unit configured to validate whether the original output result of the basic code text is correct according to the target output result; The compilation exception determining module comprises: a parsing exception detecting unit configured to perform static parsing on the code text to be evaluated to detect whether a parsing exception exists in the code text to be evaluated; a parsing exception processing unit configured to compile the code text to be evaluated if the parsing exception does not exist in the code text to be evaluated; The code text to be evaluated comprises a preset code text; the preset code text is a fixed code for constructing a framework of the basic code text; the parsing exception comprises a text exception of the preset code text; correspondingly, the parsing exception detecting unit comprises: a character matching subunit configured to perform character matching on the code text to be evaluated and the preset code text; a text exception determining subunit configured to determine whether a text exception exists in the code text to be evaluated according to a matching result; The parsing exception comprises a preset writing exception; correspondingly, the parsing exception detecting unit comprises: The preset coding exception matching subunit is configured to match the code text to be evaluated with a preset coding exception database established in advance according to a preset regular expression; the regular expression refers to a matching rule needed when matching characters contained in the code text to be evaluated with the preset coding exception database; and the coding exception database includes code texts corresponding to preset coding exceptions. The preset coding exception determining subunit is configured to determine whether the preset coding exception exists in the code text to be evaluated according to the matching result; the preset coding exception refers to an editing error occurring in a preset coding process, including a syntax error and a spelling error.
5. An electronic device, comprising: The electronic device comprises: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the code evaluation method of any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for enabling the processor to execute the code evaluation method of any one of claims 1-3 when executed.
Citation Information
Patent Citations
Programming code evaluation method and device
CN113392003A