CN108170435A - A kind of source code conversion method, device and equipment - Google Patents

A kind of source code conversion method, device and equipment Download PDF

Info

Publication number
CN108170435A
CN108170435A CN201810040092.4A CN201810040092A CN108170435A CN 108170435 A CN108170435 A CN 108170435A CN 201810040092 A CN201810040092 A CN 201810040092A CN 108170435 A CN108170435 A CN 108170435A
Authority
CN
China
Prior art keywords
syntax tree
abstract syntax
source code
tree
nodal community
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
CN201810040092.4A
Other languages
Chinese (zh)
Inventor
冯文杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ucweb Singapore Pte Ltd
Original Assignee
Ucweb Singapore Pte 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 Ucweb Singapore Pte Ltd filed Critical Ucweb Singapore Pte Ltd
Priority to CN201810040092.4A priority Critical patent/CN108170435A/en
Publication of CN108170435A publication Critical patent/CN108170435A/en
Pending legal-status Critical Current

Links

Classifications

    • 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

Abstract

This application discloses a kind of source code conversion method, device and equipment, in the source code conversion method, JSX source code character strings can be converted to JavaScript source code, to realize the conversion between different type source code;By the above method, JSX source codes that developer can be relatively simple only by writing syntax rule, you can realize the achievable function of JavaScript code in the prior art, improve development efficiency, shorten the development cycle.

Description

A kind of source code conversion method, device and equipment
Technical field
This application involves a kind of field of computer technology more particularly to source code conversion method, device and equipment.
Background technology
A kind of literal translation formula scripts of JavaScript, are a kind of regime type, weak type, the language based on prototype, interior Put support type.Its interpreter is referred to as JavaScript engine, is a part for browser, is widely used in the foot of client This language is to be used on HTML (application under standard generalized markup language) webpage earliest, for increasing to html web page Add dynamic function..
In the prior art, it is to need to use a large amount of JavaScript source code that front end developer, which carries out development, Miscellaneous dynamic function is added for webpage, provides the result of browse of more smooth beauty to the user.
However, front end developer usually requires to describe page layout structure by html document, then pass through JavaScript code calls DOM API (Document Object Model Application Programming Interface) or the API of theassistant base (Application Programming Interface) operates change HTML structure, This realization process easily causes code and mixes and cause to be difficult to safeguard extension.
Invention content
This specification embodiment provides a kind of source code conversion method, device and equipment, to solve to develop in the prior art When personnel realize function using JavaScript source code, working efficiency is relatively low caused by syntax rule is complex asks Topic.
A kind of source code conversion method that this specification embodiment provides, the method includes:
First abstract syntax tree is constructed according to JSX source codes character string;
The tree construction and nodal community of the first abstract syntax tree are reconstructed, obtains the second abstract syntax tree;
Second abstract syntax tree is resolved into JavaScript source code character string.
Based on similary thought, a kind of source code conversion equipment that this specification embodiment also provides, described device includes:
Constructing module, for constructing the first abstract syntax tree according to JSX source codes character string;
Reconstructed module for reconstructing the tree construction and nodal community of the first abstract syntax tree, obtains the second abstract syntax tree;
Parsing module, for second abstract syntax tree to be resolved to JavaScript source code character string.
In addition, a kind of source code conversion equipment that this specification embodiment also provides, including:
Memory, storage source code converter;
Communication interface receives the construction request of the first syntax tree;
Processor after communication interface receives the construction request of the first syntax tree, calls the source generation stored in memory Code conversion program, and perform:
First abstract syntax tree is constructed according to JSX source codes character string;
The tree construction and nodal community of the first abstract syntax tree are reconstructed, obtains the second abstract syntax tree;
Second abstract syntax tree is resolved into JavaScript source code character string.
Above-mentioned at least one technical solution that this specification embodiment uses can reach following advantageous effect:
This specification is converted to JavaScript source code character string by that will meet JSX source code character strings, realizes Conversion between different type source code;By the above method, developer can be only relatively simple by writing syntax rule JSX source codes, you can realize the achievable function of JavaScript source code in the prior art, avoid developer's work effect The problem of rate is relatively low, and then shorten the development cycle;At the same time.Leading portion developer without the complicated syntax rule of study, Completion development that can be rapidly and efficiently, reduces learning cost.
Description of the drawings
Attached drawing described herein is used for providing further understanding of the present application, forms the part of the application, this Shen Illustrative embodiments and their description please do not form the improper restriction to the application for explaining the application.In the accompanying drawings:
Fig. 1 is the source code transfer process schematic diagram that this specification embodiment provides;
Fig. 2 is the source code conversion method flow chart that this specification embodiment provides;
Fig. 3 is another source code conversion method flow chart that this specification embodiment provides;
Fig. 4 is another source code conversion method flow chart that this specification embodiment provides;
Fig. 5 is the source code conversion device structure schematic diagram that this specification embodiment provides.
Specific embodiment
Purpose, technical scheme and advantage to make the application are clearer, below in conjunction with the application specific embodiment and Technical scheme is clearly and completely described in corresponding attached drawing.Obviously, described embodiment is only the application one Section Example, instead of all the embodiments.Based on the embodiment in the application, those of ordinary skill in the art are not doing Go out all other embodiments obtained under the premise of creative work, shall fall in the protection scope of this application.
In one or more embodiments in the present specification, source code conversion method can be applied to JSX (JavaScript XML) source code character string is converted to the process of JavaScript source code.Specific transfer process such as Fig. 1 institutes Show, wherein, JSX source codes are for representing JSX source code character strings, and AST (abstractsyntax tree) is for expression first Abstract syntax tree, for representing the second abstract syntax tree, JavaScript source code is used to represent AST Transformed JavaScript source code character string.
Specifically, the JSX source codes character string can meet the code of JSX sources syntax rule, for performing In the process, JSX source code character strings are converted into JS sources (JavaScript) code character string.JSX syntax rules can be by opening Hair personnel preset, which, can be very big compared with the grammer of JS source codes to be easy to learn and simple for structure Reduction learning cost and development cost.
A kind of source code conversion method is provided in this specification embodiment, specific implementation procedure can be as shown in Fig. 2, specific packet Include following steps:
Step S201:First abstract syntax tree is constructed according to JSX source codes character string.
In the present embodiment, the source code conversion method can also be performed by client executing by server.Into one Step, the source code conversion method described in the present embodiment can edit the JSX code conversions completed according to front end developer For that can realize the JS codes of said function, front end developer can be edited to the JSX code conversions completed for that can realize The JS codes of said function, and then directly convert and perform, to realize interactive function needed for dynamic page.
Specifically, JSX syntax rules can be regarded as being bound to each other to form a kind of grammer by JavaScript and XML grammers Rule directly states interface assembly, and can be nested against one another between interface assembly using the mode of XML tag.It can manage It solving and defines the grammer with attribute tree construction (DOM structure) to be a kind of, its purpose is not meant to realize in browser or engine, But these labels are compiled into the JS codes of standard by various compilers.
AST in first abstract syntax tree, that is, frame diagram, be JSX code character strings abstract syntax structure it is tree-shaped The form of expression, which is used to clench the train of thought of program, so as to facilitate the follow-up link of compilation process (such as Code building) program is understood.Each node of first abstract syntax tree represents a kind of in JSX code character strings Structure, why say it is abstract, be because the first abstract syntax tree can't represent each details that true grammer occurs, than As said, nested parenthesis is implied in the structure of tree, and there is no presented in the form of node.
Specifically, in the construction process of the first abstract syntax tree, it is necessary first to each in JSX code character strings Character is split, and forms lexical unit independent one by one, and at the same time, traversal splits each lexical unit completed, And be added to one by one in each node in the first abstract syntax tree, obtain the first final abstract syntax tree.Wherein, syntactic units It is the minimum unit for being had practical significance in Transformational Grammar.
On the basis of above-described embodiment, morphological analysis can be carried out to splitting the lexical unit completed, lexical unit Three-dimensional combination is carried out, with the relationship between clearly multiple lexical units.Specifically, the process of semantic analysis is a traversal language again The process of method unit, but it is in comparison more complicated, and because during participle, each syntactic units independently tile, And in syntactic analysis, sentence and expression formula can mutually be included with tree-shaped structure.
Optionally, the lexical unit in first abstract syntax tree can be blank, number, annotation, identifier and Any one in operator.
Step S203:The tree construction and nodal community of the first abstract syntax tree are reconstructed, obtains the second abstract syntax tree.
In this implementation, developer can be with corresponding node in prespecified first abstract syntax tree and the second abstract syntax tree Between mapping relations, so as to according to the mapping relations reconstruct the first abstract syntax tree tree construction and nodal community.
Alternatively, the mapping relations can be pre-stored in mapping library by the present embodiment, so as to perform In the process by searching for being inserted into, move, replace or delete each node in the first abstract syntax tree in mapping library.
Wherein, the nodal community of each node can include splitting the lexical unit of completion in the above process.For example, morphology Unit includes various types of JSX labels, tag attributes and label sub-element.The lexical unit of different type content can correspond to Sub-rule in field Substitution Rules, and then lexical unit will be replaced according to corresponding field replacement sub-rule.
It, can be to the progress time of the first abstract syntax tree during the first abstract syntax tree is reconstructed in the present embodiment It is performed during going through, until completing to traverse to all nodes, the modification operation of each nodal community also terminates, and then obtain therewith Second abstract syntax tree.Wherein, the second abstract syntax tree is used to be resolved to JavaScript source code character string.
Step S205:Second abstract syntax tree is resolved into JavaScript source code character string.
Specifically, parsing the second abstract syntax tree during, can with the second abstract syntax tree of recursive traversal, and according to Relationship and JavaScript sources syntax rule in second abstract syntax tree between each node reconfigure JavaScript sources Code character string.
Another source code conversion method is provided in this specification embodiment on the basis of above-described embodiment, such as Fig. 3 institutes Show, specifically include following steps:
Step S300:JSX source code character strings are screened from source code fragment.
In source code conversion method described in this implementation, the JSX source code portions in code segment can be automatically converted to JS source codes.Wherein, can be the source code composition of different programming languages in source code fragment.
Narration, source code conversion equipment are unfolded so that the code segment is the html webpage for including JSX source code portions as an example First the source code in html webpage can be scanned and recognized, when finding the peculiar label of JSX source code character strings, then by the spy When having code section screening (or interception comes out) in the leader label of label and tail tag label, as the JSX source codes this implementation Suo Shu Character string.The advantages of this arrangement are as follows developer can will include various types of code blocks as input, source code turns The JSX source code portions for including code segment for changing method intelligence and automation are converted to JS source codes, and improving code can tie up Shield property lowers development cost.
Step S302:First abstract syntax tree is constructed according to JSX source codes character string.
Step S304:Traverse first abstract syntax tree.
Specifically, the traversal order of first abstract syntax tree include but not limited to preorder traversal, postorder traversal and in Sequence traverses.
Step S306:It changes the tree construction and nodal community of first abstract syntax tree successively according to traversal order, obtains To the second abstract syntax tree;Wherein, the modification operation includes insertion, mobile, replacement or delete operation.
In the present embodiment, while constructing the process of the field value of each node in the first abstract syntax tree, it can also verify The correctness of syntactic units, and then accurately analyze and carry out the adjustment of code structure.
Step S308:Second abstract syntax tree is resolved into JavaScript code character string.
In addition, another source code conversion method is provided in this specification embodiment on the basis of above-described embodiment, such as Shown in Fig. 4, specifically include:
Step S401:It encapsulates in tree node modification algorithm to preset interface.
Wherein, it can be pre- that the tree node modification algorithm, which is used to implement modification tree construction and nodal community, preset interface, First develop the one or more interface objects finished, in the present embodiment, it is preset interface that tree node can be changed to algorithm packaging Function, the advantages of this arrangement are as follows improve code maintainability, lower development cost.
Step S403:First abstract syntax tree is constructed according to JSX source codes character string;
Step S405:For any one node in the first abstract syntax tree, called using nodal community as call parameters Preset interface obtains nodal community replacement values.
It, can be by node category when the nodal community of node each in the first abstract syntax tree is replaced in the present embodiment Property is input to corresponding function in preset interface, and using the output of called function as node as call parameters Attribute replacement values.
It is input in the function of preset interface specifically, same nodal community can be divided into multiple call parameters, example Such as, the preset interface can include A.createElement API, can be by tag attributes and mark that nodal community includes Bamboo slips used for divination or drawing lots element is input to createElement API as call parameters, and then obtains nodal community replacement values.
Step S407:The nodal community is replaced using the nodal community replacement values.
Step S409:The call operation for performing preset interface is returned to, until completing the reconstructed operation of the first abstract syntax tree.
In the present embodiment, for each node in the first abstract syntax tree, it is required for calling preset interface at least once Nodal community replacement values are obtained, until completing the replacement operation of the nodal community of whole nodes.
Step S411:Second abstract syntax tree is resolved into JavaScript source code character string.
Several embodiments of source code conversion method provided above for the application, based on same thinking, the application is also The embodiment of source code conversion equipment is provided, as shown in figure 5, this specification embodiment also provides a kind of source code converting means It puts, described device includes:
Constructing module, for constructing the first abstract syntax tree according to JSX source codes character string;
Reconstructed module for reconstructing the tree construction and nodal community of the first abstract syntax tree, obtains the second abstract syntax tree;
Parsing module, for second abstract syntax tree to be resolved to JavaScript source code character string.
On the basis of above-described embodiment, the reconstructed module, it may also be used for traversal first abstract syntax tree;According to Traversal order changes the tree construction and nodal community of first abstract syntax tree successively, obtains the second abstract syntax tree;Wherein, The modification operation includes insertion, mobile, replacement or delete operation.
On the basis of above-described embodiment, the source code conversion equipment further includes package module, is repaiied for encapsulating node Change in algorithm to preset interface;Reconstructed module can be additionally used in, for any one node in the first abstract syntax tree, with node category Property calls preset interface, obtains nodal community replacement values as call parameters;Using described in nodal community replacement values replacement Nodal community;The call operation for performing preset interface is returned to, until completing the reconstructed operation of the first abstract syntax tree.
On the basis of above-described embodiment, source code conversion equipment further includes screening module, for being sieved from source code fragment Select JSX source code character strings.
On the basis of above-described embodiment, the traversal order of first abstract syntax tree includes but not limited to first sequence time It goes through, postorder traversal and inorder traversal.
In addition, this specification embodiment is also providing a kind of source code conversion equipment, including:
Memory, storage source code converter;
Communication interface receives the construction request of the first syntax tree;
Processor after communication interface receives the construction request of the first syntax tree, calls the source generation stored in memory Code conversion program, and perform:
First abstract syntax tree is constructed according to JSX source codes character string;
The tree construction and nodal community of the first abstract syntax tree are reconstructed, obtains the second abstract syntax tree;
Second abstract syntax tree is resolved into JavaScript source code character string.
Each embodiment in this specification is described by the way of progressive, identical similar portion between each embodiment Point just to refer each other, and the highlights of each of the examples are difference from other examples.Especially for device, For equipment and medium class embodiment, since it is substantially similar to embodiment of the method, so description is fairly simple, related part Illustrate referring to the part of embodiment of the method, just no longer repeat one by one here.
It is above-mentioned that this specification specific embodiment is described.Other embodiments are in the scope of the appended claims It is interior.In some cases, the action recorded in detail in the claims or step or module can be according to different from embodiments Sequence performs and still can realize desired result.In addition, the process described in the accompanying drawings not necessarily requires what is shown Particular order or consecutive order could realize desired result.In some embodiments, multitasking and parallel processing It is also possible or it may be advantageous.
In the 1990s, the improvement of a technology can be distinguished clearly be on hardware improvement (for example, Improvement to circuit structures such as diode, transistor, switches) or software on improvement (improvement for method flow).So And with the development of technology, the improvement of current many method flows can be considered as directly improving for hardware circuit. Designer nearly all obtains corresponding hardware circuit by the way that improved method flow is programmed into hardware circuit.Cause This, it cannot be said that the improvement of a method flow cannot be realized with hardware entities module.For example, programmable logic device (Programmable Logic Device, PLD) (such as field programmable gate array (Field Programmable Gate Array, FPGA)) it is exactly such a integrated circuit, logic function determines device programming by user.By designer Voluntarily programming a digital display circuit " integrated " on a piece of PLD, designs and make without asking chip maker Dedicated IC chip.Moreover, nowadays, substitution manually makes IC chip, this programming is also used instead mostly " patrols Volume compiler (logic compiler) " software realizes that software compiler used is similar when it writes with program development, And the source code before compiling also write by handy specific programming language, this is referred to as hardware description language (Hardware Description Language, HDL), and HDL is also not only a kind of, but there are many kind, such as ABEL (Advanced Boolean Expression Language)、AHDL(Altera Hardware Description Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL (Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby Hardware Description Language) etc., VHDL (Very-High-Speed are most generally used at present Integrated Circuit Hardware Description Language) and Verilog.Those skilled in the art also should This understands, it is only necessary to method flow slightly programming in logic and is programmed into integrated circuit with above-mentioned several hardware description languages, The hardware circuit for realizing the logical method flow can be readily available.
Controller can be implemented in any suitable manner, for example, controller can take such as microprocessor or processing The computer of computer readable program code (such as software or firmware) that device and storage can be performed by (micro-) processor can Read medium, logic gate, switch, application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), the form of programmable logic controller (PLC) and embedded microcontroller, the example of controller include but not limited to following microcontroller Device:ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, are deposited Memory controller is also implemented as a part for the control logic of memory.It is also known in the art that in addition to Pure computer readable program code mode is realized other than controller, can be made completely by the way that method and step is carried out programming in logic Controller is obtained in the form of logic gate, switch, application-specific integrated circuit, programmable logic controller (PLC) and embedded microcontroller etc. to come in fact Existing identical function.Therefore this controller is considered a kind of hardware component, and various to being used to implement for including in it The device of function can also be considered as the structure in hardware component.Or even, the device for being used to implement various functions can be regarded For either the software module of implementation method can be the structure in hardware component again.
System, device, module or the unit that above-described embodiment illustrates can specifically realize by computer chip or entity, Or it is realized by having the function of certain product.A kind of typical realization equipment is computer.Specifically, computer for example may be used Think personal computer, laptop computer, cellular phone, camera phone, smart phone, personal digital assistant, media play It is any in device, navigation equipment, electronic mail equipment, game console, tablet computer, wearable device or these equipment The combination of equipment.
For convenience of description, it is divided into various units during description apparatus above with function to describe respectively.Certainly, implementing this The function of each unit is realized can in the same or multiple software and or hardware during application.
It should be understood by those skilled in the art that, the embodiment of the present invention can be provided as method, system or computer program Product.Therefore, the reality in terms of complete hardware embodiment, complete software embodiment or combination software and hardware can be used in the present invention Apply the form of example.Moreover, the computer for wherein including computer usable program code in one or more can be used in the present invention The computer program production that usable storage medium is implemented on (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) The form of product.
The present invention be with reference to according to the method for the embodiment of the present invention, the flow of equipment (system) and computer program product Figure and/or block diagram describe.It should be understood that it can be realized by computer program instructions every first-class in flowchart and/or the block diagram The combination of flow and/or box in journey and/or box and flowchart and/or the block diagram.These computer programs can be provided The processor of all-purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices is instructed to produce A raw machine so that the instruction performed by computer or the processor of other programmable data processing devices is generated for real The device of function specified in present one flow of flow chart or one box of multiple flows and/or block diagram or multiple boxes.
These computer program instructions, which may also be stored in, can guide computer or other programmable data processing devices with spy Determine in the computer-readable memory that mode works so that the instruction generation being stored in the computer-readable memory includes referring to Enable the manufacture of device, the command device realize in one flow of flow chart or multiple flows and/or one box of block diagram or The function of being specified in multiple boxes.
These computer program instructions can be also loaded into computer or other programmable data processing devices so that counted Series of operation steps are performed on calculation machine or other programmable devices to generate computer implemented processing, so as in computer or The instruction offer performed on other programmable devices is used to implement in one flow of flow chart or multiple flows and/or block diagram one The step of function of being specified in a box or multiple boxes.
In a typical configuration, computing device includes one or more processors (CPU), input/output interface, net Network interface and memory.
Memory may include computer-readable medium in volatile memory, random access memory (RAM) and/or The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method Or technology come realize information store.Information can be computer-readable instruction, data structure, the module of program or other data. The example of the storage medium of computer includes, but are not limited to phase transition internal memory (PRAM), static RAM (SRAM), moves State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable Programmable read only memory (EEPROM), fast flash memory bank or other memory techniques, CD-ROM read-only memory (CD-ROM), Digital versatile disc (DVD) or other optical storages, magnetic tape cassette, the storage of tape magnetic rigid disk or other magnetic storage apparatus Or any other non-transmission medium, available for storing the information that can be accessed by a computing device.It defines, calculates according to herein Machine readable medium does not include temporary computer readable media (transitory media), the data letter number and carrier wave of such as modulation.
It should also be noted that, term " comprising ", "comprising" or its any other variant are intended to nonexcludability Comprising so that process, method, commodity or equipment including a series of elements are not only including those elements, but also wrap Include other elements that are not explicitly listed or further include for this process, method, commodity or equipment it is intrinsic will Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that wanted including described Also there are other identical elements in the process of element, method, commodity or equipment.
It will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer program product. Therefore, complete hardware embodiment, complete software embodiment or the embodiment in terms of combining software and hardware can be used in the application Form.It is deposited moreover, the application can be used to can be used in one or more computers for wherein including computer usable program code The shape of computer program product that storage media is implemented on (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) Formula.
The application can be described in the general context of computer executable instructions, such as program Module.Usually, program module includes performing particular transaction or realizes routine, program, object, the group of particular abstract data type Part, data structure etc..The application can also be put into practice in a distributed computing environment, in these distributed computing environment, by Affairs are performed and connected remote processing devices by communication network.In a distributed computing environment, program module can be with In the local and remote computer storage media including storage device.
Each embodiment in this specification is described by the way of progressive, identical similar portion between each embodiment Point just to refer each other, and the highlights of each of the examples are difference from other examples.Especially for system reality For applying example, since it is substantially similar to embodiment of the method, so description is fairly simple, related part is referring to embodiment of the method Part explanation.
The foregoing is merely embodiments herein, are not limited to the application.For those skilled in the art For, the application can have various modifications and variations.All any modifications made within spirit herein and principle are equal Replace, improve etc., it should be included among the interest field of the application.

Claims (11)

1. a kind of source code conversion method, including:
First abstract syntax tree is constructed according to JSX source codes character string;
The tree construction and nodal community of the first abstract syntax tree are reconstructed, obtains the second abstract syntax tree;
Second abstract syntax tree is resolved into JavaScript source code character string.
2. the method as described in claim 1 reconstructs the tree construction and nodal community of the first abstract syntax tree, it is abstract to obtain second Syntax tree specifically includes:
Traverse first abstract syntax tree;
It changes the tree construction and nodal community of first abstract syntax tree successively according to traversal order, obtains the second abstract syntax Tree;Wherein, the modification operation includes insertion, mobile, replacement or delete operation.
3. the method as described in claim 1, before constructing the first abstract syntax tree according to JSX source codes character string, including:
Encapsulation is changed with tree node in algorithm to preset interface;
The tree construction and nodal community of the first abstract syntax tree are reconstructed, obtains the second abstract syntax tree, including:
For any one node in the first abstract syntax tree, preset interface is called using nodal community as call parameters, is obtained Nodal community replacement values;
The nodal community is replaced using the nodal community replacement values;
The call operation for performing preset interface is returned to, until completing the reconstructed operation of the first abstract syntax tree.
4. the method as described in claim 1 before constructing the first abstract syntax tree according to JSX source codes character string, further includes:
JSX source code character strings are screened from source code fragment.
5. method as claimed in claim 2, the traversal order of first abstract syntax tree include but not limited to preorder traversal, Postorder traversal and inorder traversal.
6. a kind of source code conversion equipment, including:
Constructing module, for constructing the first abstract syntax tree according to JSX source codes character string;
Reconstructed module for reconstructing the tree construction and nodal community of the first abstract syntax tree, obtains the second abstract syntax tree;
Parsing module, for second abstract syntax tree to be resolved to JavaScript source code character string.
7. device as claimed in claim 6, the reconstructed module, it may also be used for traversal first abstract syntax tree;According to Traversal order changes the tree construction and nodal community of first abstract syntax tree successively, obtains the second abstract syntax tree;Wherein, The modification operation includes insertion, mobile, replacement or delete operation.
8. device as claimed in claim 6, further includes package module, algorithm is changed to preset interface for encapsulating tree node In;
Reconstructed module can be additionally used in, for any one node in the first abstract syntax tree, using nodal community as call parameters, Preset interface is called, obtains nodal community replacement values;The nodal community is replaced using the nodal community replacement values;Return is held The call operation of the preset interface of row, until completing the reconstructed operation of the first abstract syntax tree.
9. device as claimed in claim 6, further includes screening module, for screening JSX source code characters from source code fragment String.
10. device as claimed in claim 7, the traversal order of first abstract syntax tree includes but not limited to first sequence time It goes through, postorder traversal and inorder traversal.
11. a kind of source code conversion equipment, including:
Memory, storage source code converter;
Communication interface receives the construction request of the first syntax tree;
Processor after communication interface receives the construction request of the first syntax tree, calls the source code stored in memory to turn Program is changed, and is performed:
First abstract syntax tree is constructed according to JSX source codes character string;
The tree construction and nodal community of the first abstract syntax tree are reconstructed, obtains the second abstract syntax tree;
Second abstract syntax tree is resolved into JavaScript source code character string.
CN201810040092.4A 2018-01-16 2018-01-16 A kind of source code conversion method, device and equipment Pending CN108170435A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810040092.4A CN108170435A (en) 2018-01-16 2018-01-16 A kind of source code conversion method, device and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810040092.4A CN108170435A (en) 2018-01-16 2018-01-16 A kind of source code conversion method, device and equipment

