CN114895886A - Programming statement conversion method, electronic equipment and storage medium - Google Patents

Programming statement conversion method, electronic equipment and storage medium Download PDF

Info

Publication number
CN114895886A
CN114895886A CN202210582936.4A CN202210582936A CN114895886A CN 114895886 A CN114895886 A CN 114895886A CN 202210582936 A CN202210582936 A CN 202210582936A CN 114895886 A CN114895886 A CN 114895886A
Authority
CN
China
Prior art keywords
statement
jump
position information
code
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210582936.4A
Other languages
Chinese (zh)
Inventor
钟加武
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Life Insurance Company of China Ltd
Original Assignee
Ping An Life Insurance Company of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Life Insurance Company of China Ltd filed Critical Ping An Life Insurance Company of China Ltd
Priority to CN202210582936.4A priority Critical patent/CN114895886A/en
Publication of CN114895886A publication Critical patent/CN114895886A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/316Aspect-oriented programming techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis
    • G06F8/433Dependency analysis; Data or control flow analysis
    • G06F8/434Pointers; Aliasing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The present invention relates to the field of code processing technologies, and in particular, to a programming statement conversion method, an electronic device, and a storage medium. According to the method, a target syntax tree is constructed according to an original code, first position information is obtained, a target jump label corresponding to a goto jump statement is determined according to the first position information, and second position information is obtained. Further, according to the first position information and the second position information, starting point position information of the same level as the label definition statement is obtained from ancestor node positions of all levels of the goto jump statement, then the first position information is used as end point position information, codes to be converted are obtained by dividing from original codes according to the starting point position information and the end point position information, finally the goto jump statement is replaced by a target jump statement, converted result codes are obtained according to the target jump statement and the codes to be converted, conversion of the original codes is achieved, and then coding efficiency is improved.

Description

