CN114443048A - Text-based compiling method and device, electronic equipment and storage medium - Google Patents

Text-based compiling method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114443048A
CN114443048A CN202111653352.3A CN202111653352A CN114443048A CN 114443048 A CN114443048 A CN 114443048A CN 202111653352 A CN202111653352 A CN 202111653352A CN 114443048 A CN114443048 A CN 114443048A
Authority
CN
China
Prior art keywords
text
lexical
target
grammar
parsing
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
CN202111653352.3A
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.)
Tianyi Cloud Technology Co Ltd
Original Assignee
Tianyi Cloud 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 Tianyi Cloud Technology Co Ltd filed Critical Tianyi Cloud Technology Co Ltd
Priority to CN202111653352.3A priority Critical patent/CN114443048A/en
Publication of CN114443048A publication Critical patent/CN114443048A/en
Pending legal-status Critical Current

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
    • G06F8/427Parsing
    • 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/51Source to source

Abstract

The embodiment of the application provides a text-based compiling method, a text-based compiling device, electronic equipment and a storage medium, wherein each specified target text word in an input text is positioned based on preset target position information, so that each corresponding lexical unit and reading sequence information of each lexical unit are determined from the input text based on the respective positioning of each target text word, and the selective reading of each lexical unit is realized according to each reading sequence information, so that the structuring of corresponding lexical data streams is realized.

Description

Text-based compiling method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a text-based compiling method and apparatus, an electronic device, and a storage medium.
Background
In the computer field, the translation process from the original language to the target language is generally called compilation (complex) and is usually performed by a Finite State automaton (FSM). Specifically, after the lexical analyzer performs lexical analysis on the input text, the data stream represented by the input text is converted into corresponding lexical streams, and each lexical unit in the lexical streams is further converted into a grammar node in a corresponding grammar tree by a grammar analyzer in the FSM in a mode of stipulation or deduction, so that the corresponding compiled text is output through each grammar node of the grammar tree.
However, in the above process, the reading order of each lexical unit output by the lexical analyzer is fixed, so when the syntax parser performs syntax parsing, only a corresponding reduction (deduction) process can be performed on each lexical unit according to the reading order of the lexical unit.
Disclosure of Invention
The embodiment of the application provides a compiling method and device based on a text, an electronic device and a storage medium, which are used for improving the development efficiency of text compiling.
In a first aspect, an embodiment of the present application provides a text-based compiling apparatus, including:
acquiring an input text to be compiled, wherein the input text at least carries: target location information determined for specifying each target text word.
Performing lexical analysis on an input text, and determining corresponding lexical units based on text position information, wherein each lexical unit at least carries: corresponding read order information.
And according to the arrangement sequence from small to large, sequentially carrying out grammar analysis on each lexical unit carrying the corresponding reading sequence identifier to obtain a corresponding analysis text stream.
And carrying out grammar conversion on the analysis text stream based on a preset grammar rule to obtain a compiling result of the input text.
In a second aspect, an embodiment of the present application provides a text-based compiling apparatus, including:
an obtaining module, configured to obtain an input text to be compiled, where the input text at least carries: target position information determined for each specified target text word.
And the lexical analysis module is used for performing lexical analysis on the input text and determining corresponding lexical units based on the target position information, wherein each lexical unit at least carries: corresponding read order information.
And the grammar parsing module is used for sequentially parsing the grammatical units carrying the corresponding reading sequence identifiers according to the arrangement sequence from small to large to obtain corresponding parsed text streams.
And the conversion module is used for carrying out grammar conversion on the analysis text stream based on a preset grammar rule to obtain a compiling result of the input text.
In an optional embodiment, when performing lexical analysis on the input text and determining each corresponding lexical unit based on the target location information, the lexical analysis module is specifically configured to:
segmenting the input text based on a preset dictionary library, and determining at least one piece of corresponding segmentation position information;
constructing a corresponding lexical acyclic graph based on the at least one segmentation position information, and performing path analysis on the lexical acyclic graph based on a preset dynamic standard algorithm to obtain a corresponding target path;
and determining corresponding lexical units from the input text based on the target path and the target position information.
In an optional embodiment, when performing syntax transformation on the parsing text stream based on a preset syntax rule to obtain a compiling result of the input text, the transformation module is specifically configured to:
determining the respective text type of each parsing text unit in the parsing text stream based on a preset grammar rule, and constructing a corresponding parsing grammar tree based on each determined text type.
And traversing the parsing syntax tree based on a preset traversal sequence to determine corresponding syntax tree nodes.
And respectively carrying out grammar conversion on each grammar tree node to obtain a corresponding target text, and taking the target text as a compiling result of the input text.
In an optional embodiment, when performing syntax transformation on each syntax tree node to obtain a corresponding target text, the transformation module is specifically configured to:
respectively executing the following operations for each syntax tree node: determining a target conversion function corresponding to the node type from a preset conversion function set based on the node type of one grammar tree node, and carrying out grammar conversion on one grammar tree node based on the target conversion function to obtain a corresponding conversion text;
and determining text rules for the converted texts based on the traversal sequence, and arranging the converted texts based on the text rules to obtain corresponding target texts.
In a third aspect, an embodiment of the present application further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, where the computer program, when executed by the processor, causes the processor to implement any one of the text-based compiling methods in the first aspect.
In a fourth aspect, the present application further provides a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the text-based compiling method of the first aspect is implemented.
For technical effects brought by any one implementation manner in the second aspect to the fourth aspect, reference may be made to technical effects brought by a corresponding implementation manner in the first aspect, and details are not described here.
Drawings
Fig. 1 is a schematic diagram of a text compiling logic in a related art according to an embodiment of the present application;
fig. 2 is a schematic view of an application scenario provided in an embodiment of the present application;
FIG. 3 is an architecture diagram of a text compiler according to an embodiment of the present application;
fig. 4 is a flowchart of a text-based compiling method according to an embodiment of the present application;
fig. 5 is an exemplary diagram of parsing a text tree according to an embodiment of the present application;
fig. 6 is a logic diagram of a text-based compiling method according to an embodiment of the present application;
fig. 7 is a schematic diagram of a group session syntax extension logic according to an embodiment of the present application;
FIG. 8 is a diagram illustrating extended logic of a WITH FUNCTION grammar according to an embodiment of the present application;
fig. 9 is a schematic diagram of a text-based compiling apparatus according to an embodiment of the present application;
fig. 10 is a schematic view of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given in the present application without making any creative effort, shall fall within the protection scope of the present invention.
The design idea of the application is as follows:
referring to fig. 1, in the related art, a compiler is generally a streaming text processor, which mainly includes: two important components, namely a lexical analyzer and a grammar parser, are that an input language (text) is generally regarded as a string of continuous data streams in the text compiling process, each specified vocabulary contained in the text is analyzed and extracted by the lexical analyzer when the data streams pass through the lexical analyzer, and a lexical data stream consisting of a plurality of vocabularies is output, and each lexical unit in the lexical data stream can be regarded as a terminator (namely the lexical deduction can be terminated, and the word is a specific object of the input language (text) and is not an abstract grammatical concept), so the lexical analyzing process generally corresponds to the process of converting the original data stream into a corresponding terminator stream.
Further, the lexical analyzer transmits the converted lexical data stream to the parser, the parser determines, for each read lexical unit (terminal) by a reduction (or deduction) and the like, a target state to which the parser is to be transferred according to the lexical characteristics of the currently read lexical unit (and the subsequently read lexical units) in combination with the current state of the parser, and performs a corresponding action, and through the above-mentioned series of actions, the parser converts the lexical data stream (terminal stream) into a syntax tree containing non-terminal symbols (non-leaf nodes) and terminal symbols (leaf nodes), that is, in the lexical data stream, each lexical unit (terminal symbol) is parsed separately, and during the whole parsing process, the reading order of each lexical unit (terminal symbol) is unchanged and each lexical unit is read only once, that is, the parser can only read each lexical unit (terminator) in sequence in a move-in manner, and cannot loop or jump the read operation. In other words, the parser can only decide whether to move in and out of a convention (or deduction), and the structure of the parser remains unchanged throughout the parsing process (only the current state is changed, not the state transition function).
However, in the above process, since the reading order of each lexical unit (terminal) by the parser is fixed, that is, the lexical data stream (terminal stream) composed of each lexical unit (terminal) is usually unstructured (i.e. branch, loop, and jump cannot be performed), this method, although it is very flexible, cannot fully utilize the implemented grammar rules, and is not conducive to implementing grammar multiplexing in the work of grammar extension, grammar compatibility, and the like, resulting in low development efficiency of text compilation in the related art.
In order to solve the problem of low text compiling and developing efficiency in the related art, embodiments of the present application provide a text-based compiling method, apparatus, electronic device, and storage medium, where each specified target text word in an input text is located based on preset target position information, so that, based on the respective location of each target text word, corresponding lexical units and respective reading order information of each lexical unit are determined from the input text, and selective reading of each lexical unit is implemented according to each reading order information, thereby implementing structuring of corresponding lexical data streams, and in syntax expansion and syntax compatibility work, implemented grammars can be effectively multiplexed, and time cost and developing efficiency of text compiling are reduced. Meanwhile, based on the method, the grammar and grammar can be designed more flexibly, the expression range of the grammar is expanded in order of magnitude, tasks which cannot be completed originally are completed, and the extensibility of the compiling language is further improved remarkably.
The preferred embodiments of the present application will be described and illustrated in conjunction with the appended drawings.
Fig. 2 is a schematic view of an application scenario according to an embodiment of the present application. The application scenario diagram includes a terminal device 210 and a text compiler 220.
In the embodiment of the present application, the terminal device 210 includes, but is not limited to, a mobile phone, a tablet computer, a notebook computer, a desktop computer, an e-book reader, an intelligent voice interaction device, an intelligent household appliance, a vehicle-mounted terminal, and other devices; the terminal device may be installed with a client related to text compilation, where the client may be software (e.g., a browser), or may also be a web page, an applet, and the like, and the text compiler 220 may be a background server corresponding to the software, or the web page, the applet, and the like, or an electronic device (e.g., a server) specially used for text compilation, and the application is not limited specifically. The text compiler 220 may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as cloud service, a cloud database, cloud computing, a cloud function, cloud storage, web service, cloud communication, middleware service, domain name service, security service, Content Delivery Network (CDN), big data and artificial intelligence platform, and the like.
It should be noted that, the text-based compiling method in the embodiment of the present application may be executed by an electronic device, and the electronic device may be the text compiler 220 or the terminal device 210, that is, the method may be executed by the text compiler 220 or the terminal device 210 alone, or may be executed by both the text compiler 220 and the terminal device 210.
In an alternative embodiment, the terminal device 210 and the text compiler 220 may communicate via a communication network.
In an alternative embodiment, the communication network is a wired network or a wireless network.
It should be noted that fig. 2 is only an example, and the number of the terminal devices and the text compilers is not limited in practice, and is not specifically limited in the embodiment of the present application.
To better explain the design idea of the embodiment of the present application, referring to fig. 3, it is assumed that the text compiler 220 includes four components, namely a lexical locating module 2201, a syntax editing module 2202, a lexical analyzing module 2203, and a syntax parsing module 2204, where:
lexical positioning module 2201: the lexical analysis module 2203 is used for acquiring input text, determining target position information for each specified target text word, and adjusting the current reading position of the lexical analysis module 2203 based on the target position information.
Grammar editing module 2202: the grammar parsing module 2204 is used for adjusting so as to selectively read the corresponding lexical units in a cyclic or jumping manner.
Lexical analysis module 2203: the method is used for analyzing and extracting each lexical unit contained in the input text and outputting corresponding structured lexical data streams.
Grammar parsing module 2204: the grammar unit is used for executing corresponding state transition actions aiming at each lexical unit, constructing a corresponding target grammar tree based on a series of transition actions, and determining a compiling result aiming at the input text based on the target grammar tree.
The text-based compiling method provided by the exemplary embodiment of the present application is described below with reference to the drawings in conjunction with the application scenarios described above, and it should be noted that the application scenarios described above are only shown for the convenience of understanding the spirit and principle of the present application, and the embodiments of the present application are not limited in this respect. In addition, the embodiment of the application can be applied to various scenes, including not only computer language compiling scenes, but also various scenes such as cloud technology, artificial intelligence, intelligent traffic, driving assistance and the like.
In the following, in conjunction with the application scenarios described above, a text-based compiling method provided by the exemplary embodiments of the present application is described with reference to the drawings.
Referring to fig. 4, an embodiment of the present application provides a text-based compiling method, including:
s401: acquiring an input text to be compiled, wherein the input text at least carries: target location information determined for specifying each target text word.
Specifically, the lexical analysis module 2203 obtains an input text to be compiled, and the lexical positioning module 2201 determines corresponding target position information for each specified target text word, and adjusts the current reading position of the lexical analysis module 2203 based on the target position information.
Optionally, the input text comprises a clause, a sentence, a paragraph or a thesis, and the input text is executable text, such as text composed in any natural language.
For example, in an alternative embodiment, the input text is treated as a set of input sentences that are: "today is sunny.
The corresponding target location information may be represented as a start character in the input text or as an end character for the input text, indicating the initial location of reading the input text.
S402: performing lexical analysis on the input text, and determining corresponding lexical units based on the target position information, wherein each lexical unit at least carries: corresponding read order information.
Specifically, the input text is segmented based on a preset dictionary base, at least one piece of corresponding segmentation position information is determined, a corresponding lexical acyclic graph is constructed based on each segmentation position information, the shortest target path is determined from the lexical acyclic graphs, and corresponding lexical units are sequentially determined according to the target path and the target position information determined by the lexical locator.
For example, if the input text is "today is a sunny day", the lexical data streams corresponding to a plurality of different combinations, such as "sunny day" - "today" - "yes", can be obtained by relocating the corresponding lexical units "today", "yes" and "sunny day" included in the input text through the target location information, and specifically, the following combinations are included:
1) "today" - "yes", "sunny day"; 2) "today" - "sunny" - "yes";
3) "is" - "sunny day" - "today"; 4) "is" - "today" - "sunny day";
5) "sunny", "today", "yes"; 6) "sunny" - "is" - "today";
based on the above manner, the reading order information carried by each lexical unit can make the lexical data stream more structural, specifically, allowing branches, loops, jumps, etc. to appear in the lexical data stream, specifically, the branches, loops, jumps, etc. are mainly realized by modifying the reading order information carried by each lexical unit.
For example, for each determined lexical unit "today", "yes" and "sunny day", if the reading order is not modified correspondingly, the default reading order information is determined to be "1", "2" and "3", respectively, and at this time, the corresponding lexical data stream does not have any structure, each lexical unit may be regarded as a terminal to indicate that the lexical unit is a specific object of the input text (e.g., "today"), and in an alternative embodiment, the reading order information of each of the lexical units is determined as shown in table 1 below:
TABLE 1
Lexical unit Reading order information
Today " 1、4
'is' 3
"sunny day" 2、5
Based on the reading order information shown in table 1 above, it can be determined that the corresponding lexical data streams are "today" - "sunny" - "today" - "sunny", and based on the corresponding reading order information, the circulation or skip reading of the corresponding lexical units is performed without following a fixed text reading order, thereby realizing the structuring of the lexical data streams (terminator streams).
S403: and according to the arrangement sequence from small to large, sequentially carrying out grammar analysis on each lexical unit carrying the corresponding reading sequence identifier to obtain a corresponding analysis text stream.
Specifically, the syntax parsing module 2204 sequentially parses the syntax units according to the determined reading sequence, that is, according to the read syntax units (and subsequent syntax units), determines the target state to be transferred, and executes the corresponding state transfer action to obtain the corresponding parsing text stream.
S404: and carrying out grammar conversion on the analysis text stream based on a preset grammar rule to obtain a compiling result of the input text.
Specifically, according to the parsing text unit representing the corresponding state transition action in the obtained parsing text stream, a corresponding parsing syntax tree is constructed, optionally, the parsing syntax tree is traversed according to a preset traversal order, for example, a first-order traversal, a middle-order traversal, a last-order traversal, and the like, corresponding syntax tree nodes are determined, further, text conversion is performed on each syntax tree node, specifically, for each syntax tree node, a target conversion function corresponding to the node type is determined from a preset conversion function set based on the node type of one syntax tree node, and a syntax tree node is subjected to syntax conversion based on the target conversion function, so that a corresponding target text is obtained according to the respective conversion result of each syntax tree node.
For example, if the text stream is analyzed to be characterized as a character string "rename a01 to B01" and then SQL script lexical analysis is performed, the following word sequences are formed: "rename", "a 01", "to", "B01", as shown in fig. 5, the word sequence may generate a corresponding parsing syntax tree based on a preset parsing rule, wherein 1 the parsing syntax tree describes a syntax structure of an SQL script in a tree structure.
Performing semantic analysis on the Rename statement formed by analyzing the syntax tree, specifically, performing syntax conversion on the Rename node in the parsing syntax tree according to depth-first traversal, and determining that the node of the syntax tree represents Wie the renaming operation of a database table; continuously traversing to the subsequent syntax tree node OldTableName of the Rename node in a deep mode, carrying out syntax conversion on the syntax tree node, and determining the syntax tree node as the name of the library table before renaming; and then, deeply traversing subsequent syntax tree nodes A01 of the OldTableName syntax tree nodes, performing syntax conversion on the nodes, determining the name of the original database table to be A01, and after the parsing syntax tree is deeply traversed based on the above process, obtaining corresponding target texts based on respective syntax conversion results of the sequentially traversed syntax tree nodes, wherein the syntax conversion results are as follows: the library table a01 was renamed to B01.
Referring to fig. 6, a logic diagram of a text-based compiling method provided in an embodiment of the present application is shown, where in the logic diagram, a text compiler includes a lexical locating module, a lexical analysis module, a syntax editing module, and a syntax parsing module, and the lexical locating module in the text compiler relocates each specified target text word in an input text, so as to determine corresponding lexical units and reading order information of each lexical unit from the input text based on respective locations of each target text word, and further, the syntax parsing module implements selective reading of each lexical unit according to each reading order information, so as to ensure structuring of a corresponding lexical data stream, and determines a corresponding target text by parsing the lexical data stream.
According to the text-based compiling method provided by the embodiment of the application, realized grammars can be effectively multiplexed in grammar extension and grammar compatibility work, and time cost and development efficiency of text compiling are reduced. For example, in an actual scenario, the extension of the GROUP SETS syntax can be realized BY multiplexing two implemented syntaxes, namely UNION ALL and GROUP BY.
Specifically, referring to fig. 7, in the GROUP session syntax structure, the definition of the data packet is usually represented BY a fixed data pair, such as GROUP session (a, b), GROUP session (b, c), etc., and in an alternative embodiment, a plurality of extensible syntax structures consistent with the GROUP session expression can be constructed BY GROUP BY query and UNION operation.
For example, BY using the GROUP BY query statement, reading the corresponding lexical unit "a" from the GROUP SETS (a, b) and the corresponding lexical unit "c" from the GROUP SETS (b, c), and modifying the corresponding reading order as shown in S401 to S404, which are not described herein again, based on the read lexical units "a", "c" and UNION ALL, an equivalent expression for the syntax structure of the GROUP SETS can be realized.
Or, the extension of the WITH FUNCTION grammar is realized through the calling and the transmission of the local FUNCTION.
Specifically, referring to fig. 8, in the wide FUNCTION syntax, a local FUNCTION f (x, y) is called, for example, in an alternative embodiment, f (x, y) is x + y, and further statements SELECT f (a, b) FROM t and WHERE f (c, d) >0 that conform to the wide FUNCTION syntax structure are called, based on the statements and the text-based compiling method as described in S401-S404 in this embodiment, the local FUNCTION and related parameters can be structurally read.
For example, the equivalent expression SELECT a + b FROM t for the syntax structure of the wild FUNCTION may be implemented by the statement SELECT f (a, b) FROM t WITH the syntax structure of the wild FUNCTION, and the called local FUNCTION f (x, y) x + y, and similarly, in an alternative embodiment, the equivalent expression WHERE c + d >0 may also be implemented for the statement WHERE f (c, d) >0 WITH the syntax structure of the wild FUNCTION.
According to the process, the text-based compiling method provided by the embodiment of the application enables the design of grammar and grammar to be more flexible, enlarges the expression range of the grammar in order of magnitude, completes the tasks which cannot be completed originally, and further enables the extensibility of the compiling language to be remarkably improved.
Referring to fig. 9, a text-based compiling apparatus provided in the embodiment of the present application includes an obtaining module 901, a lexical analysis module 902, a syntax parsing module 903, and a conversion module 904, where:
an obtaining module 901, configured to obtain an input text to be compiled, where the input text at least carries: target position information determined for each specified target text word.
A lexical analysis module 902, configured to perform lexical analysis on the input text, and determine, based on the target location information, each corresponding lexical unit, where each lexical unit at least carries: corresponding read order information.
And the grammar parsing module 903 is configured to perform grammar parsing on the lexical units carrying the corresponding reading order identifiers in sequence according to a small-to-large arrangement order to obtain corresponding parsing text streams.
A converting module 904, configured to perform syntax conversion on the parsing text stream based on a preset syntax rule, so as to obtain a compiling result of the input text.
In an alternative embodiment, when performing lexical analysis on the input text and determining corresponding lexical units based on the target location information, the lexical analysis module 902 is specifically configured to:
segmenting the input text based on a preset dictionary library, and determining at least one piece of corresponding segmentation position information;
constructing a corresponding lexical acyclic graph based on the at least one segmentation position information, and performing path analysis on the lexical acyclic graph based on a preset dynamic standard algorithm to obtain a corresponding target path;
and determining corresponding lexical units from the input text based on the target path and the target position information.
In an alternative embodiment, when performing syntax transformation on the parsing text stream based on a preset syntax rule to obtain a compiling result of the input text, the transformation module 904 is specifically configured to:
determining the respective text type of each parsing text unit in the parsing text stream based on a preset grammar rule, and constructing a corresponding parsing grammar tree based on each determined text type.
And traversing the parsing syntax tree based on a preset traversal sequence to determine corresponding syntax tree nodes.
And respectively carrying out grammar conversion on each grammar tree node to obtain a corresponding target text, and taking the target text as a compiling result of the input text.
In an alternative embodiment, when performing syntax transformation on each syntax tree node to obtain a corresponding target text, the transformation module 904 is specifically configured to:
respectively executing the following operations for each syntax tree node: determining a target conversion function corresponding to the node type from a preset conversion function set based on the node type of one grammar tree node, and carrying out grammar conversion on one grammar tree node based on the target conversion function to obtain a corresponding conversion text;
and determining text rules for the converted texts based on the traversal sequence, and arranging the converted texts based on the text rules to obtain corresponding target texts.
Based on the same inventive concept as the embodiment of the application, the embodiment of the application also provides electronic equipment which can be used for text-based compiling. In one embodiment, the electronic device may be a server, a terminal device, or other electronic device. In this embodiment, the electronic device may be configured as shown in fig. 10, and include a memory 1001, a communication interface 1003, and one or more processors 1002.
A memory 1001 for storing computer programs executed by the processor 1002. The memory 1001 may mainly include a storage program area and a storage data area, where the storage program area may store an operating system, a program required for running an instant messaging function, and the like; the storage data area can store various instant messaging information, operation instruction sets and the like.
Memory 1001 may be a volatile memory (volatile memory), such as a random-access memory (RAM); the memory 1001 may also be a non-volatile memory (non-volatile memory) such as, but not limited to, a read-only memory (rom), a flash memory (flash memory), a Hard Disk Drive (HDD) or a solid-state drive (SSD), or any other medium which can be used to carry or store desired program code in the form of instructions or data structures and which can be accessed by a computer. Memory 1001 may be a combination of the above.
The processor 1002 may include one or more Central Processing Units (CPUs), a digital Processing Unit, and the like. A processor 1002 for implementing the above-described text-based compilation method when invoking the computer program stored in the memory 1001.
The communication interface 1003 is used for communicating with a terminal device and other servers.
In the embodiment of the present application, the specific connection medium among the memory 1001, the communication interface 1003, and the processor 1002 is not limited. In the embodiment of the present application, the memory 1001 and the processor 1002 are connected by a bus 1004 in fig. 10, the bus 1004 is represented by a thick line in fig. 10, and the connection manner between other components is merely illustrative and is not limited thereto. The bus 1004 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 10, but this is not intended to represent only one bus or type of bus.
According to an aspect of the application, a computer program product or computer program is provided, comprising computer instructions, the computer instructions being stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions to cause the computer device to perform any of the text-based compiling methods of the above embodiments. The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A 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 (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable 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.
The embodiment of the application provides a text-based compiling method, a text-based compiling device, electronic equipment and a storage medium, wherein each specified target text word in an input text is positioned based on preset target position information, so that each corresponding lexical unit and reading sequence information of each lexical unit are determined from the input text based on the respective positioning of each target text word, and the selective reading of each lexical unit is realized according to each reading sequence information, so that the structuring of corresponding lexical data streams is realized, grammars can be effectively multiplexed in grammar expansion and grammar compatibility work, and the time cost and the development efficiency of text compiling are reduced. Meanwhile, based on the method, the grammar and grammar can be designed more flexibly, the expression range of the grammar is expanded in order of magnitude, tasks which cannot be completed originally are completed, and the extensibility of the compiling language is further improved remarkably.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A text-based compilation method, comprising:
acquiring an input text to be compiled, wherein the input text at least carries: target position information determined for each specified target text word;
performing lexical analysis on the input text, and determining corresponding lexical units based on the target position information, wherein each lexical unit at least carries: corresponding reading order information;
according to the arrangement sequence from small to large, syntax analysis is carried out on all the lexical units carrying the corresponding reading sequence identifications in sequence to obtain corresponding analysis text streams;
and carrying out grammar conversion on the analysis text stream based on a preset grammar rule to obtain a compiling result of the input text.
2. The method of claim 1, wherein said lexical analyzing said input text and determining respective lexical units based on said target location information comprises:
segmenting the input text based on a preset dictionary library, and determining at least one piece of corresponding segmentation position information;
constructing a corresponding lexical acyclic graph based on the at least one segmentation position information, and performing path analysis on the lexical acyclic graph based on a preset dynamic standard algorithm to obtain a corresponding target path;
and determining corresponding lexical units from the input text based on the target path and the target position information.
3. The method according to claim 1 or 2, wherein the parsing text stream based on a preset grammar rule to obtain a compiling result of the input text comprises:
determining the text type of each parsing text unit in the parsing text stream based on a preset grammar rule, and constructing a corresponding parsing grammar tree based on each determined text type;
traversing the parsing syntax tree based on a preset traversal order, and determining corresponding syntax tree nodes;
and respectively carrying out grammar conversion on each grammar tree node to obtain a corresponding target text, and taking the target text as a compiling result of the input text.
4. The method according to claim 1 or 2, wherein said separately syntactically transforming said respective syntax tree nodes to obtain corresponding target texts comprises:
for each syntax tree node, performing the following operations: determining a target conversion function corresponding to a node type from a preset conversion function set based on the node type of the node of a grammar tree, and carrying out grammar conversion on the node of the grammar tree based on the target conversion function to obtain a corresponding conversion text;
and determining a text rule for each converted text based on the traversal sequence, and arranging each converted text based on the text rule to obtain a corresponding target text.
5. A text-based compiling apparatus characterized by comprising:
an obtaining module, configured to obtain an input text to be compiled, where the input text at least carries: target position information determined for each specified target text word;
and the lexical analysis module is used for performing lexical analysis on the input text and determining corresponding lexical units based on the text position information, wherein each lexical unit at least carries: corresponding reading order information;
the grammar parsing module is used for sequentially parsing the grammatical units carrying the corresponding reading sequence identifiers according to the arrangement sequence from small to large to obtain corresponding parsed text streams;
and the conversion module is used for carrying out grammar conversion on the analysis text stream based on a preset grammar rule to obtain a compiling result of the input text.
6. The apparatus of claim 5, wherein the lexical analysis module, when performing lexical analysis on the input text and determining corresponding lexical units based on the target location information, is specifically configured to:
segmenting the input text based on a preset dictionary library, and determining at least one piece of corresponding segmentation position information;
constructing a corresponding lexical acyclic graph based on the at least one segmentation position information, and performing path analysis on the lexical acyclic graph based on a preset dynamic standard algorithm to obtain a corresponding target path;
and determining corresponding lexical units from the input text based on the target path and the target position information.
7. The apparatus according to claim 5 or 6, wherein, when performing syntax transformation on the parsing text stream based on a preset syntax rule and obtaining a compiling result of the input text, the transformation module is specifically configured to:
determining the text type of each parsing text unit in the parsing text stream based on a preset grammar rule, and constructing a corresponding parsing grammar tree based on each determined text type;
traversing the parsing syntax tree based on a preset traversal sequence to determine corresponding syntax tree nodes;
and respectively carrying out grammar conversion on each grammar tree node to obtain a corresponding target text, and taking the target text as a compiling result of the input text.
8. The apparatus according to claim 5 or 6, wherein, when performing syntax transformation on each of the syntax tree nodes to obtain the corresponding target text, the transformation module is specifically configured to:
for each syntax tree node, performing the following operations: determining a target conversion function corresponding to a node type from a preset conversion function set based on the node type of the node of a syntax tree, and carrying out syntax conversion on the node of the syntax tree based on the target conversion function to obtain a corresponding conversion text;
and determining a text rule for each converted text based on the traversal sequence, and arranging each converted text based on the text rule to obtain a corresponding target text.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the text-based compilation method as claimed in any one of claims 1 to 4 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 4.
CN202111653352.3A 2021-12-30 2021-12-30 Text-based compiling method and device, electronic equipment and storage medium Pending CN114443048A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111653352.3A CN114443048A (en) 2021-12-30 2021-12-30 Text-based compiling method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111653352.3A CN114443048A (en) 2021-12-30 2021-12-30 Text-based compiling method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114443048A true CN114443048A (en) 2022-05-06

Family

ID=81365217

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111653352.3A Pending CN114443048A (en) 2021-12-30 2021-12-30 Text-based compiling method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114443048A (en)

Similar Documents

Publication Publication Date Title
CN111708539B (en) Application program code conversion method and device, electronic equipment and storage medium
US11334692B2 (en) Extracting a knowledge graph from program source code
CN110442330B (en) List component conversion method and device, electronic equipment and storage medium
CN106547527B (en) JavaScript file construction method and device
CN111209005B (en) Method and apparatus for compiling program file, and computer-readable storage medium
US10055399B2 (en) Method and system for linear generalized LL recognition and context-aware parsing
CN110502227B (en) Code complement method and device, storage medium and electronic equipment
CN111045678A (en) Method, device and equipment for executing dynamic code on page and storage medium
CN110244941B (en) Task development method and device, electronic equipment and computer readable storage medium
CN109710260B (en) Multi-platform-based applet code conversion method
WO2023065629A1 (en) Dialogue management method and system, and terminal and storage medium
CN103677952A (en) Coder decoder generating device and method
CN115509514B (en) Front-end data simulation method, device, equipment and medium
CN114895908B (en) Web application expression-based implementation method, system, equipment and storage medium
JP2021111327A (en) Method for generating api knowledge graph, system, and non-transitory computer-readable medium
CN115148212A (en) Voice interaction method, intelligent device and system
CN102707934B (en) A kind of realize method and system with what form of scripts represented value-added service flow process
CN112269566B (en) Script generation processing method, device, equipment and system
CN110362317B (en) Code conversion method, device and storage medium
CN110851678B (en) Method and device for crawling data
CN114115900B (en) Script compiling method and device and electronic equipment
CN114443048A (en) Text-based compiling method and device, electronic equipment and storage medium
CN112925889A (en) Natural language processing method, device, electronic equipment and storage medium
CN111539200A (en) Method, device, medium and electronic equipment for generating rich text
CN112988778A (en) Method and device for processing database query script

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