Publications (1)

Publication Number Publication Date
CN108170435A true CN108170435A (en) 2018-06-15

Family

ID=62514881

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810040092.4A Pending CN108170435A (en) 2018-01-16 2018-01-16 A kind of source code conversion method, device and equipment

Country Status (1)

Country Link
CN (1) CN108170435A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109375922A (en) * 2018-09-26 2019-02-22 深圳壹账通智能科技有限公司 A kind of automatic generation method and terminal device of interface document
CN109918073A (en) * 2019-01-29 2019-06-21 维沃移动通信有限公司 A kind of generation method of sound code file, device and terminal
CN110471666A (en) * 2019-07-18 2019-11-19 五八有限公司 Code automatic switching method and device, code converter and medium
CN110704053A (en) * 2019-09-03 2020-01-17 五八有限公司 Method and device for processing style information
CN111045678A (en) * 2019-11-06 2020-04-21 北京奇艺世纪科技有限公司 Method, device and equipment for executing dynamic code on page and storage medium
CN111209004A (en) * 2019-12-30 2020-05-29 北京健康之家科技有限公司 Code conversion method and device
CN112328257A (en) * 2020-11-24 2021-02-05 中国工商银行股份有限公司 Code conversion method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100211572A1 (en) * 2009-02-13 2010-08-19 International Business Machines Corporation Indexing and searching json objects
CN101937388A (en) * 2009-12-17 2011-01-05 北京测腾信息技术有限公司 High-extensibility and high-maintainability source code defect detection method and device
CN107423106A (en) * 2017-07-07 2017-12-01 北京小米移动软件有限公司 The method and apparatus for supporting more frame grammars

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100211572A1 (en) * 2009-02-13 2010-08-19 International Business Machines Corporation Indexing and searching json objects
CN101937388A (en) * 2009-12-17 2011-01-05 北京测腾信息技术有限公司 High-extensibility and high-maintainability source code defect detection method and device
CN107423106A (en) * 2017-07-07 2017-12-01 北京小米移动软件有限公司 The method and apparatus for supporting more frame grammars

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
DEAR_MR: "AST 抽象语法树学习", 《HTTPS://BLOG.CSDN.NET/ DEAR_MR /ARTICLE/DETAILS/72587908》 *

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109375922A (en) * 2018-09-26 2019-02-22 深圳壹账通智能科技有限公司 A kind of automatic generation method and terminal device of interface document
CN109918073A (en) * 2019-01-29 2019-06-21 维沃移动通信有限公司 A kind of generation method of sound code file, device and terminal
CN110471666A (en) * 2019-07-18 2019-11-19 五八有限公司 Code automatic switching method and device, code converter and medium
CN110704053A (en) * 2019-09-03 2020-01-17 五八有限公司 Method and device for processing style information
CN111045678A (en) * 2019-11-06 2020-04-21 北京奇艺世纪科技有限公司 Method, device and equipment for executing dynamic code on page and storage medium
CN111209004A (en) * 2019-12-30 2020-05-29 北京健康之家科技有限公司 Code conversion method and device
CN111209004B (en) * 2019-12-30 2023-09-01 北京水滴科技集团有限公司 Code conversion method and device
CN112328257A (en) * 2020-11-24 2021-02-05 中国工商银行股份有限公司 Code conversion method and device