Programming statement conversion method, electronic equipment and storage medium
Technical Field
The present invention relates to the field of code processing technologies, and in particular, to a programming statement conversion method, an electronic device, and a storage medium.
Background
In the related art, the goto jump statement widely exists in the programming statement system of various programming languages, for example: procedural Structured Query Language (PL/SQL), C Language, C + +, Golang, and other programming languages. The goto jump statement is widely applied because the goto jump statement has the characteristic of free jump and can jump randomly in a grammar structure, similar to jump statements in assembly language. However, the property of free jump of the goto jump statement also brings harm to the optimization and execution of the code compiler, and in the application scenario of the goto jump statement, the prefetch instruction stream of a Central Processing Unit (CPU) is easily interrupted, thereby reducing the running efficiency of the code.
Disclosure of Invention
The present invention is directed to solving at least one of the problems of the prior art. Therefore, the invention provides a programming statement conversion method, an electronic device and a storage medium, which can convert a goto jump statement in a code so as to improve the compiling efficiency of a program.
A program statement conversion method according to an embodiment of the first aspect of the present invention, the method comprising;
constructing a target syntax tree according to an original code, wherein the target syntax tree reflects a statement structure of the original code;
acquiring first position information of the position of a goto jump statement in the target syntax tree;
determining a target jump label corresponding to the goto jump statement according to the first position information;
acquiring second position information of a position where a label definition statement in the target syntax tree is located, wherein the label definition statement is used for defining the target jump label;
acquiring starting point position information with the same level as the label definition statement from ancestor node positions of all levels of the goto jump statement according to the first position information and the second position information;
dividing the original code to obtain a code to be converted by taking the first position information as end point position information according to the starting point position information and the end point position information;
and replacing the goto jump statement with a target jump statement, and obtaining a converted result code according to the target jump statement and the code to be converted.
Optionally, according to some embodiments of the present invention, the obtaining, according to the first location information and the second location information, starting point location information of the same level as the label definition sentence from ancestor node locations of each level of the goto jump sentence includes:
acquiring the first type node position of the goto jump statement in the target syntax tree according to the first position information;
determining the positions of ancestor nodes at all levels of the goto jump statement according to the position of the first-level node;
acquiring the position of a second type node of the label definition statement in the target syntax tree according to the second position information;
and acquiring the starting point position information at the same level as the label definition statement according to the ancestor node positions of all levels and the second-class node position.
Optionally, according to some embodiments of the present invention, the obtaining, according to the position of the ancestor node of each level and the position of the node of the second level, the start position information of the same level as the label definition statement further includes:
when the original code comprises more than two goto jump statements, determining the hierarchical position arrangement of the ancestor node positions of all levels of the goto jump statements in the target syntax tree;
and acquiring the common ancestor node position of each goto jump statement in the target grammar tree based on the hierarchical position arrangement, and acquiring the starting point position information of the common ancestor node position at the same level as the label definition statement.
Optionally, according to some embodiments of the present invention, the starting point location information includes a jump starting node location, the ending point location information includes more than two jump ending node locations, the first location information is used as ending point location information, and a code to be converted is obtained by dividing from the original code according to the starting point location information and the ending point location information, including:
determining the common ancestor node location at the same level as the tag definition statement as the jump start node location;
determining each first-class node position in the first position information as the position of the jump terminal node;
and dividing the original code to obtain the code to be converted based on the position of the jump starting node and the position of the jump ending node.
Optionally, according to some embodiments of the present invention, the dividing the original code into codes to be converted according to the starting point position information and the ending point position information by using the first position information as the ending point position information further includes:
acquiring a construction conversion relation between the original code and the target syntax tree;
obtaining a conversion initial line corresponding to the starting point position information in the original code according to the starting point position information and the constructed conversion relation;
obtaining a conversion termination line corresponding to the end point position information in the original code according to the end point position information and the constructed conversion relation;
and dividing to obtain the code to be converted according to the conversion starting line and the conversion ending line.
Optionally, according to some embodiments of the present invention, the replacing the goto jump statement with a target jump statement, and obtaining a converted result code according to the target jump statement and the code to be converted includes:
the code to be converted is incorporated into an execution part of the target jump statement, the conversion starting line corresponds to the starting code of the execution part, and the conversion ending line corresponds to the jump code of the execution part;
and setting the label execution statement of the target jump label as a jump result statement corresponding to the jump code so as to jump the code to be converted to the label execution statement.
Optionally, according to some embodiments of the present invention, the setting the tag execution statement of the target jump tag as the jump result statement corresponding to the jump code, so that the code to be converted jumps to the tag execution statement, further includes:
forming a statement jump name of the target jump statement based on the label name of the target jump label;
and linking the jump code to the statement jump name so as to make the code to be converted jump to the label execution statement.
Optionally, according to some embodiments of the invention, the method further comprises:
judging whether the positional relation between the goto jump statement and the label definition statement is abnormal or not according to the first position information and the second position information;
and when the position relation between the goto jump statement and the label definition statement is abnormal, stopping the statement conversion of the original code and performing error reporting reminding.
In a second aspect, an embodiment of the present invention provides an electronic device, including: a memory storing a computer program, and a processor implementing the program statement conversion method according to any one of the embodiments of the first aspect of the present invention when the processor executes the computer program.
In a third aspect, an embodiment of the present invention provides a computer-readable storage medium, where the storage medium stores a program, and the program is executed by a processor to implement the program statement conversion method according to any one of the embodiments of the first aspect of the present invention.
According to the programming statement conversion method, the electronic device and the storage medium of the embodiment of the invention, the invention has at least the following beneficial effects:
according to the method, a target syntax tree is constructed according to an original code, first position information of the position of a goto jump statement in the target syntax tree is obtained, a target jump label corresponding to the goto jump statement is determined according to the first position information, and second position information of the position of a label definition statement in the target syntax tree is obtained. Further, according to the first position information and the second position information, starting point position information of the same level as the label definition statement is obtained from the ancestor node positions of all levels of the goto jump statement, then the first position information is used as end point position information, codes to be converted are obtained by dividing the original codes according to the starting point position information and the end point position information, finally the goto jump statement is replaced by the target jump statement, and converted result codes are obtained according to the target jump statement and the codes to be converted. According to the method, the starting point position information and the end point position information are determined through the first position information of the position where the goto jump statement is located in the target syntax tree and the second position information of the position where the label definition statement is located, then the code to be converted is obtained through division of the starting point position information and the end point position information, and finally the goto jump statement is replaced by the target jump statement, so that conversion of the original code is achieved, and the coding efficiency is improved.
Additional aspects and advantages of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the invention.
Drawings
The above and/or additional aspects and advantages of the present invention will become apparent and readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings of which:
FIG. 1 is a flowchart illustrating an implementation of a program statement conversion method according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating another implementation of the method for converting program statements according to the present invention;
FIG. 3 is a flowchart illustrating another implementation of the program statement conversion method according to the embodiment of the present invention;
FIG. 4 is a flowchart illustrating another implementation of the method for converting program statements according to the present invention;
FIG. 5 is a flowchart illustrating another implementation of the method for converting program statements according to the present invention;
FIG. 6 is a flowchart illustrating another implementation of the method for converting program statements according to the present invention;
FIG. 7 is a flowchart illustrating another implementation of the method for converting program statements according to the present invention;
FIG. 8 is a flowchart illustrating another implementation of the method for converting program statements according to the present invention;
FIG. 9 is a conversion diagram illustrating a program statement conversion method according to an embodiment of the present invention;
FIG. 10 is a diagram illustrating another example of the program statement conversion method according to the present invention;
FIG. 11 is a diagram of an electronic device for performing a method for converting a programming statement according to an embodiment of the invention.
Detailed Description
Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the accompanying drawings are illustrative only for the purpose of explaining the present invention, and are not to be construed as limiting the present invention.
In the description of the present invention, the meaning of a plurality of means is one or more, the meaning of a plurality of means is two or more, and larger, smaller, larger, etc. are understood as excluding the number, and larger, smaller, inner, etc. are understood as including the number. If the first and second are described for the purpose of distinguishing technical features, they are not to be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated or implicitly indicating the precedence of the technical features indicated.
In the description of the present invention, it should be understood that the orientation or positional relationship referred to in the description of the orientation, such as the upper, lower, left, right, front, rear, etc., is based on the orientation or positional relationship shown in the drawings, and is only for convenience of description and simplification of description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus, should not be construed as limiting the present invention.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an illustrative embodiment," "an example," "a specific example," or "some examples" or the like mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more of the embodiments or examples.
In the description of the present invention, it should be noted that unless otherwise explicitly defined, terms such as arrangement, installation, connection and the like should be broadly understood, and those skilled in the art can reasonably determine the specific meanings of the above terms in the present invention in combination with the specific contents of the technical solutions. In addition, the following labels applied to specific steps do not represent limitations on the order of steps and execution logic, and the order of execution between steps and execution logic should be understood and inferred with reference to corresponding explanatory expressions.
In the related art, the goto jump statement widely exists in the programming statement system of various programming languages, for example: procedural Structured Query Language (PL/SQL), C Language, C + +, Golang, and other programming languages. The goto jump statement is widely applied because the goto jump statement has the characteristic of free jump and can jump randomly in a grammar structure, similar to jump statements in assembly language. However, the property of free jump of the goto jump statement also brings harm to the optimization and execution of the code compiler, and in the application scenario of the goto jump statement, the prefetch instruction stream of a Central Processing Unit (CPU) is easily interrupted, thereby reducing the running efficiency of the code.
In some program compilation, the work of translating a source program into a target program can be divided into five stages: lexical analysis, syntax analysis, semantic inspection and intermediate code generation, code optimization and target code generation. The main link is to perform lexical analysis and syntactic analysis, also called source program analysis, and if syntactic errors are found in the lexical analysis and syntactic analysis processes, program compilation cannot be performed smoothly. The characteristic that the goto jump statement jumps freely also brings harm to program compiling, and as many code compilers cannot be compatible with the use grammar of the goto jump statement, the use of the goto jump statement is often judged as grammar error in the lexical analysis and grammar analysis processes, so that the program compiling cannot be carried out smoothly.
The programming statement conversion method, the electronic device and the storage medium provided by the embodiment of the invention are suitable for process-oriented programs written by adopting a command type programming language. Imperative programming languages are action-based computer languages, in the context of von neumann computer architectures. The main structure of the procedure-oriented program written by adopting the command type programming language is composed of a plurality of functions, wherein the functions comprise input parameters, return values and a calculation process, and the calculation process is realized by adopting a section of program statements. The programming language used to implement the program may be any one of the existing imperative programming languages, such as C language or C-like programming languages.
Further description is made below on the basis of the accompanying drawings.
The present invention is directed to solving at least one of the problems of the prior art. Therefore, the invention provides a programming statement conversion method, an electronic device and a storage medium, which can convert a goto jump statement in a code so as to improve the compiling efficiency of a program.
Referring to fig. 1, a program statement conversion method according to an embodiment of a first aspect of the present invention includes;
step S101, constructing a target syntax tree according to an original code, wherein the target syntax tree reflects a statement structure of the original code;
it should be understood that a Syntax Tree (Syntax Tree), alternatively referred to as Abstract Syntax Tree (AST), is a concept in the compilation principle, and functions to represent an Abstract Syntax structure in the form of a Tree, where each non-leaf node on the Tree is an operator in the Abstract Syntax and the leaf nodes represent concrete objects of the Abstract Syntax Tree. The use of syntax trees allows machines to read the inherent meaning of the abstract syntax as well as the order of execution of the abstract syntax. The syntax tree has wide application, for example, source code parsing of programming language, analysis of expressions, even natural language processing and machine translation technologies need syntax tree technology. According to some embodiments provided by the present invention, generating syntax trees typically requires two processes: lexical analysis and syntactic analysis. The task of lexical analysis is to read in a file from left to right character by character, i.e. to scan the character stream in the file and then to identify words according to the word formation rules. Parsing is a logical phase of the compilation process. The task of syntactic analysis is to combine sequences of words into various types of grammatical phrases on the basis of lexical analysis. It is common practice for professional compiler programmers to write lexical and syntactic parsers to parse the corresponding statements to generate syntax trees.
According to some embodiments provided by the present invention, the method for converting programming statements requires that a target syntax tree is first constructed from the original code. It should be noted that the original code refers to the code that has not been converted before the programming statement conversion method of the present invention, and the target syntax tree reflects the statement structure of the original code. It should be understood that the statement structure of the original code is composed of several branch parent statements and branch child statements. In some embodiments of the present invention, the branch native sentences capable of generating branch sub-sentences in the sentence structure include logical sentences such as if sentences, while sentences, for sentences, and also include tag definition sentences determined according to programming requirements. It should be understood that the branch native sentences that can generate branch sub-sentences in the sentence structure are various and are not limited to the specific embodiments set forth above. According to some embodiments provided by the present invention, in the process of constructing the target syntax tree according to the original code, the construction transformation relationship between the original code and the target syntax tree needs to be obtained from the statement structure of the original code, for example, according to the positions of logical statements such as if statement, while statement, for statement, and the like, to determine the hierarchy and branch of the target syntax tree, so as to further construct the target syntax tree based on the construction transformation relationship.
Step S102, acquiring first position information of the position of a goto jump statement in a target syntax tree;
it should be noted that the first location information refers to information reflecting the location of the goto jump statement in the target syntax tree. It should be understood that there may be only one goto jump statement in the original code, or there may be a plurality of goto jump statements, and accordingly, the first location information may include one or more branch locations of the goto jump statement in the target syntax tree.
Step S103, determining a target jump label corresponding to the goto jump statement according to the first position information;
in some embodiments of the present invention, the destination jump tag is disposed at a rear end of the goto jump statement, and the destination jump tag receives a jump target of the goto jump statement, so that the goto jump statement can be linked to a tag execution statement of the destination jump tag.
Step S104, second position information of the position of a label definition statement in the target syntax tree is obtained, and the label definition statement is used for defining a target jump label;
it should be noted that the second location information refers to information reflecting a location of the tag definition statement in the target syntax tree. It should be understood that the tag definition statement is used to define the destination jump tag, and in some embodiments, the tag definition statement includes a tag execution statement of the destination jump tag. According to some embodiments of the present invention, in the original code, the tag definition statement may be before the destination jump tag or after the destination jump tag. When the goto jump statement is executed, based on the target jump label, the goto jump statement will be linked into the label definition statement, so as to further execute the label execution statement of the target jump label. According to some embodiments provided by the present invention, the position of the goto jump statement in the target syntax tree can be specified according to the first position information, so that a target jump tag corresponding to the goto jump statement can be determined, and further, the target syntax tree is traversed according to the target jump tag, and the position of the tag definition statement is locked.
Step S105, acquiring starting point position information with the same level as the label definition sentence from ancestor node positions of all levels of the goto jump sentence according to the first position information and the second position information;
according to some embodiments provided by the invention, the positions of ancestor nodes of the goto jump statement in the target syntax tree can be clarified according to the first position information, and then the starting point position information with the same level as the label definition statement is obtained from the positions of the ancestor nodes of all levels of the goto jump statement according to the position of the label definition statement locked in the second position information. Note that the same level as the tag definition sentence means that the tag definition sentence has the same parent node. Therefore, according to some embodiments provided by the present invention, the starting point position information of the same level as the label definition statement is obtained from the ancestor node positions of each level of the goto jump statement, that is, the parent node of the label definition statement is found from the ancestor node positions of each level of the goto jump statement, and then the parent node is extended by one level in the branch direction where the goto jump statement is located, so that the determination can be made: and in the positions of the ancestral nodes at the levels of the goto jump statement, the positions at the same level as the label definition statement. Thereby further acquiring the starting point position information. It is to be understood that the starting point location information refers to location information corresponding to the starting point location of the code division range to be converted in the target syntax tree.
Step S106, taking the first position information as the end position information, and dividing the original code according to the start position information and the end position information to obtain the code to be converted;
specifically, the starting point position information refers to position information corresponding to the end point position of the code division range to be converted in the target syntax tree. The code to be converted refers to the part of the code which is directly related to the goto jump statement in the original code and needs to be expressed by the target jump statement. It should be noted that, the reason why the position information of the same level as that of the label definition sentence in the ancestor node positions of the respective levels of the goto jump sentence is used to determine the start position information, and the first position information is used as the end position information is to ensure that the programming logic is not changed even if the normal conversion of the programming syntax is satisfied in the process of converting the goto jump sentence into the target jump sentence by the programming sentence conversion method of the present invention.
And S107, replacing the goto jump statement with a target jump statement, and obtaining a converted result code according to the target jump statement and the code to be converted.
It should be noted that the destination jump statement refers to a programming statement that is different from the goto jump statement and can also function as a jump. According to some preferred embodiments provided by the invention, the target jump statement has better compatibility compared with the goto jump statement, and can be adapted to various types of code compilers, so that the optimization and the execution of the code compilers are smoothly completed. In some specific embodiments of the present invention, the selection scheme of the target jump statement includes, but is not limited to, selecting jump statements such as a while-break statement, a for-continue statement, and a try-catch statement as the target jump statement in the programming statement conversion method of the present invention. It should be emphasized that the target jump statement in the program statement conversion method of the present invention is not limited to the above-mentioned specific embodiments.
Referring to fig. 9, according to some more specific embodiments of the present invention, the target syntax tree 920 includes:
a jump terminal node 921 corresponding to the goto jump statement, wherein TARGET corresponding to the jump terminal node 921 is a TARGET jump label;
a label definition node 922 corresponding to the label definition sentence, wherein "print ('goto here. - > directly')" in the label definition node 922 is a label execution sentence of the destination jump label;
a jump start node 923 at the same level as the label definition node 922 in each level ancestor node position of the jump end node 921;
the label defines a parent 924 of node 922.
It should be understood that, in the embodiment shown in fig. 9, the nodes corresponding to the sentences stmt1, if (x ═ 2), if (y ═ 3),. ·, stmtn are at the same level as the label definition node 922. It is emphasized that embodiments to which the present invention relates include, but are not limited to, the programming statement conversion method illustrated in FIG. 9.
Based on fig. 9, further explanation is made on step S101 to step S107. According to the invention, a TARGET syntax tree 920 is constructed according to an original code 910, first position information of the position of a jump final node 921 in the TARGET syntax tree 920 is obtained, a TARGET jump label TARGET corresponding to the jump final node 921 is determined according to the first position information, and second position information of the position of a label definition node 922 in the TARGET syntax tree 920 is obtained. Further, according to the first position information and the second position information, starting point position information of the same level as that of the label definition node 922 is obtained from the positions of ancestors of all levels of the jump final node 921, then the first position information is used as end point position information, codes to be converted are obtained by dividing from the original codes 910 according to the starting point position information and the end point position information, finally the goto jump statement is replaced by the target jump statement, and converted result codes 930 are obtained according to the target jump statement and the codes to be converted. In the embodiment shown in fig. 9, the target jump statement is a while-break statement, it should be understood that those skilled in the art may make various equivalent modifications or substitutions under the sharing condition consistent with the spirit of the present invention, for example, when the target jump statement is a try-catch statement, those skilled in the art may also implement the program statement conversion method described in step S101 to step S107, and only the specific implementation details need to be adjusted accordingly according to the actual situation.
The method comprises the steps of firstly constructing a target syntax tree according to an original code, then acquiring first position information of the position where a goto jump statement is located in the target syntax tree, further determining a target jump label corresponding to the goto jump statement according to the first position information, and acquiring second position information of the position where a label definition statement is located in the target syntax tree. Further, according to the first position information and the second position information, starting point position information of the same level as the label definition statement is obtained from the ancestor node positions of all levels of the goto jump statement, then the first position information is used as end point position information, codes to be converted are obtained by dividing the original codes according to the starting point position information and the end point position information, finally the goto jump statement is replaced by the target jump statement, and converted result codes are obtained according to the target jump statement and the codes to be converted. According to the method, the starting point position information and the end point position information are determined through the first position information of the position where the goto jump statement is located in the target syntax tree and the second position information of the position where the label definition statement is located, then the code to be converted is obtained through division of the starting point position information and the end point position information, and finally the goto jump statement is replaced by the target jump statement, so that conversion of the original code is achieved, and the coding efficiency is improved.
Referring to fig. 2, according to some embodiments of the present invention, acquiring starting point location information of the same level as the tag definition sentence from ancestor node locations of respective levels of the goto jump sentence according to the first location information and the second location information includes:
step S201, acquiring a first type node position of the goto jump statement in the target syntax tree according to the first position information;
it should be noted that the first location information refers to information reflecting a location of the goto jump statement in the target syntax tree. It should be understood that there may be only one goto jump statement in the original code, or there may be a plurality of goto jump statements, and accordingly, the first location information may include one or more branch locations of the goto jump statements in the target syntax tree, that is, the first type node locations. It should be clear that the first type node location may include one or more branch locations of the goto jump statement.
Step S202, determining the positions of ancestor nodes at each level of the goto jump statement according to the positions of the nodes at the first level;
it should be noted that after the positions of the first-class nodes in the target syntax tree are clarified, positions of ancestors of the first-class nodes at different levels need to be further determined. According to some embodiments of the present invention, since the target syntax tree itself has a hierarchy and a relative position, after the position of the first type node is confirmed, the position of each level of ancestor nodes of the goto jump statement is confirmed to each level of ancestor nodes such as a father node and a grandfather node of the first type position information with reference to the first type position information.
Step S203, acquiring the position of a second type node of the label definition statement in the target syntax tree according to the second position information;
it should be noted that the second location information refers to information reflecting a location of the tag definition statement in the target syntax tree. According to some embodiments of the present invention, in the original code, the tag definition statement may be before the destination jump tag or after the destination jump tag. When the goto jump statement is executed, based on the target jump label, the goto jump statement will be linked into the label definition statement, so as to further execute the label execution statement of the target jump label. According to some embodiments provided by the present invention, the position of the goto jump statement in the target syntax tree can be specified according to the first position information, so that a destination jump tag corresponding to the goto jump statement can be determined, and further, after the destination jump tag is obtained, the target syntax tree is traversed based on the destination jump tag, so as to lock the position of the tag definition statement, that is, the position of the second-class node.
And step S204, acquiring the starting point position information at the same level as the label definition statement according to the ancestor node positions of all levels and the second-class node position.
It is to be understood that the starting point location information refers to location information corresponding to the starting point location of the code division range to be converted in the target syntax tree. According to some embodiments provided by the present invention, after the positions of the ancestors at each level of the goto jump statement and the positions of the nodes at the second level are obtained, it is further required to find a jump start node at the same level as the label definition statement from the ancestors at each level of the goto jump statement according to the positions of the ancestors at each level of the goto jump statement and the positions of the nodes at the second level, and obtain the start point position information according to the position of the jump start node in the target syntax tree. Note that the same level as the tag definition sentence means that the tag definition sentence has the same parent node. Therefore, according to some embodiments provided by the present invention, the starting point position information of the same level as the label definition statement is obtained from the ancestor node positions of each level of the goto jump statement, that is, the parent node of the label definition statement is found from the ancestor node positions of each level of the goto jump statement, and then the parent node is extended by one level in the branch direction where the goto jump statement is located, so that the determination can be made: and in the positions of the ancestral nodes at the levels of the goto jump statement, the positions at the same level as the label definition statement. Thereby further acquiring the starting point position information.
Referring to fig. 3, according to some embodiments of the present invention, obtaining the start point position information of the same level as the label definition statement according to the ancestor node positions of the levels and the node position of the second type, further includes:
step S301, when the original code comprises more than two goto jump sentences, determining the level position arrangement of the ancestor node positions of each goto jump sentence in the target syntax tree;
according to some embodiments provided by the present invention, there may be only one goto jump statement in the original code, or there may be multiple goto jump statements, and accordingly, the first location information may include one or more branch locations of the goto jump statements in the target syntax tree. When the original code comprises more than two goto jump statements, the positions of all first-class nodes of all the goto jump statements are required to be determined from the first position information, and then the hierarchical position arrangement of all levels of ancestor node positions of all the goto jump statements in the target syntax tree is determined according to the positions of all the first-class nodes. According to some embodiments of the present invention, the hierarchical position arrangement of the ancestor node positions at each level of each goto jump statement in the target syntax tree refers to a set of the ancestor node positions at each level of each goto jump statement in the original code, for example, when three goto jump statements are included in the original code, the ancestor node positions at each level of each goto jump statement in the hierarchical position arrangement in the target syntax tree include ancestor node positions such as parent node positions, grandparent node positions, and the like of the three goto jump statements. It should be understood that the hierarchical position arrangement reflects the branch positions of the ancestor nodes at the levels of each goto jump statement in the target syntax tree.
Step S302, based on the hierarchical position arrangement, obtaining the common ancestor node position of each goto jump statement in the target grammar tree, and obtaining the starting point position information of the common ancestor node position in the same level with the label definition statement.
According to some embodiments provided by the present invention, after obtaining the hierarchical position arrangement of the ancestor node positions of each goto jump statement at each level in the target syntax tree, the starting point position information needs to be further obtained based on the hierarchical position arrangement. It should be emphasized that the starting point position information refers to the position information corresponding to the starting point position of the code division range to be converted in the target syntax tree. Therefore, in order to enable all the goto jump statements in the original code to be smoothly converted into the target jump statements under the condition that the original code comprises more than two goto jump statements, in some preferred embodiments of the present invention, the common ancestor node position of each goto jump statement in the target syntax tree is obtained based on the hierarchical position arrangement, the common ancestor node position at the same level as the label definition statement is obtained from the common ancestor node position, and finally the starting point position information is obtained according to the common ancestor node position at the same level as the label definition statement. It should be understood that, by determining the common ancestor node position as the starting point position information, all goto jump statements in the original code can be smoothly converted into the target jump statements as much as possible, so that the programming statement conversion method of the present invention is smoothly executed, and the original code is converted into the result code, so as to improve the compiling efficiency of the program.
Referring to fig. 4, according to some embodiments of the present invention, the starting point location information includes a jump starting node location, the ending point location information includes more than two jump ending node locations, the first location information is used as ending point location information, and the code to be converted is obtained by dividing from the original code according to the starting point location information and the ending point location information, including:
step S401, determining the common ancestor node position at the same level as the label definition statement as the position of the jump starting node;
according to some more specific embodiments of the present invention, the start point location information includes a hop start node location. In some preferred embodiments of the present invention, in order to enable all the goto jump statements in the original code to be smoothly converted into the target jump statements, the common ancestor node position of each goto jump statement in the target syntax tree is obtained based on hierarchical position arrangement, the common ancestor node at the same level as the label definition statement is determined from the common ancestor node position, and then the common ancestor node at the same level as the label definition statement is used as the jump starting node, so as to further determine the jump starting node position according to the common ancestor node position.
Step S402, determining each first-class node position in the first position information as a jump final node position;
according to some more specific embodiments of the present invention, the end point location information includes more than two jumping end node locations. In some preferred embodiments, in order to adapt to a jump function of each goto jump statement when the original code includes more than two goto jump statements, each first-type node position in the first position information needs to be determined as a jump end node position, so that in a process of subsequently dividing and obtaining a code to be converted from the original code based on the jump start node position and the jump end node position, more than two sections of codes to be converted can be obtained, and the codes correspond to the more than two goto jump statements in the original code.
And step S403, dividing the original code to obtain the code to be converted based on the position of the jump starting node and the position of the jump ending node.
According to some specific embodiments provided by the present invention, after the location of the jump start node and the location of the jump end node are determined, the code to be converted needs to be obtained by dividing the original code based on the location of the jump start node and the location of the jump end node. It should be noted that, in the process of constructing the target syntax tree according to the original code, the construction conversion relationship between the original code and the target syntax tree needs to be obtained from the statement structure of the original code, so in some preferred embodiments, the process of obtaining the code to be converted by dividing from the original code based on the target syntax tree also needs to refer to the construction conversion relationship between the original code and the target syntax tree. According to some more specific embodiments of the present invention, referring to fig. 9, the target syntax tree 920 includes: a jump terminal node 921 corresponding to the goto jump statement, wherein TARGET corresponding to the jump terminal node 921 is a TARGET jump label; a label definition node 922 corresponding to the label definition sentence, wherein "print ('goto here. - > directly')" in the label definition node 922 is a label execution sentence of the destination jump label; among the ancestor node positions of the respective levels of the jump termination node 921, a jump start node 923 on the same level as the label definition node 922. It should be understood that the code to be converted is obtained by dividing the original code based on the position of the jump starting node 923 and the position of the jump ending node 921, and a conversion relationship between the original code and the target syntax tree needs to be referred to.
In some more specific embodiments of the present invention, the code to be converted is obtained by dividing the original code based on the location of the jump start node 923 and the location of the jump end node 921. First, the location of the corresponding statement if (x ═ 2) in the original code and the location of the goto jump statement corresponding to the statement if (x ═ 2) in the original code are confirmed in the jump start node 923; and confirming the position of the corresponding statement if (y ═ 3) in the original code and the position of the goto jump statement corresponding to the statement if (y ═ 3) in the original code in the jump starting node 923. Then, further, a first section of code to be converted is obtained according to the position of the statement if (x ═ 2) in the original code and the position of the goto jump statement corresponding to the statement if (x ═ 2) in the original code; and according to the position of the statement if (y ═ 3) in the original code and the position of the goto jump statement corresponding to the statement if (y ═ 3) in the original code, defining a second section of code to be converted. It should be understood that the first section of code to be converted and the second section of code, i.e., the code to be converted, are obtained by dividing the original code in the embodiment shown in fig. 9.
Referring to fig. 5, according to some embodiments of the present invention, dividing the original code into codes to be converted according to the start point position information and the end point position information, with the first position information as the end point position information, further includes:
step S501, obtaining a construction conversion relation between an original code and a target syntax tree;
according to some embodiments provided by the present invention, in the process of constructing the target syntax tree according to the original code, a construction transformation relationship between the original code and the target syntax tree needs to be obtained from a statement structure of the original code, for example, according to positions of logical statements such as if statement, while statement, for statement, and the like, to determine a hierarchy and branches of the target syntax tree, so as to further construct the target syntax tree based on the construction transformation relationship. It should be understood that, in some embodiments of the present invention, the code to be converted is obtained by dividing the original code according to the start point position information and the end point position information, and the conversion relationship between the original code and the target syntax tree is also required to be constructed.
Step S502, according to the starting point position information and the construction conversion relation, a conversion starting line corresponding to the starting point position information in the original code is obtained;
step S503, obtaining a conversion termination line corresponding to the end point position information in the original code according to the end point position information and the constructed conversion relation;
step S504, according to the conversion starting line and the conversion ending line, dividing to obtain the code to be converted.
According to some more specific embodiments of the present invention, referring to fig. 9, the code to be converted is obtained by dividing the original code based on the position of the jump start node 923 and the position of the jump end node 921. First, a translation start line corresponding to the jump start node 923, that is, a position of the statement if (x ═ 2) in the original code and a position of the statement if (y ═ 3) in the original code, are confirmed according to the start point position information and the constructed translation relationship. Then, a conversion termination line corresponding to the jump termination node 921, that is, a position of the goto jump sentence corresponding to the statement if (x ═ 2) in the original code and a position of the goto jump sentence corresponding to the statement if (x ═ 2) in the original code are confirmed according to the starting point position information and the constructed conversion relationship. Then, a first section of code to be converted is obtained through further demarcation according to a conversion start line of the statement if (x ═ 2) in the original code and a conversion termination line of a goto jump statement corresponding to the statement if (x ═ 2) in the original code; and according to a conversion starting line of the statement if (y ═ 3) in the original code and a conversion ending line of the goto jump statement corresponding to the statement if (y ═ 3) in the original code, a second section of code to be converted is obtained through demarcation. It should be understood that the first section of code to be converted and the second section of code, i.e., the code to be converted, are obtained by dividing the original code in the embodiment shown in fig. 9.
According to some specific embodiments provided by the invention, the first position information is used as the end point position information, the code to be converted is obtained by dividing the original code according to the start point position information and the end point position information, the hierarchy and the branch of the target syntax tree can be adjusted, and then the adjusted target syntax tree is converted into the statement structure of the code again, and finally the result code is obtained. Referring to step S10, in some embodiments of the present invention, the adjusted target syntax tree is referred to as a result syntax tree 940, which is intended to illustrate the statement structure of the result syntax tree 940 reflecting the result code. In some embodiments of the invention, the result syntax tree 940 includes:
a result end node 941, a result end node 941 is obtained by converting from the jump end node 921, where TARGET corresponding to the result end node 941 is a TARGET jump label;
a tag execution node 942 corresponding to the tag execution statement, wherein "print (' goto here. -)" in the tag execution node 942 is the tag execution statement of the destination jump tag;
the jump guide node 944, the jump guide node 944 is converted by the jump start node 923;
the jump guide node 944 corresponding to the TARGET jump statement should understand that the statement TARGET: while (1) in the jump guide node 944 and the statement break TARGET in the result end node 941, as a whole, collectively function as the TARGET jump statement.
The position of the parent node 924 of label definition node 922 in the resulting syntax tree 940 is translated into the parent node 945 of the jump boot node 944.
It should be noted that, according to the embodiment shown in step S10, the programming statement conversion method in some embodiments of the present invention first constructs the TARGET syntax tree 920 according to the original code 910, then obtains the first location information of the location of the jump termination node 921 in the TARGET syntax tree 920, further determines the TARGET jump tag TARGET corresponding to the jump termination node 921 according to the first location information, and obtains the second location information of the location of the tag definition node 922 in the TARGET syntax tree 920. Further, according to the first position information and the second position information, starting point position information of the same level as that of the label definition node 922 is obtained from the positions of ancestors of all levels of the jump final node 921, then the first position information is used as end point position information, codes to be converted are obtained by dividing from the original codes 910 according to the starting point position information and the end point position information, then the target syntax tree 920 is converted into a result syntax tree 940 based on the codes to be converted, the statement structure of the result codes 930 is clarified, finally, the goto jump statement is replaced by the target jump statement based on the result syntax tree 940 in the process of converting the structure syntax tree into the result codes. It should be understood that the target jump statement in the embodiment shown in step S10 is a while-break statement, and it should be understood that those skilled in the art may make various equivalent modifications or substitutions under the sharing condition consistent with the spirit of the present invention, for example, when the target jump statement is a try-catch statement, those skilled in the art may also make the method for converting the program statement shown in step S10, and only need to make corresponding adjustments to the specific implementation details according to the actual situation.
Referring to fig. 6, according to some embodiments of the present invention, replacing a goto jump statement with a destination jump statement, and obtaining a converted result code according to the destination jump statement and a code to be converted, includes:
step S601, incorporating the code to be converted into the execution part of the target jump statement, wherein the conversion starting line corresponds to the starting code of the execution part, and the conversion ending line corresponds to the jump code of the execution part;
it should be noted that the execution part of the target jump statement refers to the code content of the target jump statement except for the jump code. For example, when while-break is used as the destination jump statement, the code "while (1) { if (x ═ 2) { break TARGET; in the above description, the code contents except "break TARGET" are all the execution parts of while-break. It should be appreciated that in order for the code execution logic in the resulting code to be consistent with the code execution logic in the original code, in some embodiments of the present invention, the translation start line corresponds to the start code of the execution section and the translation end line corresponds to the jump code of the execution section to ensure that the code execution logic in the original code is not altered.
Step S602, setting the tag execution statement of the target jump tag as a jump result statement corresponding to the jump code, so that the code to be converted jumps to the tag execution statement.
Note that the tag execution statement corresponding to the target jump tag is defined in the tag definition statement. For example, when the tag definition statement is "TARGET: print ('go her.')", then the tag execution statement is "print ('go her.')". And the jump code of the target jump statement refers to the code content playing a jump role in the target jump statement. For example, when while-break is the destination jump statement, the code "TARGET: while (1) { if (x ═ 2) { break TARGET; in the item, the "break TARGET" is the jump code of while-break. And the jump result statement corresponding to the jump code is used as the jump result code statement. For example, when while-break is the destination jump statement, the code "TARGET: while (1) { if (x ═ 2) { break TARGET; and in the case of the 'print (' go here. ')'), the 'print (' go here. ')' is a jump result statement corresponding to the jump code. It should be noted that the setting of the tag execution statement of the target jump tag to the jump result statement corresponding to the jump code, so that the code to be converted jumps to the tag execution statement, is to make the code execution logic in the result code consistent with the code execution logic in the original code.
Referring to fig. 9, in some more specific embodiments of the present invention, specifically, in step S601, a code to be converted is incorporated into an execution section of a TARGET jump statement, a conversion start line corresponds to a start code of the execution section, and a conversion end line corresponds to a jump code of the execution section, that is, "if (x ═ 2) { goto TARGET; if (y ═ 3) { goto TARGET; "convert to" TARGET: while (1) { if (x ═ 2) { break TARGET; if (y ═ 3) { break TARGET; }}". In step S602, the tag execution statement of the TARGET jump tag is set as the jump result statement corresponding to the jump code, so that the code to be converted jumps to the tag execution statement, that is, when the jump code "branch TARGET" is executed, "TARGET: while (1)" jumps to the jump result statement "print ('go here.') corresponding to the jump code" branch TARGET ", where the tag execution statement of the TARGET jump tag" TARGET "is the" print ('go here.') ".
Referring to fig. 7, according to some embodiments of the present invention, setting a tag execution statement of a target jump tag as a jump result statement corresponding to a jump code, so that the code to be converted jumps to the tag execution statement, further includes:
step S701, forming a statement jump name of a target jump statement based on the label name of the target jump label;
step S702, the jump code is linked to the statement jump name, so that the code to be converted jumps to the label execution statement.
According to some more specific embodiments of the present invention, the tag name of the destination jump tag is the name of the destination jump tag introduced by the goto jump statement, and in some embodiments shown in fig. 9, the tag name of the destination jump tag is "TARGET". Forming a statement jump name of the TARGET jump statement based on the tag name of the TARGET jump tag, namely, setting "if (x ═ 2) { goto TARGET; if (y ═ 3) { goto TARGET; "convert to" TARGET: while (1) { if (x ═ 2) { break TARGET; if (y ═ 3) { break TARGET; }}". It should be noted that linking the jump code to the statement jump name to make the code to be converted jump to the tag execution statement refers to linking the jump code "break TARGET" to the statement jump name "TARGET: while (1)". It should be understood that through steps S701 to S702, the method for converting programming statements of the present invention can implement statement conversion, and at the same time, the code execution logic in the result code can be consistent with the code execution logic in the original code.
Referring to fig. 8, according to some embodiments of the present invention, the program statement conversion method further includes:
step S801, judging whether the positional relationship between the goto jump statement and the label definition statement is abnormal or not according to the first position information and the second position information;
step S802, when the position relation between the goto jump statement and the label definition statement is abnormal, the statement conversion of the original code is stopped and the error is reported for reminding.
It should be noted that the criterion for determining whether the positional relationship between the goto jump statement and the tag definition statement is abnormal may be flexibly set according to the actual situation, and includes: the level position of the label definition statement in the target syntax tree is too low, so that the programming statement conversion method cannot be smoothly executed; the definition of the tag definition statement is not standard; the tag definition statement and some goto jump statements are nested in the same statement structure, but the statement structure is not executed so that the tag definition statement cannot be converted. It should be understood that the criterion of whether there is a positional relationship abnormality between the breakpoint jump statement and the tag definition statement includes, but is not limited to, the specific cases mentioned above.
Fig. 11 illustrates an electronic device 1100 provided by an embodiment of the invention. The electronic device 1100 includes: a processor 1101, a memory 1102 and a computer program stored on the memory 1102 and operable on the processor 1101, the computer program when executed is for performing the above-mentioned program statement conversion method.
The processor 1101 and memory 1102 may be connected by a bus or other means.
The memory 1102, which is a non-transitory computer readable storage medium, may be used to store non-transitory software programs and non-transitory computer executable programs, such as the program statement conversion method described in the embodiments of the present invention. The processor 1101 implements the above-described program statement conversion method by executing a non-transitory software program and instructions stored in the memory 1102.
The memory 1102 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application program required for at least one function, and the like. The storage data area may store a program statement conversion method that performs the above-described program statement conversion method. Further, the memory 1102 may include a high speed random access memory 1102, and may also include a non-transitory memory 1102, such as at least one storage device memory device, flash memory device, or other non-transitory solid state memory device. In some embodiments, the memory 1102 may optionally include memory 1102 located remotely from the processor 1101, and the remote memory 1102 may be coupled to the electronic device 1100 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
Non-transitory software programs and instructions required to implement the above-described program sentence conversion method are stored in the memory 1102, and when executed by the one or more processors 1101, perform the above-described program sentence conversion method, for example, perform method steps S101 to S107 in fig. 1, method steps S201 to S204 in fig. 2, method steps S301 to S302 in fig. 3, method steps S401 to S403 in fig. 4, method steps S501 to S504 in fig. 5, method steps S601 to S602 in fig. 6, method steps S701 to S702 in fig. 7, and method steps S801 to S802 in fig. 8.
The embodiment of the invention also provides a computer-readable storage medium, which stores computer-executable instructions, and the computer-executable instructions are used for executing the programming statement conversion method.
In one embodiment, the computer-readable storage medium stores computer-executable instructions that are executed by one or more control processors, for example, to perform method steps S101-S107 in fig. 1, method steps S201-S204 in fig. 2, method steps S301-S302 in fig. 3, method steps S401-S403 in fig. 4, method steps S501-S504 in fig. 5, method steps S601-S602 in fig. 6, method steps S701-S702 in fig. 7, and method steps S801-S802 in fig. 8.
The above-described embodiments of the apparatus are merely illustrative, wherein the units illustrated as separate components may or may not be physically separate, i.e. may be located in one place, or may also be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
One of ordinary skill in the art will appreciate that all or some of the steps, systems, and methods disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as is well known to those of ordinary skill in the art. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, Digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, storage device storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media as known to those skilled in the art. It should also be appreciated that the various implementations provided by the embodiments of the present invention can be combined arbitrarily to achieve different technical effects.
While the preferred embodiments of the present invention have been described in detail, it will be understood by those skilled in the art that the foregoing and various other changes, omissions and deviations in the form and detail thereof may be made without departing from the scope of this invention.

Claims (10)

1. A method of programming statement conversion, the method comprising;
constructing a target syntax tree according to an original code, wherein the target syntax tree reflects a statement structure of the original code;
acquiring first position information of the position of a goto jump statement in the target syntax tree;
determining a target jump label corresponding to the goto jump statement according to the first position information;
acquiring second position information of a position where a label definition statement in the target syntax tree is located, wherein the label definition statement is used for defining the target jump label;
acquiring starting point position information with the same level as the label definition statement from ancestor node positions of all levels of the goto jump statement according to the first position information and the second position information;
dividing the original code to obtain a code to be converted by taking the first position information as end point position information according to the starting point position information and the end point position information;
and replacing the goto jump statement with a target jump statement, and obtaining a converted result code according to the target jump statement and the code to be converted.
2. The method according to claim 1, wherein the obtaining, according to the first location information and the second location information, starting point location information of the same level as the label definition sentence from ancestor node locations of each level of the goto jump sentence comprises:
acquiring the first type node position of the goto jump statement in the target syntax tree according to the first position information;
determining the positions of ancestor nodes at each level of the goto jump statement according to the positions of the first-level nodes;
acquiring the position of a second type node of the label definition statement in the target syntax tree according to the second position information;
and acquiring the starting point position information at the same level as the label definition statement according to the ancestor node positions of all levels and the second-class node position.
3. The method according to claim 2, wherein the obtaining of the start position information at the same level as the label definition sentence according to the position of the ancestor node at each level and the position of the node at the second level further comprises:
when the original code comprises more than two goto jump statements, determining the hierarchical position arrangement of the ancestor node positions of all levels of the goto jump statements in the target syntax tree;
and acquiring the common ancestor node position of each goto jump statement in the target grammar tree based on the hierarchical position arrangement, and acquiring the starting point position information of the common ancestor node position at the same level as the label definition statement.
4. The method according to claim 3, wherein the starting point location information includes a jump starting node location, the ending point location information includes two or more jump ending node locations, the dividing the original code into the code to be converted by using the first location information as the ending point location information according to the starting point location information and the ending point location information comprises:
determining the common ancestor node location at the same level as the tag definition statement as the jump start node location;
determining each first-class node position in the first position information as the position of the jump terminal node;
and dividing the original code to obtain the code to be converted based on the position of the jump starting node and the position of the jump ending node.
5. The method according to any one of claims 1 to 4, wherein the dividing of the original code into the code to be converted by using the first position information as the end position information and according to the start position information and the end position information further comprises:
acquiring a construction conversion relation between the original code and the target syntax tree;
obtaining a conversion initial line corresponding to the starting point position information in the original code according to the starting point position information and the constructed conversion relation;
obtaining a conversion termination line corresponding to the end point position information in the original code according to the end point position information and the constructed conversion relation;
and dividing to obtain the code to be converted according to the conversion starting line and the conversion ending line.
6. The method according to claim 5, wherein the replacing the goto jump statement with a target jump statement and obtaining a converted result code according to the target jump statement and the code to be converted comprises:
the code to be converted is incorporated into an execution part of the target jump statement, the conversion starting line corresponds to the starting code of the execution part, and the conversion ending line corresponds to the jump code of the execution part;
and setting the label execution statement of the target jump label as a jump result statement corresponding to the jump code so as to jump the code to be converted to the label execution statement.
7. The method according to claim 6, wherein the setting the tag execution statement of the target jump tag as the jump result statement corresponding to the jump code, so that the code to be converted jumps to the tag execution statement, further comprises:
forming a statement jump name of the target jump statement based on the label name of the target jump label;
and linking the jump code to the statement jump name so as to make the code to be converted jump to the label execution statement.
8. The method of claim 1, further comprising:
judging whether the positional relation between the goto jump statement and the label definition statement is abnormal or not according to the first position information and the second position information;
and when the position relation between the goto jump statement and the label definition statement is abnormal, stopping the statement conversion of the original code and carrying out error reporting reminding.
9. An electronic device, comprising: a memory storing a computer program, a processor implementing the program statement conversion method according to any one of claims 1 to 8 when the processor executes the computer program.
10. A computer-readable storage medium characterized in that the storage medium stores a program executed by a processor to implement the program sentence conversion method according to any one of claims 1 to 8.
CN202210582936.4A 2022-05-26 2022-05-26 Programming statement conversion method, electronic equipment and storage medium Pending CN114895886A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210582936.4A CN114895886A (en) 2022-05-26 2022-05-26 Programming statement conversion method, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210582936.4A CN114895886A (en) 2022-05-26 2022-05-26 Programming statement conversion method, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114895886A true CN114895886A (en) 2022-08-12

Family

ID=82725089

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210582936.4A Pending CN114895886A (en) 2022-05-26 2022-05-26 Programming statement conversion method, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114895886A (en)

Similar Documents

Publication Publication Date Title
US9710243B2 (en) Parser that uses a reflection technique to build a program semantic tree
US20070044066A1 (en) Embedded multi-language programming
CN108139891B (en) Method and system for generating suggestions to correct undefined token errors
US7665073B2 (en) Compile time meta-object protocol systems and methods
US9535664B1 (en) Computerized software development process and management environment
TWI566180B (en) A system and method thereof for creating dynamically attachable and detachable binary files
CN110688122B (en) Method and device for compiling and executing intelligent contract
CN110704063B (en) Method and device for compiling and executing intelligent contract
US8850414B2 (en) Direct access of language metadata
US20170177312A1 (en) Dynamic recompilation techniques for machine learning programs
CN101329665A (en) Method for analyzing marking language document and analyzer
WO2014106000A1 (en) Extending a development environment
US20130152061A1 (en) Full fidelity parse tree for programming language processing
US11294665B1 (en) Computerized software version control with a software database and a human database
US20040154009A1 (en) Structuring program code
Bour et al. Merlin: a language server for OCaml (experience report)
Fedorchenko et al. Equivalent transformations and regularization in context-free grammars
Xu EriLex: an embedded domain specific language generator
US20080141230A1 (en) Scope-Constrained Specification Of Features In A Programming Language
US7065753B2 (en) Method, system and computer program for syntax validation
US9715375B1 (en) Parallel compilation of software application
US20090064092A1 (en) Visual programming language optimization
US20230113783A1 (en) Cross-platform code conversion method and device
CN114895886A (en) Programming statement conversion method, electronic equipment and storage medium
US7496889B2 (en) Whitespace keywords

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination