CN111367527B - Language processing method, device, medium and electronic equipment - Google Patents

Language processing method, device, medium and electronic equipment Download PDF

Info

Publication number
CN111367527B
CN111367527B CN202010099810.2A CN202010099810A CN111367527B CN 111367527 B CN111367527 B CN 111367527B CN 202010099810 A CN202010099810 A CN 202010099810A CN 111367527 B CN111367527 B CN 111367527B
Authority
CN
China
Prior art keywords
matching
node
template
information
code
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.)
Active
Application number
CN202010099810.2A
Other languages
Chinese (zh)
Other versions
CN111367527A (en
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.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology Co 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 Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202010099810.2A priority Critical patent/CN111367527B/en
Publication of CN111367527A publication Critical patent/CN111367527A/en
Application granted granted Critical
Publication of CN111367527B publication Critical patent/CN111367527B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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/44Encoding
    • 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)
  • Stored Programmes (AREA)
  • Machine Translation (AREA)

Abstract

The present disclosure provides a method, an apparatus, a medium, and an electronic device for language processing. The method comprises the following steps: acquiring a plurality of setting node information associated with a template syntax tree; traversing nodes in the template syntax tree by adopting each set node information respectively to obtain matched node information; respectively acquiring corresponding matching node code identifiers by utilizing each piece of matching node information, and storing the matching node code identifiers in the corresponding matching node information; and after all the nodes in the template grammar tree acquire the corresponding matched node code identifications, restoring the matched node codes corresponding to the matched node code identifications of each node by using the template grammar tree to generate template program codes. The present disclosure utilizes features of a template syntax tree to constrain relationships of template codes. Meanwhile, the flexibility and the universality of matching are improved by setting the node information. The efficiency of template program code generation is improved. Template codes do not need to be written, and the error rate is reduced.

Description

Language processing method, device, medium and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, a medium, and an electronic device for language processing.
Background
Writing program code, programming for short, is the process of writing program code in a programming language and finally obtaining a result in order to achieve a certain purpose or solve a certain problem by means of a computer.
A program, that is, a collection of instructions, tells a computer how to perform a particular task. After programming, the program is interpreted or translated by special software into a computer language recognizable by the computer, and the computer performs corresponding actions according to the computer language.
Code that is structurally the same or similar often occurs in the same or different programs at the time of programming. Typically to save time, programmers manually copy such code to the corresponding location, and then machine and write it according to specific needs. The method often omits codes or modifies errors due to thinking inertia, and easily damages the simplicity and cleanliness of the codes, thereby causing code redundancy and affecting the execution efficiency of the program. And manpower is wasted to complete such repetitive work.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
An object of the present disclosure is to provide a method, an apparatus, a medium, and an electronic device for language processing, which can solve at least one of the above-mentioned technical problems. The specific scheme is as follows:
according to a specific embodiment of the present disclosure, in a first aspect, the present disclosure provides a method of language processing, including:
acquiring a plurality of setting node information associated with a template syntax tree;
traversing nodes in the template syntax tree by adopting each set node information respectively to obtain matched node information;
respectively acquiring corresponding matching node code identifications by using each piece of matching node information, and storing the matching node code identifications into the corresponding matching node information;
and after all the nodes in the template grammar tree acquire the corresponding matched node code identifications, restoring the matched node codes corresponding to the matched node code identifications of each node by using the template grammar tree to generate template program codes.
According to a second aspect, the present disclosure provides an apparatus for language processing, including:
an acquisition setting node information unit for acquiring a plurality of setting node information associated with the template syntax tree;
the matching node unit is used for respectively traversing the nodes in the template syntax tree by adopting each set node information to acquire matching node information;
the storage identification unit is used for respectively acquiring corresponding matching node code identifications by utilizing each piece of matching node information and storing the matching node code identifications into the corresponding matching node information;
and the code generation unit is used for restoring the matched node codes corresponding to the matched node code identifier of each node by using the template grammar tree to generate template program codes after all the nodes in the template grammar tree acquire the corresponding matched node code identifiers.
According to a third aspect, the present disclosure provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method of language processing according to any one of the first aspects.
According to a fourth aspect thereof, the present disclosure provides an electronic device, comprising: one or more processors; storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to implement a method of language processing as claimed in any one of the first aspects.
Compared with the prior art, the scheme of the embodiment of the disclosure at least has the following beneficial effects:
the present disclosure provides a method, an apparatus, a medium, and an electronic device for language processing. The method comprises the following steps: acquiring a plurality of setting node information associated with a template syntax tree; traversing nodes in the template syntax tree by adopting each set node information respectively to obtain matched node information; respectively acquiring corresponding matching node code identifications by using each piece of matching node information, and storing the matching node code identifications into the corresponding matching node information; and when all the nodes in the template grammar tree acquire the corresponding matched node code identifications, restoring the matched node codes corresponding to the matched node code identifications of each node by using the template grammar tree to generate template program codes.
The method utilizes the template syntax tree as the middleware of the standardized template, abstracts the program codes into a tree, and utilizes the characteristics of the tree structure to constrain the relationship of the template codes. Meanwhile, the node information is set to comprise the matching rule and the non-matching rule, so that the flexibility and the universality of matching are improved. The efficiency of template program code generation is improved. The method and the device do not need to write template codes, and reduce error rate.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and components are not necessarily drawn to scale. In the drawings:
FIG. 1 shows a flow diagram of a method of language processing according to an embodiment of the present disclosure;
FIG. 2 illustrates a block diagram of elements of an apparatus for language processing according to an embodiment of the present disclosure;
fig. 3 shows an electronic device connection structure schematic according to an embodiment of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more complete and thorough understanding of the present disclosure. It should be understood that the drawings and embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
The names of messages or information exchanged between devices in the embodiments of the present disclosure are for illustrative purposes only, and are not intended to limit the scope of the messages or information.
Alternative embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
A first embodiment, namely an embodiment of a method of language processing, is provided for the present disclosure.
The following describes an embodiment of the present disclosure in detail with reference to fig. 1, where fig. 1 is a flowchart of a method of language processing provided by the embodiment of the present disclosure.
In step S101, a plurality of setting node information associated with the template syntax tree is acquired.
It is an object of embodiments of the present disclosure to automatically generate structurally identical or similar program code through a standardized configuration.
Optionally, the template syntax tree comprises an abstract syntax tree.
In computer science, an abstract syntax tree (AST, for short) or a syntax tree (syntax tree, for short) is a tree representation of an abstract syntax structure of a source code, and particularly refers to a source code of a programming language. Each node on the tree represents a structure in the source code. The syntax is said to be "abstract" in that the syntax does not represent every detail that appears in the true syntax. For example, nesting brackets are implicit in the structure of the tree and are not present in the form of nodes; whereas a conditional jump statement like the if-condition-then may be represented using a node with two branches. The abstract syntax tree is an intermediate representation form of a program, and is widely applied to various fields such as program analysis. The embodiment of the disclosure abstracts the program code into a tree by using the template syntax tree as the middleware of the standardized template, and restricts the relationship of the template code by using the characteristics of the tree structure, thereby improving the generation efficiency of the template code.
The set node information is information associated with the template syntax tree input by the program developer. For example, a program developer needs to generate a section of template program code a, and a template syntax tree B corresponding to the template program code a, so as to open a configuration interface of the template syntax tree B, and the configuration interface includes prompt information of setting node information of the template syntax tree B, and the program developer inputs the setting node information one by one according to the prompt information. After the input is completed and submitted, the setting node information is obtained.
Optionally, the number of the set node information is consistent with the number of the nodes in the template syntax tree, and the set node information corresponds to the nodes in the template syntax tree one to one. This ensures that the complete template program code is obtained.
Of course, when the node information is set to correspond to a node of a sub-tree in the template syntax tree, the sub-template program code of the sub-tree can also be generated based on the embodiment of the present disclosure.
The setting node information implies a matching rule with a node in the template syntax tree.
The setting node information includes a first matching node name and a matching rule and/or a non-matching rule.
The matching rule includes: first matching depth information traversed upwards and second matching node names in the first matching depth range; in addition, the method further comprises first matching success interruption information of a third matching node name and/or first matching failure interruption information of a fourth matching node name within the first matching depth range.
The non-matching rule includes: the second matching depth information traversed upwards and a non-matching fifth matching node name in the second matching depth range; and in addition, second matching success interruption information of a sixth matching node name and/or second matching failure interruption information of a seventh matching node name in a second matching depth range is/are included.
Optionally, the matching sequence of the nodes in the set node information is consistent with the description sequence.
For example: and saving the set node information by adopting a data structure:
Figure BDA0002386495200000051
the data structure of the set node information includes a non-matching rule and a matching rule, and the matching sequence of the set node information is as follows: firstly, matching name1, then matching according to a non-matching rule, and finally matching according to a matching rule;
the matching order in the non-matching rule is: in the depth range of number2, under the condition that name5 does not exist, if node _ name6 is matched, the matching is successful and the successful interrupt information is adopted for quitting, and if node _ name7 is matched, the matching is failed and the failed interrupt information is adopted for quitting;
the matching order in the matching rule is: in the depth range of number1, under the condition of existence of name2, if the node _ name3 is matched, the matching is successful and the successful interrupt information is adopted for quitting, and if the node _ name4 is matched, the matching is failed and the failed interrupt information is adopted for quitting;
for example, match _ node: the node of the await is connected with the node,
Figure BDA0002386495200000061
the rule indicates that after the await node is matched, in the range of the upward traversal depth of the node being 2, if the function node is matched under the condition that the try node does not exist, the matching rule is ended with successful matching.
In the setting node information, there are various permutation and combination forms between the matching rules and the non-matching rules. For example: a [ matching rule ] or [ non-matching rule ] exists separately; or a combination of [ matching rules, non-matching rules ]; or a combination of [ non-matching rules, matching rules ].
Similarly, there are also various permutation and combination forms of successful interruption information and failed interruption information in the matching rule and the non-matching rule. For example: either [ exit _0] or [ exit _1] alone; or a combination of [ exit _0, exit _1]; or a combination of [ exit _1, exit _0 ].
The different ordering determines the logical order of the matching.
The set node information comprises the matching rules and the non-matching rules, so that the flexibility and the universality of matching are improved. The efficiency of template program code generation is improved.
And step S102, traversing the nodes in the template syntax tree by adopting each set node information to acquire the matched node information.
The purpose of this step is to find the corresponding node information, i.e., the matching node information, in the template syntax tree for each set node information.
The node information in the template syntax tree includes at least a node name. For example, continuing the above example, the node information in the template syntax tree includes: an await node and a function node.
The matching node information is information of one node in the template syntax tree.
Optionally, traversing nodes in the template syntax tree by using the set node information to obtain matching node information includes the following steps:
and step S102-1, traversing the nodes in the template syntax tree by adopting a depth-first traversal algorithm, matching the nodes by adopting the set node information, and acquiring matched node information.
The depth-first traversal algorithm is similar to the tree's predecessor traversal. The method is characterized in that the depth direction is searched firstly.
The present embodiment does not describe in detail the process of traversing the nodes in the template syntax tree by using the depth-first traversal algorithm, and can be implemented by referring to various implementation manners in the prior art.
Step S103, obtaining corresponding matching node code identifications by using each piece of matching node information, and storing the matching node code identifications into the corresponding matching node information.
The purpose of this step is to find the corresponding matching node code identifier through the matching node information, and the matching node code identifier indicates the storage position of the matching node code.
The node information in the template syntax tree further includes matching node code identification. And when the matching node code identification is used for generating the template program code, searching the matching node code corresponding to the matching node code identification.
The matching node code is the program code corresponding to the matching node. When the matching node code is stored in the memory, the matching node code identifier is the initial memory address stored in the matching node code, and the initial memory address can be an actual address or a name representing the address; and when the matched node code is stored in the hard disk file, the matched node code identifier is the file name stored in the matched node code.
The method for acquiring the corresponding matching node code identification by using the matching node information comprises the following steps:
and calling a hook callback function by using the matching node information to acquire the returned matching node code identifier.
A callback function is a function called by a function pointer. If you pass a pointer (address) to a function as a parameter to another function, we say that this is a callback function when this pointer is used to call the function that it points to. Typically for intercepting messages, obtaining system information, or handling asynchronous events.
The hook function is part of the message processing mechanism, and by setting a hook, an application program can filter all messages and events at a system level and access messages which cannot be accessed under normal conditions. The essence of a hook is a program that handles system messages, which are put on the system through system calls.
The hook callback function is a function for calling the callback function to complete data processing by using a processing mechanism of the hook on the message.
For example, the matching node information is passed into a hook callback function, where the matching node information is operated on, and the function returns a matching node code identification.
And step S104, after all the nodes in the template grammar tree acquire the corresponding matched node code identifications, restoring the matched node codes corresponding to the matched node code identifications of each node by using the template grammar tree to generate template program codes.
Optionally, before the obtaining of the information of the plurality of setting nodes associated with the template syntax tree, the method further includes the following steps:
and step S100, analyzing the preset program code segment based on the preset lexical analysis rule and the preset syntactic analysis rule to generate a corresponding template grammar tree.
The purpose of this step is to generate a template syntax tree for a predetermined section of program code that is selected as a template.
For example, parsing a predetermined program code segment into an abstract syntax tree requires the use of predetermined lexical analysis rules and predetermined syntax analysis rules, which are procedures in computer science for converting character sequences into tag sequences. A program or function generated based on a preset lexical analysis rule is called a lexical analyzer, also called a scanner. The lexical analyzer generally exists in the form of a function for being called by the parser based on a preset parsing rule. A parser, which is usually presented as a component of a compiler or interpreter, functions to perform syntax checking and construct a data structure (typically a hierarchical data structure such as a parse tree, abstract syntax tree, etc.) consisting of the input words. A parser typically uses a separate lexical parser to separate individual "words" from the input character stream and uses the word stream as its input.
Optionally, the restoring, by using the template syntax tree, the matching node code corresponding to the matching node code identifier of each node to generate a template program code includes the following steps:
and step S104-1, analyzing the template grammar tree based on a preset lexical analysis rule and a preset grammar analysis rule, and acquiring corresponding position information of each node in the template grammar tree in a template program code.
This step essentially resolves the program code into the inverse of the template syntax tree.
And step S104-2, acquiring corresponding matched node codes through the matched node code identification of each node.
And S104-3, respectively inserting the matched node codes into the position information of the corresponding nodes to generate template program codes.
The embodiment of the disclosure abstracts the program codes into a tree by using the template syntax tree as the middleware of the standardized template, and constrains the relationship of the template codes by using the characteristics of the tree structure. Meanwhile, the node information is set to comprise the matching rule and the non-matching rule, so that the flexibility and the universality of matching are improved. The efficiency of template program code generation is improved. The method and the device do not need to write template codes, and reduce error rate.
Corresponding to the first embodiment provided by the present disclosure, the present disclosure also provides a second embodiment, i.e., a language processing apparatus. Since the second embodiment is basically similar to the first embodiment, the description is simple, and the relevant portions should be referred to the corresponding description of the first embodiment. The device embodiments described below are merely illustrative.
Fig. 2 illustrates an embodiment of an apparatus for language processing provided by the present disclosure. Fig. 2 is a block diagram of elements of a language processing apparatus according to an embodiment of the present disclosure.
Referring to fig. 2, the present disclosure provides a language processing apparatus, including: an acquisition setting node information unit 201, a matching node unit 202, a storage identification unit 203, and a code generation unit 204.
An acquisition setting node information unit 201 for acquiring a plurality of setting node information associated with the template syntax tree;
a matching node unit 202, configured to traverse nodes in the template syntax tree respectively by using each set node information, and obtain matching node information;
a storage identification unit 203, configured to obtain a corresponding matching node code identification by using each piece of matching node information, and store the matching node code identification in the corresponding matching node information;
a code generating unit 204, configured to restore, by using the template syntax tree, a matching node code corresponding to the matching node code identifier of each node after all nodes in the template syntax tree acquire the corresponding matching node code identifiers, and generate a template program code.
Optionally, the set node information includes a first matching node name and a matching rule and/or a non-matching rule;
the matching rule comprises the following steps: first matching depth information traversed upwards and second matching node names in the first matching depth range; in addition, the method also comprises first matching success interruption information of a third matching node name and/or first matching failure interruption information of a fourth matching node name within a first matching depth range;
the non-matching rule includes: the second matching depth information traversed upwards and a non-matching fifth matching node name in the second matching depth range; and in addition, second matching success interruption information of a sixth matching node name and/or second matching failure interruption information of a seventh matching node name in a second matching depth range is/are included.
Optionally, the matching sequence of the nodes in the set node information is consistent with the description sequence.
Optionally, the matching node unit 202 includes:
and the matching node subunit is used for traversing the nodes in the template syntax tree by adopting a depth-first traversal algorithm, matching the nodes by adopting the set node information and acquiring the matching node information.
Optionally, the storage identification unit 203 includes:
and the acquiring identifier subunit is used for calling a hook callback function by using the matching node information to acquire the returned matching node code identifier.
Optionally, in the apparatus, the apparatus further includes:
and the template grammar tree generating unit is used for analyzing the preset program code segments based on a preset lexical analysis rule and a preset grammar analysis rule before the plurality of setting node information associated with the template grammar tree is acquired, and generating the corresponding template grammar tree.
Optionally, the code generating unit 204 includes:
the position information obtaining subunit is used for analyzing the template syntax tree based on a preset lexical analysis rule and a preset syntax analysis rule, and obtaining the position information corresponding to each node in the template syntax tree in a template program code;
a matching node code acquiring subunit, configured to acquire a corresponding matching node code through a matching node code identifier of each node;
and the template program code generating subunit is used for respectively inserting the matched node codes into the position information of the corresponding nodes to generate template program codes.
The embodiment of the disclosure abstracts the program codes into a tree by using the template syntax tree as the middleware of the standardized template, and constrains the relationship of the template codes by using the characteristics of the tree structure. Meanwhile, the node information is set to comprise the matching rule and the non-matching rule, so that the flexibility and the universality of matching are improved. The efficiency of template program code generation is improved. The method and the device do not need to write template codes, and reduce error rate.
The present disclosure provides a third embodiment, namely, an electronic device, which is used for a method for language processing, and includes: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the one processor to cause the at least one processor to perform the method of language processing as described in the first embodiment.
The disclosed embodiments provide a fourth embodiment, namely a computer storage medium for language processing, which stores computer-executable instructions that can execute the method for language processing as described in the first embodiment.
Referring now to FIG. 3, shown is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 3 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 3, the electronic device may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 301 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 302 or a program loaded from a storage device 308 into a Random Access Memory (RAM) 303. In the RAM 303, various programs and data necessary for the operation of the electronic apparatus are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input/output (I/O) interface 305 is also connected to bus 304.
Generally, the following devices may be connected to the I/O interface 305: input devices 306 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, or the like; an output device 307 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 308 including, for example, magnetic tape, hard disk, etc.; and a communication device 309. The communication means 309 may allow the electronic device to communicate wirelessly or by wire with other devices to exchange data. While fig. 3 illustrates an electronic device having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication means 309, or installed from the storage means 308, or installed from the ROM 302. The computer program, when executed by the processing device 301, performs the above-described functions defined in the methods of the embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems on a chip (SOCs), complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other embodiments in which any combination of the features described above or their equivalents does not depart from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (9)

1. A method of language processing, comprising:
acquiring a plurality of setting node information associated with a template syntax tree;
traversing nodes in the template syntax tree by adopting each set node information respectively to obtain matched node information;
respectively acquiring corresponding matching node code identifications by using each piece of matching node information, and storing the matching node code identifications into the corresponding matching node information;
when all nodes in the template grammar tree acquire the corresponding matching node code identifications, restoring the matching node codes corresponding to the matching node code identification of each node by using the template grammar tree to generate template program codes;
the set node information comprises a first matching node name and a matching rule and/or a non-matching rule;
the matching rule includes: first matching depth information traversed upwards and second matching node names in the first matching depth range; in addition, the method also comprises first matching success interruption information of a third matching node name and/or first matching failure interruption information of a fourth matching node name within a first matching depth range;
the non-matching rule comprises: the second matching depth information traversed upwards and a non-matching fifth matching node name in the second matching depth range; in addition, second matching success interruption information of a sixth matching node name and/or second matching failure interruption information of a seventh matching node name within a second matching depth range is included.
2. The method according to claim 1, wherein the matching order of the nodes in the set node information coincides with the description order.
3. The method of claim 1, wherein traversing nodes in the template syntax tree using the set node information to obtain matching node information comprises:
and traversing the nodes in the template syntax tree by adopting a depth-first traversal algorithm, and matching the nodes by adopting the set node information to obtain matched node information.
4. The method according to claim 1, wherein said obtaining the corresponding matching node code identification using the matching node information comprises:
and calling a hook callback function by using the matching node information to acquire the returned matching node code identifier.
5. The method of claim 1, further comprising, prior to said obtaining a plurality of setup node information associated with the template syntax tree:
and analyzing the preset program code segments based on the preset lexical analysis rule and the preset syntactic analysis rule to generate a corresponding template grammar tree.
6. The method of claim 5, wherein the restoring the matched node code of each node using the template syntax tree identifies a corresponding matched node code, and generating a template program code comprises:
analyzing the template grammar tree based on a preset lexical analysis rule and a preset grammar analysis rule to obtain corresponding position information of each node in the template grammar tree in a template program code;
acquiring a corresponding matching node code through the matching node code identifier of each node;
and respectively inserting the matched node codes into the position information of the corresponding nodes to generate template program codes.
7. An apparatus for language processing, comprising:
an acquisition setting node information unit for acquiring a plurality of setting node information associated with the template syntax tree;
the matching node unit is used for respectively traversing the nodes in the template syntax tree by adopting each set node information to acquire matching node information;
the storage identification unit is used for respectively acquiring corresponding matching node code identifications by utilizing each piece of matching node information and storing the matching node code identifications into the corresponding matching node information;
a code generation unit, configured to restore, by using the template syntax tree, a matching node code corresponding to the matching node code identifier of each node after all nodes in the template syntax tree acquire the corresponding matching node code identifiers, and generate a template program code;
the set node information comprises a first matching node name and a matching rule and/or a non-matching rule;
the matching rule includes: first matching depth information traversed upwards and second matching node names in the first matching depth range; in addition, the method also comprises first matching success interruption information of a third matching node name and/or first matching failure interruption information of a fourth matching node name within a first matching depth range;
the non-matching rule includes: the second matching depth information traversed upwards and a non-matching fifth matching node name in the second matching depth range; and in addition, second matching success interruption information of a sixth matching node name and/or second matching failure interruption information of a seventh matching node name in a second matching depth range is/are included.
8. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1 to 6.
9. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out the method of any one of claims 1 to 6.
CN202010099810.2A 2020-02-18 2020-02-18 Language processing method, device, medium and electronic equipment Active CN111367527B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010099810.2A CN111367527B (en) 2020-02-18 2020-02-18 Language processing method, device, medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010099810.2A CN111367527B (en) 2020-02-18 2020-02-18 Language processing method, device, medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN111367527A CN111367527A (en) 2020-07-03
CN111367527B true CN111367527B (en) 2023-03-28

Family

ID=71206331

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010099810.2A Active CN111367527B (en) 2020-02-18 2020-02-18 Language processing method, device, medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN111367527B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112306499B (en) * 2020-11-24 2023-10-13 中国工商银行股份有限公司 Program element extraction method and device

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8881122B1 (en) * 2011-12-09 2014-11-04 Google Inc. Predicate matching library for complex program analysis
WO2016163901A1 (en) * 2015-04-07 2016-10-13 Huawei Technologies Co., Ltd. An apparatus for processing an abstract syntax tree being associated with a source code of a source program
CN108182069A (en) * 2017-12-28 2018-06-19 深圳市创梦天地科技股份有限公司 Programming language transformation method, terminal device and computer-readable medium
CN109814866A (en) * 2019-01-31 2019-05-28 天津字节跳动科技有限公司 Page application is converted into the treating method and apparatus of native applications
CN109947431A (en) * 2019-03-28 2019-06-28 北京字节跳动网络技术有限公司 A kind of code generating method, device, equipment and storage medium
CN109947433A (en) * 2019-03-28 2019-06-28 优信拍(北京)信息科技有限公司 A kind of generation method of small routine, update method and device
CN110187885A (en) * 2019-06-10 2019-08-30 合肥本源量子计算科技有限责任公司 A kind of the intermediate code generation method and device of the compiling of quantum program
CN110275709A (en) * 2018-03-15 2019-09-24 阿里巴巴集团控股有限公司 Processing and optimization method, device, equipment and storage medium for dynamic language
CN110471666A (en) * 2019-07-18 2019-11-19 五八有限公司 Code automatic switching method and device, code converter and medium
CN110554875A (en) * 2018-05-30 2019-12-10 北京三快在线科技有限公司 Code conversion method and device, electronic equipment and storage medium
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100153933A1 (en) * 2008-12-17 2010-06-17 Karsten Bohlmann Path Navigation In Abstract Syntax Trees
US20140282373A1 (en) * 2013-03-15 2014-09-18 Trinity Millennium Group, Inc. Automated business rule harvesting with abstract syntax tree transformation

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8881122B1 (en) * 2011-12-09 2014-11-04 Google Inc. Predicate matching library for complex program analysis
WO2016163901A1 (en) * 2015-04-07 2016-10-13 Huawei Technologies Co., Ltd. An apparatus for processing an abstract syntax tree being associated with a source code of a source program
CN108182069A (en) * 2017-12-28 2018-06-19 深圳市创梦天地科技股份有限公司 Programming language transformation method, terminal device and computer-readable medium
CN110275709A (en) * 2018-03-15 2019-09-24 阿里巴巴集团控股有限公司 Processing and optimization method, device, equipment and storage medium for dynamic language
CN110554875A (en) * 2018-05-30 2019-12-10 北京三快在线科技有限公司 Code conversion method and device, electronic equipment and storage medium
CN109814866A (en) * 2019-01-31 2019-05-28 天津字节跳动科技有限公司 Page application is converted into the treating method and apparatus of native applications
CN109947431A (en) * 2019-03-28 2019-06-28 北京字节跳动网络技术有限公司 A kind of code generating method, device, equipment and storage medium
CN109947433A (en) * 2019-03-28 2019-06-28 优信拍(北京)信息科技有限公司 A kind of generation method of small routine, update method and device
CN110187885A (en) * 2019-06-10 2019-08-30 合肥本源量子计算科技有限责任公司 A kind of the intermediate code generation method and device of the compiling of quantum program
CN110471666A (en) * 2019-07-18 2019-11-19 五八有限公司 Code automatic switching method and device, code converter and medium
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于模板的代码转换工具;刘毅等;《计算机系统应用》(第02期);全文 *

