Execution code processing method and device, equipment, medium and program product
By using syntax tree query and replacing position tags in interpreted languages, directly jumping to the corresponding execution statements, the problem of poor execution performance of GOTO statements in the prior art is solved, and more efficient jump instruction execution is achieved.
Patent Information
- Application Number
- CN202510192690.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-06-10
AI Technical Summary
In the prior art, the execution performance of GOTO statements in interpreted languages is poor because the execution statements corresponding to the position labels need to be matched one by one, resulting in a longer time.
The execution code is parsed by calling the interpreter. If the currently parsed execution statement is a jump instruction, the node of the syntax tree is query, and the execution statement corresponding to the first position label in the jump instruction is obtained, and the position label in the currently parsed execution statement is replaced. The parsed jump instruction is obtained, and the execution statement corresponding to the first position label is directly jumped to the execution statement corresponding to the first position label.
By jumping directly to the execution statement corresponding to the tag, the running time is saved and the execution performance of the jump instruction is greatly improved.
Smart Images

Figure CN120122995A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and in particular, to a method, apparatus, device, medium, and program product for processing execution code. Background Art
[0002] With the rise of structured programming, more structured control flow statements have become the mainstream; to implement more complex program logics and algorithms, jump statements are used to enable the program to jump between different code blocks, thereby achieving a more flexible control flow.
[0003] Among them, the GOTO statement is a jump instruction in a common programming language that can unconditionally jump to the position of a specified label and continue execution; for an interpreted language, the position label is obtained through an interpreter, and then it is matched one by one during the execution phase until the execution statement corresponding to the position label is found.
[0004] However, this method requires one-by-one matching, which takes a long time, resulting in poor execution performance of the jump instruction. Summary of the Invention
[0005] Embodiments of this application provide a method, apparatus, device, medium, and program product for processing execution code to achieve the effect of improving the execution performance of jump instructions.
[0006] In a first aspect, embodiments of this application provide a method for processing execution code, including: invoking an interpreter to parse the execution code; the execution code includes multiple execution statements; if the currently parsed execution statement is a jump instruction, query the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction; wherein, the nodes of the syntax tree are used to store the execution statement corresponding to the position label corresponding to the node; replace the position label in the currently parsed execution statement with the execution statement corresponding to the first position label to obtain the parsed jump instruction; execute the parsed jump instruction to jump to the execution statement corresponding to the first position label.
[0007] In a possible implementation, querying the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction specifically includes: querying the first node corresponding to the first position label from the nodes of the syntax tree; using the statement stored under the first node as the execution statement corresponding to the first position label.
[0008] In a possible implementation, if the currently parsed execution statement is not a jump instruction, parse the position label in the execution statement to obtain the execution statement corresponding to the position label; store the execution statement corresponding to the position label under the node corresponding to the position label in the syntax tree.
[0009] In a possible implementation, after querying for the first node corresponding to the first position tag from the nodes of the syntax tree, it further includes: if there is no execution statement stored under the first node of the syntax tree, then do not execute the currently parsed execution statement.
[0010] In a possible implementation, if there is no execution statement stored under the first node of the syntax tree, then generate a to-be-processed tag event and store the to-be-processed tag event under the first node.
[0011] In a possible implementation, if the currently parsed execution statement is not a jump instruction, then parse the position tag in the execution statement to obtain the statement corresponding to the position tag, specifically including: if the currently parsed execution statement is not a jump instruction, and there is a to-be-processed tag event under the node corresponding to the position tag in the syntax tree, then parse the position tag in the execution statement to obtain the execution statement corresponding to the position tag.
[0012] In a possible implementation, if the currently parsed execution statement is not a jump instruction, and there is no to-be-processed tag event under the node corresponding to the jump tag in the syntax tree, then after the currently parsed execution statement is parsed, execute the execution statement.
[0013] In a possible implementation, construct a syntax tree based on the hierarchical relationship between the execution statements of the execution code; the nodes of the syntax tree correspond to the respective execution statements; determine the node in the syntax tree corresponding to the position tag according to the execution statement bound by the position tag declared in the execution code.
[0014] In a second aspect, an embodiment of the present application provides a processing device for execution code, including: a calling module for calling an interpreter executor to parse the execution code; the execution code includes multiple execution statements; a processing module for, if the currently parsed execution statement is a jump instruction, querying the nodes of the syntax tree to obtain the execution statement corresponding to the first position tag in the jump instruction; wherein, the nodes of the syntax tree are used to store the execution statements corresponding to the position tags corresponding to the nodes; the processing module is further used to replace the position tag in the currently parsed execution statement with the execution statement corresponding to the first position tag to obtain the parsed jump instruction; and execute the parsed jump instruction to jump to the execution statement corresponding to the first position tag.
[0015] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0016] The memory stores computer execution instructions;
[0017] The processor executes the computer execution instructions stored in the memory, so that the processor executes as described in the first aspect and / or various possible implementation manners of the first aspect.
[0018] Fourthly, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored, and when the computer-executable instructions are executed by a processor, they are used to implement the first aspect and / or various possible implementation manners of the first aspect as described above.
[0019] Fifthly, an embodiment of the present application provides a computer program product, including a computer program, and when the computer program is executed by a processor, it implements the first aspect and / or various possible implementation manners of the first aspect as described above.
[0020] A method, device, equipment, medium and program product for executing code provided by an embodiment of the present application call an interpreter to parse the execution code; the execution code includes a plurality of execution statements; if the currently parsed execution statement is a jump instruction, query the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction; wherein, the nodes of the syntax tree are used to store the execution statement corresponding to the position label corresponding to the node; replace the position label in the currently parsed execution statement with the execution statement corresponding to the first position label to obtain the parsed jump instruction; execute the parsed jump instruction to jump to the execution statement corresponding to the first position label. This solution can directly jump to the execution statement corresponding to the label by replacing the position label in the currently parsed execution statement with the execution statement corresponding to the first position label, saving the running time and greatly improving the execution performance of the jump instruction. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings here are incorporated into the specification and form a part of this specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0022] Figure 1 is a flowchart showing a method for processing execution code provided by the present application Figure 1 ;
[0023] Figure 2 is an example explanatory diagram of an execution code provided by the present application;
[0024] Figure 3 is a flowchart showing a method for processing execution code provided by the present application Figure 2 ;
[0025] Figure 4 is a flowchart showing the execution of a jump instruction provided by the present application;
[0026] Figure 5 is a structural schematic diagram of a device for processing execution code provided by the present application;
[0027] Figure 6Schematic diagram of the electronic device provided by this application.
[0028] Through the above-mentioned drawings, specific embodiments of this application have been shown, and more detailed descriptions will be given later. These drawings and textual descriptions are not intended to limit the scope of the concept of this application in any way, but to illustrate the concept of this application to those skilled in the art by referring to specific embodiments. Detailed implementation manners
[0029] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with this application. On the contrary, they are only examples of devices and methods consistent with some aspects of this application as detailed in the appended claims.
[0030] With the rise of structured programming, more structured control flow statements have become the mainstream; to implement more complex program logics and algorithms, jump statements are used to enable the program to jump between different code blocks, thereby achieving a more flexible control flow.
[0031] Among them, the GOTO statement is a jump instruction in a commonly used programming language that can unconditionally jump to the position of a specified label and continue execution; for an interpreted language, the interpreter obtains the position label and then matches them one by one during the execution phase until the execution statement corresponding to the position label is found. This method requires one-by-one matching and takes a long time, resulting in poor execution performance of the jump instruction.
[0032] The technical solution provided by this application calls the interpreter to parse the execution code; the execution code includes multiple execution statements; if the currently parsed execution statement is a jump instruction, the nodes of the syntax tree are queried to obtain the execution statement corresponding to the first position label in the jump instruction; wherein, the nodes of the syntax tree are used to store the execution statement corresponding to the position label corresponding to the node; the position label in the currently parsed execution statement is replaced with the execution statement corresponding to the first position label to obtain the parsed jump instruction; the parsed jump instruction is executed to jump to the execution statement corresponding to the first position label. This solution can directly jump to the execution statement corresponding to the label by replacing the position label in the currently parsed execution statement with the execution statement corresponding to the first position label, saving the running time and greatly improving the execution performance of the jump instruction.
[0033] The following uses specific embodiments to elaborate in detail on the technical solution of the present application and how the technical solution of the present application solves the above technical problems. The following several specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below with reference to the accompanying drawings.
[0034] Embodiment 1
[0035] Figure 1 Flow diagram of a method for processing execution code provided by the present application Figure 1 as Figure 1 shown, the method includes:
[0036] S101, call an interpreter executor to parse the execution code; the execution code includes multiple execution statements.
[0037] S102, if the currently parsed execution statement is a jump instruction, query the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction; wherein, the nodes of the syntax tree are used to store the execution statements corresponding to the position labels corresponding to the nodes.
[0038] S103, replace the position label in the currently parsed execution statement with the execution statement corresponding to the first position label to obtain the parsed jump instruction; execute the parsed jump instruction to jump to the execution statement corresponding to the first position label.
[0039] Among them, the interpreter executor is a software tool or program component used to execute code written in an interpreted programming language. Its main function is to read the program code and, according to the syntax and semantic rules of the code, interpret and execute the code line by line or block by block, without the need to first compile the entire program into machine language like a compiled language. For example, the interpreter executor of Python (such as CPython) will read the Python source code, decompose it into multiple operations, and then directly execute these operations to finally obtain the running result of the program.
[0040] In practical applications, the interpreter executor includes the Python interpreter - CPython, the JavaScript engine - V8, the Ruby interpreter - MRI (Matz's Ruby Interpreter), the PHP interpreter - Zend Engine, and the Perl interpreter - Perl Interpreter; among them, CPython is the official and most widely used interpreter for the Python language; it is written in the C language, interprets Python code into bytecode, and then executes it through a bytecode interpreter. The execution process of CPython involves multiple stages such as lexical analysis, syntax analysis, building an abstract syntax tree (AST), bytecode generation, and execution. For example, when running a Python script, CPython will first perform lexical analysis on the code in the script, such as decomposing print("Hello") into lexical units like the keyword print and the argument part ("Hello"). Then, it builds a syntax tree through syntax analysis, generates a sequence of bytecode instructions, and finally executes these bytecodes to output Hello.
[0041] In addition, a jump instruction (goto statement) is a computer instruction used to change the execution order of a program, enabling the program to jump from the current position to another position and continue execution. It is an important means to implement program control flow and allows the program to switch between different code segments according to different conditions or requirements. Among them, the goto instruction is a control flow statement used to unconditionally transfer the control right of the program to a specified line or address. To achieve the purpose of random access and avoid wasting time by matching corresponding execution statements one by one according to position labels, by using the "goto" mechanism of the interpreter executor itself, these statements that do not need to be executed can be bypassed, and the corresponding execution statement position can be directly found according to the set "target" (this target is usually the position pointed to by a previously defined label, which is associated with a specific statement), and then the subsequent statements can be executed starting from there.
[0042] In practical applications, Figure 2 This is an example interpretation diagram of the execution code provided by this application, as Figure 2 shown; for example, the execution code is as shown in the following example:
[0043] declare
[0044] i int = 1;
[0045] begin
[0046] < <lb1>>
[0047] begin -- sql0
[0048] < <lb2>>
[0049] sql1
[0050] sql2 ...
[0052] < <lb3>>
[0053] Begin -- sql4
[0054] goto lb3;
[0055] end;
[0056] sql10
[0057] < <lb4>>
[0058] sql11
[0059] goto lb5;
[0060] end;
[0061] end;
[0062] Call the interpretation executor to parse the execution code. If the currently parsed execution statement is a jump instruction "goto lb1", query the nodes of the syntax tree to obtain the execution statement "sql0" corresponding to the first position label "lb1" in this jump instruction, replace the position label in the currently parsed execution statement with the execution statement corresponding to the first position label, and obtain the parsed jump instruction; execute the parsed jump instruction to jump to the execution statement corresponding to the first position label. By replacing the position label in the currently parsed execution statement with the execution statement corresponding to the first position label, it is possible to directly jump to the execution statement corresponding to the label, saving running time and greatly improving the execution performance of the jump instruction.
[0063] Call the interpretation executor to parse the execution code. The position label corresponding to the execution statement to which the jump instruction jumps is determined during the parsing stage, rather than during the execution of the jump instruction. In this way, the execution performance of the jump instruction in the interpretation executor is improved.
[0064] In some examples, querying the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in this jump instruction specifically includes:
[0065] Query the first node corresponding to the first position label from the nodes of the syntax tree;
[0066] Take the statement stored under the first node as the execution statement corresponding to the first position label.
[0067] Among them, the nodes of the syntax tree are the basic components of the syntax tree. Each node represents a syntax structure unit in the program code. These nodes are connected to each other through edges to form a hierarchical tree structure for representing the overall syntax structure of the code.
[0068] Nodes represent the execution code structure in the syntax tree. The connection relationships between nodes clearly represent the syntax structure of the execution code, converting the execution code from a one-dimensional text form into a hierarchical tree structure.
[0069] By finding the first node corresponding to the first position label in the syntax tree nodes, the marked position can be accurately found. Ensure that the jump operation can accurately locate the correct position and avoid execution errors caused by ambiguous positions.
[0070] For example, for the execution code "{lb2: a = 5; goto lb2;}", when "goto lb2" is executed, by searching for the node corresponding to lb2 in the syntax tree, it can ensure that the program accurately jumps to the position where the statement "a = 5" is located, ensuring that the program executes as expected and does not jump to other incorrect positions.
[0071] In some examples, Figure 3 is a flowchart illustration of a method for processing execution code provided by this application Figure 2 as Figure 3 shown, the method further includes:
[0072] S301, if the currently parsed execution statement is not a jump instruction, then parse the position label in the execution statement to obtain the execution statement corresponding to the position label;
[0073] S302, store the execution statement corresponding to the position label under the node corresponding to the position label in the syntax tree.
[0074] In practical applications, for example, the sample execution code in C language:
[0075] lb1:
[0076] a = 10;
[0077] lb2:
[0078] b = 20;
[0079] if (a > 5) {
[0080] / / This contains a position label but is not a jump statement
[0081] lb3: c = 30;
[0082] } else {
[0083] c = 40;
[0084] }
[0085] When parsing "if (a > 5) { lb3: c = 30;}", parse lb3 to find its corresponding execution statement "c = 30;" and store it under the node corresponding to this position label in the syntax tree. This parsing provides the necessary information for possible subsequent jump operations, ensuring correct execution when a jump instruction is executed.
[0086] In some examples, after querying the first node corresponding to the first position label from the nodes of the syntax tree, it further includes:
[0087] If no execution statement is stored under the first node of the syntax tree, the currently parsed execution statement is not executed.
[0088] When the execution statement corresponding to the first position label cannot be found in the query of the first node, it means that the interpreter has not parsed the execution statement corresponding to this position label yet; at this time, the interpreter does not know the execution statement bound to this first position label, so it does not execute the parsed execution statement. This avoids program crashes or uncontrollable behaviors caused by executing unprepared execution statements.
[0089] In some examples, if no execution statement is stored under the first node of the syntax tree, a pending label event is generated and stored under the first node.
[0090] When the execution statement corresponding to the first position label cannot be found, a pending label event is generated. This pending label event may indicate that there is some unfinished or waiting situation in the execution of the program at this node.
[0091] Storing the pending label event under the first node can facilitate the interpreter to quickly locate the special situation of this node when processing the program subsequently. The interpreter can check the pending label event of the first node and perform corresponding processing according to the stored information. For example, when the generated pending label event is "goto lb4;" and execute the execution statement corresponding to lb4; when the statement about label lb4 is parsed and the execution statement corresponding to label lb4 is obtained, the pending label event will be executed.
[0092] In some examples, if the currently parsed execution statement is not a jump instruction, the position label in this execution statement is parsed to obtain the execution statement corresponding to this position label, specifically including:
[0093] If the currently parsed execution statement is not a jump instruction and there is a pending label event under the node corresponding to the position label in this execution statement, the position label in this execution statement is parsed to obtain the execution statement corresponding to this position label.
[0094] The interpreter will parse each code statement one by one. When encountering an execution statement being parsed and it is not a jump instruction, if this statement contains a label, then this label needs to be further parsed to find the execution statement corresponding to this label.
[0095] Even if the currently executed statement itself is not a jump instruction, but there is a pending label event, that is, a jump operation based on the position label at this position (such as goto lb4; in the above example). Parse the execution statements corresponding to the position labels in advance. When a jump instruction points to this position label, it is possible to quickly and accurately know where to jump to for execution, ensuring the correct jump logic of the program and ensuring that the program execution order meets expectations.
[0096] In some examples, if the currently parsed execution statement is not a jump instruction and there is no pending label event under the node corresponding to the position label in the syntax tree for this execution statement, then after the currently parsed execution statement is parsed, execute this execution statement.
[0097] When the parsed execution code is not a jump instruction and there is no pending label event under the node corresponding to the jump label in the syntax tree, the interpreter will continue to parse the subsequent code statements in the normal parsing order. The execution code is usually written in a certain logical order, and continuing to parse the subsequent code statements can ensure that the entire program's logical flow can be completely processed.
[0098] In some examples, based on the hierarchical relationship between the execution statements of the execution code, construct a syntax tree; the nodes of the syntax tree correspond to the respective execution statements;
[0099] Determine the node in the syntax tree corresponding to the position label according to the execution statement bound by the position label declared in the execution code.
[0100] Among them, the syntax tree is a multi-way tree structure used to represent the syntax structure of the execution code. This multi-way tree structure has both a hierarchical structure and a relationship between statements before and after at the same level; the syntax tree shows in a hierarchical manner how the execution code is composed according to the syntax rules of the programming language, converting the execution code from a linear text form into a tree structure that is more convenient for computer processing.
[0101] Determine the node in the syntax tree corresponding to the position label according to the execution statement bound by the position label declared in the execution code; it can ensure that when the jump instruction is executed, the correct execution statement can be quickly found among the nodes of the syntax tree, avoiding wasting time by matching each position label one by one.
[0102] In practical applications, Figure 4 The execution flow chart of a jump instruction provided by this application is as Figure 4 As shown in the figure; among them, "goto lb2" represents a jump instruction, and sqln is an execution statement; the dotted arrow indicates the binding between label lb2 and sqln, the solid arrow indicates the execution order, and the dark dotted arrow indicates the jump operation performed by the goto instruction. It can be seen from the figure that when "goto lb2" is to be executed, since lb2 is directly bound to sqln, it can directly jump to the position of this execution statement, without having to match one by one as indicated by the light dotted arrow until the correct execution statement corresponding to the label is found.
[0103] Embodiment 2
[0104] Figure 5 The structural schematic diagram of a processing device for execution code provided by this application is as follows Figure 5 as shown, including:
[0105] A calling module 11, which is used to call an interpreter executor to parse the execution code; the execution code includes multiple execution statements;
[0106] A processing module 12, which is used to query the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction if the currently parsed execution statement is a jump instruction; among them, the nodes of the syntax tree are used to store the execution statements corresponding to the position labels corresponding to the nodes.
[0107] The processing module 12 is further used to replace the position label in the currently parsed execution statement with the execution statement corresponding to the first position label to obtain a parsed jump instruction; execute the parsed jump instruction to jump to the execution statement corresponding to the first position label.
[0108] Among them, the interpreter executor is a software tool or program component used to execute code written in an interpreted programming language. Its main function is to read the program code, and according to the syntax and semantic rules of the code, interpret and execute the code line by line or block by block, without having to compile the entire program into machine language like a compiled language. For example, the interpreter executor of Python (such as CPython) will read the Python source code, decompose it into multiple operations, and then directly execute these operations to finally obtain the running result of the program.
[0109] In practical applications, the interpreter executor includes the Python interpreter - CPython, the JavaScript engine - V8, the Ruby interpreter - MRI (Matz's Ruby Interpreter), the PHP interpreter - Zend Engine, and the Perl interpreter - Perl Interpreter. Among them, CPython is the official and most widely used interpreter for the Python language. It is written in the C language, interprets Python code into bytecode, and then executes it through a bytecode interpreter. The execution process of CPython involves multiple stages such as lexical analysis, syntax analysis, construction of an abstract syntax tree (AST), bytecode generation, and execution. For example, when running a Python script, CPython first performs lexical analysis on the code in the script. For instance, it breaks down print("Hello") into lexical units such as the keyword print and the argument part ("Hello"). Then it constructs a syntax tree through syntax analysis, generates a sequence of bytecode instructions, and finally executes these bytecodes to output Hello.
[0110] In addition, a jump instruction (goto statement) is a computer instruction used to change the execution order of a program, enabling the program to jump from the current position to another position and continue execution. It is an important means to implement program control flow and allows the program to switch between different code segments according to different conditions or requirements. Among them, the goto instruction is a control flow statement used to unconditionally transfer the control right of the program to a specified line or address. To achieve the purpose of random access and avoid wasting time by matching corresponding execution statements one by one according to position labels, by utilizing the "goto" mechanism of the interpreter executor itself, these statements that do not need to be executed can be bypassed, and the corresponding execution statement position can be directly found according to the set "target" (this target is usually the position pointed to by a previously defined label, which is associated with a specific statement), and then the subsequent statements can be executed starting from there.
[0111] In practical applications, for example, the execution code is as shown in the following example:
[0112] declare
[0113] i int = 1;
[0114] begin
[0115] < <lb1>>
[0116] begin -- sql0
[0117] < <lb2>>
[0118] sql1
[0119] sql2 ...
[0121] < <lb3>>
[0122] Begin -- sql4
[0123] goto lb3;
[0124] end;
[0125] sql10
[0126] < <lb4>>
[0127] sql11
[0128] goto lb5;
[0129] end;
[0130] end;
[0131] Call the interpreter executor to parse the execution code. If the currently parsed execution statement is a jump instruction "goto lb1", query the nodes of the syntax tree to obtain the execution statement "sql0" corresponding to the first position label "lb1" in the jump instruction, replace the position label in the currently parsed execution statement with the execution statement corresponding to the first position label, and obtain the parsed jump instruction; execute the parsed jump instruction to jump to the execution statement corresponding to the first position label. By replacing the position label in the currently parsed execution statement with the execution statement corresponding to the first position label, it is possible to directly jump to the execution statement corresponding to the label, saving running time and greatly improving the execution performance of the jump instruction.
[0132] Call the interpreter executor to parse the execution code. The execution statement corresponding to the position label to which the jump instruction jumps is determined during the parsing stage, rather than during the execution of the jump instruction. In this way, the execution performance of the jump instruction in the interpreter executor is improved.
[0133] In some examples, the processing module 12 is further configured to query the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction, specifically including:
[0134] Query the first node corresponding to the first position label from the nodes of the syntax tree;
[0135] Take the statement stored under the first node as the execution statement corresponding to the first position label.
[0136] Among them, the nodes of the syntax tree are the basic components of the syntax tree. Each node represents a syntax structure unit in the program code. These nodes are connected to each other through edges to form a hierarchical tree structure for representing the overall syntax structure of the code.
[0137] The nodes represent the execution code structure in the syntax tree, and the connection relationship between the nodes clearly represents the syntax structure of the execution code, converting the execution code from a one-dimensional text form into a hierarchical tree structure.
[0138] By searching for the first node corresponding to the first position label in the syntax tree nodes, the marked position can be accurately found. Ensure that the jump operation can accurately locate to the correct position and avoid execution errors caused by ambiguous positions.
[0139] In some examples, the processing module 12 is further configured to:
[0140] If the currently parsed execution statement is not a jump instruction, parse the position label in the execution statement to obtain the execution statement corresponding to the position label;
[0141] Store the execution statement corresponding to the position label under the node corresponding to the position label in the syntax tree.
[0142] In practical applications, for example, in the sample execution code in C language:
[0143] lb1:
[0144] a = 10;
[0145] lb2:
[0146] b = 20;
[0147] if (a > 5) {
[0148] / / This contains a position label but is not a jump statement
[0149] lb3: c = 30;
[0150] } else {
[0151] c = 40;
[0152] }
[0153] When parsing if (a > 5) { lb3: c = 30;}, parse lb3, find its corresponding execution statement "c = 30;", and store it under the node corresponding to the position label in the syntax tree. This parsing provides the necessary information for subsequent possible jump operations to ensure correct execution when executing jump instructions.
[0154] In some examples, the processing module 12 is further configured to, after querying the first node corresponding to the first position label from the nodes of the syntax tree, further include:
[0155] If no execution statement is stored under the first node of the syntax tree, do not execute the currently parsed execution statement.
[0156] When the first node corresponding to the first position label is queried and no corresponding execution statement is found, it indicates that the interpreter has not yet parsed the execution statement corresponding to the position label; at this time, the interpreter does not know the execution statement bound to the first position label, so it does not execute the parsed execution statement. This avoids program crashes or uncontrollable behaviors caused by executing unprepared execution statements.
[0157] In some examples, the processing module 12 is further configured to generate a to-be-processed label event if there is no execution statement stored under the first node of the syntax tree, and store the to-be-processed label event under the first node.
[0158] When the execution statement corresponding to the first position label cannot be found, a to-be-processed label event is generated. Such a to-be-processed label event may indicate that there is some unfinished or waiting-to-be-processed situation in the execution of the program at this node.
[0159] Storing the to-be-processed label event under the first node can facilitate the interpreter to quickly locate the special situation of this node when processing the program subsequently. The interpreter can check the to-be-processed label event of the first node and perform corresponding processing according to the stored information. For example, when the generated to-be-processed label event is "goto lb4;", execute the execution statement corresponding to lb4; when the statement regarding label lb4 is parsed and the execution statement corresponding to label lb4 is obtained, the to-be-processed label event will be executed.
[0160] In some examples, the processing module 12 is further configured to, if the currently parsed execution statement is not a jump instruction, parse the position label in the execution statement to obtain the execution statement corresponding to the position label, specifically including:
[0161] If the currently parsed execution statement is not a jump instruction and there is a to-be-processed label event under the node corresponding to the position label in the execution statement in the syntax tree, then parse the position label in the execution statement to obtain the execution statement corresponding to the position label.
[0162] The interpreter will parse each code statement one by one. When encountering an execution statement being parsed and it is not a jump instruction, if this statement contains a label, then the label needs to be further parsed to find the execution statement corresponding to the label.
[0163] Even if the current execution statement itself is not a jump instruction, but there is a to-be-processed label event, that is, a jump operation based on this position label (such as "goto lb4;" in the above example). By parsing the execution statement corresponding to the position label in advance, when a jump instruction points to this position label, it can quickly and accurately know where to jump to execute, ensure the correct jump logic of the program, and ensure that the program execution order meets the expectations.
[0164] In some examples, the processing module 12 is further configured to, if the currently parsed execution statement is not a jump instruction and there is no to-be-processed label event under the node corresponding to the position label in the execution statement in the syntax tree, then execute the execution statement after the currently parsed execution statement is parsed.
[0165] When the parsed execution code is not a jump instruction and there is no pending label event under the node corresponding to the jump label in the syntax tree, the interpreter will continue to parse the subsequent code statements in the normal parsing order. The execution code is usually written in a certain logical order, and continuing to parse the subsequent code statements can ensure that the logical flow of the entire program can be completely processed.
[0166] In some examples, the processing module 12 is further configured to construct a syntax tree based on the hierarchical relationship between the execution statements of the execution code; the nodes of the syntax tree correspond to the respective execution statements;
[0167] Determine the node in the syntax tree corresponding to the position label according to the execution statement bound by the position label declared in the execution code.
[0168] Among them, the syntax tree is a multi-way tree structure used to represent the syntax structure of the execution code. This multi-way tree structure has both a hierarchical structure and a relationship between statements at the same level; the syntax tree shows in a hierarchical manner how the execution code is composed according to the syntax rules of the programming language, converting the execution code from a linear text form into a tree structure that is more convenient for computer processing.
[0169] Determine the node in the syntax tree corresponding to the position label according to the execution statement bound by the position label declared in the execution code; it can ensure that when the jump instruction is executed, the correct execution statement can be quickly found among the nodes of the syntax tree, avoiding wasting time by matching each position label one by one.
[0170] The processing device for execution code provided in this embodiment can execute the method provided in the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here in this embodiment.
[0171] Figure 6 It is a schematic structural diagram of the electronic device provided in this application. As Figure 6 shown, the electronic device 60 provided in this embodiment includes: at least one processor 601 and a memory 602. Optionally, the device 60 further includes a communication component 603. Among them, the processor 601, the memory 602, and the communication component 603 are connected through a bus 604.
[0172] In a specific implementation process, at least one processor 601 executes the computer execution instructions stored in the memory 602, so that at least one processor 601 executes the above method.
[0173] The specific implementation process of the processor 601 can refer to the above method embodiment, and its implementation principle and technical effect are similar, which will not be elaborated here in this embodiment.
[0174] The present application also provides a computer program product, including a computer program which, when executed by a processor, implements the above-mentioned method.
[0175] The present application also provides a computer-readable storage medium storing computer-executable instructions, which when executed by a processor, implement the above-mentioned method.
[0176] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, a magnetic disk or an optical disc. The readable storage medium can be any available medium accessible by a general-purpose or special-purpose computer.
[0177] In addition, in each embodiment of the present invention, each functional unit can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit.
[0178] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of the present invention. The aforementioned storage medium includes: USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks or optical discs and other various media that can store program codes.
[0179] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including those in the above method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disks or optical discs and other various media that can store program codes.
[0180] Finally, it should be noted that: After considering the specification and practicing the invention disclosed herein, those skilled in the art will readily conceive of other embodiments of the present invention. The present invention is intended to cover any variations, uses, or adaptations of the present invention, which follow the general principles of the present invention and include the common general knowledge or conventional technical means in the technical field not disclosed in the present invention. It is not limited to the exact structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the present invention is only limited by the appended claims.
Claims
1. A method for processing an execution code, characterized in that: include: Calling an interpreter to parse the execution code; the execution code includes a plurality of execution statements; If the currently parsed execution statement is a jump instruction, query the node of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction; wherein the node of the syntax tree is used to store the execution statement corresponding to the position label corresponding to the node; The position label in the currently parsed execution statement is replaced with the execution statement corresponding to the first position label to obtain a parsed jump instruction; and the parsed jump instruction is executed to jump to the execution statement corresponding to the first position label.
2. The method according to claim 1, characterized in that The querying of the nodes of the syntax tree to obtain the execution statement corresponding to the first position label in the jump instruction specifically includes: Querying the first node corresponding to the first position tag from the nodes of the syntax tree; The statement stored under the first node is used as the execution statement corresponding to the first position tag.
3. The method according to claim 1, characterized in that The method further comprises: If the currently parsed execution statement is not a jump instruction, the position label in the execution statement is parsed to obtain the execution statement corresponding to the position label; The execution statement corresponding to the position label is stored under the node corresponding to the position label in the syntax tree.
4. The method according to claim 2, characterized in that: After searching the nodes of the syntax tree for the first node corresponding to the first position tag, the method further includes: If no execution statement is stored under the first node of the syntax tree, the currently parsed execution statement is not executed.
5. The method according to claim 4, characterized in that The method further comprises: If no execution statement is stored under the first node of the syntax tree, a label event to be processed is generated and stored under the first node.
6. The method according to claim 5, characterized in that If the currently parsed execution statement is not a jump instruction, the position label in the execution statement is parsed to obtain the execution statement corresponding to the position label, which specifically includes: If the currently parsed execution statement is not a jump instruction, and there is a pending label event under the corresponding node of the position label in the execution statement in the syntax tree, the position label in the execution statement is parsed to obtain the execution statement corresponding to the position label.
7. The method according to claim 6, characterized in that The method further comprises: If the currently parsed execution statement is not a jump instruction, and there is no pending label event under the corresponding node of the position label in the execution statement in the syntax tree, then after the currently parsed execution statement is parsed, the execution statement is executed.
8. The method according to any one of claims 1 to 7, characterized in that: The method further comprises: Based on the hierarchical relationship between the execution statements of the execution code, construct the syntax tree; the nodes of the syntax tree correspond to the execution statements; According to the execution statement bound to the position tag declared in the execution code, the node corresponding to the position tag in the syntax tree is determined.
9. A processing device for executing code, characterized in that: include: A calling module, used for calling an interpreter to parse an execution code; the execution code includes a plurality of execution statements; A processing module, configured to query a node of a syntax tree to obtain an execution statement corresponding to a first position label in the jump instruction if the currently parsed execution statement is a jump instruction; wherein the node of the syntax tree is used to store the execution statement corresponding to the position label corresponding to the node; The processing module is also used to replace the position label in the currently parsed execution statement with the execution statement corresponding to the first position label to obtain a parsed jump instruction; and execute the parsed jump instruction to jump to the execution statement corresponding to the first position label.
10. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 8 when executed by a processor.
12. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 8 when being executed by a processor.