Similar Documents

Publication Publication Date Title
CN108170435A (en) A kind of source code conversion method, device and equipment
CN106371829B (en) Template framework design method and system based on modularization idea
US8286132B2 (en) Comparing and merging structured documents syntactically and semantically
Beazley Automated scientific software scripting with SWIG
US8397157B2 (en) Context-free grammar
CN110427215A (en) A kind of program version mRNA differential display mRNA method and device applied to front end exploitation
CN111290778B (en) AI model packaging method, platform and electronic equipment
CN106648662B (en) Report generation device and method based on project cost calculation description language BCL
CN107506181A (en) Business processing, data processing method, device and electronic equipment
CN105446725B (en) Method and system for Mode-driven architecture
CN110442330A (en) List element conversion method, device, electronic equipment and storage medium
CN111045678A (en) Method, device and equipment for executing dynamic code on page and storage medium
CN107622080A (en) A kind of data processing method and equipment
CN106886398A (en) The extracting method and equipment of a kind of CSS
CN111831384A (en) Language switching method and device, equipment and storage medium
CN114153459A (en) Interface document generation method and device
CN112463135A (en) Code generation method, code generator, electronic device, and storage medium
CN107038058A (en) A kind of code process method and device
CN112631604B (en) Front-end frame implementation method and device
CN107391529A (en) A kind of method and device for realizing Object Relation Mapping ORM
CN104462157B (en) A kind of method and device of text data secondary structure
CN101162480A (en) Schedule drawing automatic recognition and comprehend method
Guillon et al. Two-Way Automata and One-Tape Machines: Read Only Versus Linear Time
US8997035B2 (en) Extensible template-based code generator builder
CN107506299A (en) A kind of code analysis methods and terminal device

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20180615

RJ01 Rejection of invention patent application after publication