Also Published As

Publication number Publication date
CN111367527A (en) 2020-07-03

Similar Documents

Publication Publication Date Title
CN111324342B (en) Method, device, medium and electronic equipment for generating interface layer code
CN109726217B (en) Database operation method, device, equipment and storage medium
CN111506900A (en) Vulnerability detection method and device, electronic equipment and computer storage medium
CN111338813B (en) Method, device, medium and electronic equipment for dynamically generating middleware
CN114035805A (en) Code conversion method, apparatus, medium, and device for pre-compiler
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN107729001B (en) Expression processing method and device
CN112380876A (en) Translation method, device, equipment and medium based on multi-language machine translation model
CN114721656A (en) Interface structure extraction method, device, medium and electronic equipment
CN111367527B (en) Language processing method, device, medium and electronic equipment
CN113220281A (en) Information generation method and device, terminal equipment and storage medium
CN110704050B (en) Module initializing method and device, electronic equipment and computer readable storage medium
CN111666218A (en) Code auditing method and device, electronic equipment and medium
CN111240801A (en) Method, device, medium and electronic equipment for generating heap memory snapshot file
CN111752644A (en) Interface simulation method, device, equipment and storage medium
CN111124541A (en) Configuration file generation method, device, equipment and medium
CN111414161B (en) Method, device, medium and electronic equipment for generating IDL file
CN110806967A (en) Unit testing method and device
CN113761588A (en) Data verification method and device, terminal equipment and storage medium
CN111367791A (en) Method, device, medium and electronic equipment for generating test case
CN111796865A (en) Byte code file modification method and device, terminal equipment and medium
CN111797009A (en) Method and device for detecting code compatibility and electronic equipment
CN113448602A (en) Version updating method and device
CN111209042B (en) Method, device, medium and electronic equipment for establishing function stack
CN111221513B (en) Method, device, medium and electronic equipment for adjusting cascading style sheet

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
GR01 Patent grant
GR01 Patent grant