CN115562649A - Computer mixed program language source code auxiliary compiling method and system - Google Patents

Computer mixed program language source code auxiliary compiling method and system Download PDF

Info

Publication number
CN115562649A
CN115562649A CN202211328152.5A CN202211328152A CN115562649A CN 115562649 A CN115562649 A CN 115562649A CN 202211328152 A CN202211328152 A CN 202211328152A CN 115562649 A CN115562649 A CN 115562649A
Authority
CN
China
Prior art keywords
abstract syntax
code
syntax tree
character string
program
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.)
Granted
Application number
CN202211328152.5A
Other languages
Chinese (zh)
Other versions
CN115562649B (en
Inventor
高斌
孙小鹏
张小红
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xinjiang Pinxuan Biotechnology Co ltd
Original Assignee
Xinjiang Pinxuan Biotechnology 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 Xinjiang Pinxuan Biotechnology Co ltd filed Critical Xinjiang Pinxuan Biotechnology Co ltd
Priority to CN202211328152.5A priority Critical patent/CN115562649B/en
Publication of CN115562649A publication Critical patent/CN115562649A/en
Application granted granted Critical
Publication of CN115562649B publication Critical patent/CN115562649B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/33Intelligent editors
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The invention provides a computer mixed program language source code auxiliary compiling method and system, which comprises the following steps of: the method comprises the steps of obtaining a source code file, determining all program languages included in the source code file, establishing an abstract syntax tree corresponding to the program languages in the source code file in a recursive mode, and performing automatic completion and code skipping of mixed language codes according to the abstract syntax tree to assist source code writing of the mixed languages and improve development efficiency.

Description

Computer mixed program language source code auxiliary compiling method and system
Technical Field
The invention relates to the technical field of computer programming languages, in particular to a computer mixed program language source code auxiliary compiling method and system.
Background
The computer program language source code auxiliary editing can greatly improve the programming efficiency, and various manufacturers invest a lot of efforts to carry out related research and development.
Automatic code completion is one of means for assisting editing of source codes, and in the automatic code completion, a method having a mapping relation with codes to be completed and attribute names are stored in a dictionary, after part of codes are to be input, a list to be selected is formed according to the dictionary, and therefore a developer can select related codes from the list to be selected to complete quick input of the codes. Automatic code completion using AST is also a widely used method that obtains meta information of an inputted code, such as a parameter name, a parameter type, and the like, by expressing the inputted code as AST, and when it is necessary to input the same or related meta information again, obtains the inputted meta information by parsing AST, thereby automatically completing the filling according to the meta information. In addition to the above-mentioned approaches, with the development of machine learning technology, a code to be complemented is analyzed according to the input code information by a machine learning method, so as to realize code input. For example, patent CN113867710A published by hua corporation discloses a probability prediction model in automatic completion using codes, and determines the result of completing codes according to the inputted prefix words and the probabilities calculated by various models. Meanwhile, the patent US20210034335A1 of microsoft corporation also discloses an automatic Code completion method suitable for various different programming languages, which utilizes a neural network to predict the most probable Code candidate item, thereby realizing the function of auxiliary Code input, and the method mentioned in the patent is also applied to the development environments Visual Studio and Visual Studio Code developed by microsoft corporation. In Visual Studio Code, microsoft develops this as a separate plug-in IntelliCode, which developers can download in the plug-in library of Visual Studio Code to use with the Code.
Besides automatic completion of the code, code skipping is also a means for writing auxiliary code, and due to the limitation of the size of an editor, a developer cannot easily see all the codes at the same time, and when a certain function needs to be used, the developer needs to skip to a place where the function code is displayed to view the code to acquire information including a signature and the like, especially for a dynamic program language.
Although the automatic code completion and code skipping can assist developers in software development, the technical means are all completed aiming at a single program language, and for different program languages involved in the same source code file, the automatic code completion and code skipping aiming at different program languages cannot be realized at the same time. For example, the code below shows one way to call JavaScript code in a Python source file:
from py_mini_racer import py_mini_racer.MiniRacer()as context
context.eval("""function f1(x){return x*x};function f2(x){return x+x};functi on funcAdder(fun1,fun2{return fun1+fun2;}""")
context.call("funcAdder(f1(5),f2(10))")
the JavaScript code to be executed by the code is transmitted into a py _ min i _ concentrator module of the Python in a character string mode, and the py _ min _ concentrator recalls the runtime of the corresponding JavaScript to execute the transmitted JavaScript code. In the execution process of the code, when information such as variables, function names and the like in python is input, the prior art can realize the functions of automatic code completion and code jump, for example, when a context is input after a from py _ mini _ source image py _ mini _ source.MiniRacer () as context is input in a vscode, the context can be completed automatically, when "-" is input after the context, different methods including eval in the context can be jumped out for a developer to select, the context is clicked by a mouse, and the code can be jumped to a library for defining the context. When a js code included in context & eval () is input, however, the automatic completion of code and the code jump function are disabled, and we cannot realize completion and jump of the js code therein. The above situation is only a simplest situation, one programming language can call not only another programming language, but also multiple programming languages, and even multiple loop nesting can be formed, but the prior art has no solution to this problem.
Disclosure of Invention
In view of the problems in the prior art, the invention provides a computer mixed program language source code auxiliary writing method and a computer mixed program language source code auxiliary writing system, which are used for improving the programming efficiency.
On one hand, the invention provides a computer mixed program language source code auxiliary writing method, which is characterized by comprising the following steps:
creating a single source code file, and determining a main program language corresponding to the source code file according to a file name suffix of the source code file;
acquiring source code which is input by a user, wherein the source code exists in the single source code file and at least comprises two different types of program languages;
generating a corresponding main abstract syntax tree according to the source code input by the user and the main program language;
determining a node in a main abstract syntax tree where a user cursor is located according to the main abstract syntax tree;
judging whether the nodes in the main abstract syntax tree comprise data of character string types or not;
if the nodes in the main abstract syntax tree do not comprise data of character string types, automatic completion and code skip are carried out according to the main abstract syntax tree;
if the nodes in the main abstract syntax tree comprise data of a character string type, judging whether the data of the character string type is a program;
if the data of the character string type is not a program, not performing automatic code completion and code skipping;
if the data of the character string type is a program, determining a first secondary program language corresponding to the program;
generating a corresponding first sub abstract syntax tree according to the character string and a first sub program language;
determining a node in the first secondary abstract syntax tree where a user cursor is located according to the first secondary abstract syntax tree;
judging whether the nodes in the first secondary abstract syntax tree comprise data of character string types or not;
if the nodes in the first sub abstract syntax tree do not comprise data of character string types, automatic completion and code skip are carried out according to the first sub abstract syntax tree;
if the node in the first sub abstract syntax tree comprises data of a character string type, judging whether the data of the character string type is a program;
if the data of the character string type is not a program, not performing automatic code completion and code skipping;
if the data of the character string type is a program, determining a second subprogram language corresponding to the program;
generating a corresponding second auxiliary abstract syntax tree according to the character string and a second auxiliary program language;
and determining whether to perform automatic code completion and code skipping in the client according to the second abstract syntax tree.
And recursion is carried out on the steps so as to realize automatic code completion and code skip of any deep mixed programming language.
In a second aspect, the present invention provides a computer mixed program language source code auxiliary writing system, which is characterized by comprising:
the system comprises a client and a server, wherein the client and the server are connected through a network, and the network is a local area network, the Internet or other proprietary networks;
creating a single source code file at a client, the server being configured to detect real-time changes to the single source code file;
acquiring a source code which is input in a client by a user, wherein the source code exists in the single source code file, and the source code at least comprises two different types of program languages;
generating a corresponding main abstract syntax tree in a server according to a source code input by a user and the main program language;
determining a node in a main abstract syntax tree where a user cursor is located according to the main abstract syntax tree;
judging whether the nodes in the main abstract syntax tree comprise data of character string types or not;
if the nodes in the main abstract syntax tree do not comprise data of character string types, automatically completing codes and skipping the codes in the client according to the main abstract syntax tree;
if the nodes in the main abstract syntax tree comprise data of a character string type, judging whether the data of the character string type is a program;
if the data of the character string type is not a program, not performing automatic code completion and code skipping;
if the data of the character string type is a program, determining a first sub-program language corresponding to the program;
generating a corresponding first secondary abstract syntax tree in the server according to the character string and the first secondary programming language;
determining a node in the first secondary abstract syntax tree where a user cursor is located according to the first secondary abstract syntax tree;
judging whether the nodes in the first secondary abstract syntax tree comprise data of character string types or not;
if the nodes in the first secondary abstract syntax tree do not comprise data of character string types, performing automatic completion and code skipping in the client according to the first secondary abstract syntax tree;
if the node in the first sub abstract syntax tree comprises data of a character string type, judging whether the data of the character string type is a program;
if the data of the character string type is not a program, not performing automatic code completion and code skipping;
if the data of the character string type is a program, determining a second subprogram language corresponding to the program;
generating a corresponding second secondary abstract syntax tree in the server according to the character string and a second secondary program language;
determining whether to perform automatic code completion and code skipping in the client according to the second abstract syntax tree;
and recursion of the steps is carried out to realize automatic code completion and code skip of any deep mixed programming language.
Drawings
FIG. 1 is a flow chart of a method according to the present invention;
FIG. 2 (a) is a schematic diagram of a Javascript code written in Python code without applying the method of the present invention;
FIG. 2 (b) is a schematic diagram of the Javascript code written in Python code when the method of the present invention is applied;
Detailed Description
The computer mixed program language source code auxiliary compiling method provided by the invention can realize the automatic completion and code skip functions of any deep mixed program language, and as shown in figure 1, the method can be divided into 4 steps:
step 1: acquiring a source code file;
step 2: determining a program language included in the source code file;
and step 3: recursively establishing an abstract syntax tree corresponding to a program language in the source code file;
and 4, step 4: and performing automatic code completion and code skipping according to the abstract syntax tree.
Further explanation is given below by taking a source file including Python and JavaScript programs as an example.
FIG. 2 (a) shows that before the present invention is applied, the Javascript code which is imported in the form of character string is inputted into the Python code, when the Javascript is inputted, because it is treated as character string, it will not be done with code completion and automatic jump, for example, when inputting the retur in the fourth line code, the option of code automatic completion for selection does not appear;
py, a single source code file is created, as shown in fig. 2 (b).
Determining that the main program language corresponding to the source code file is a Python program according to the filename suffix py of the source code file;
obtaining source code being input by a user, the source code existing in the single source code file, the source code including at least two different types of program languages, such as Python and Javascript included in fig. 2 (b);
generating a corresponding main Abstract Syntax Tree (AST) corresponding to Python according to a source code input by a user and the main program language (Python);
determining, from the main abstract syntax tree, a node in the main abstract syntax tree where a user cursor is located, the cursor now being located after a retur in the fourth line of code in fig. 2 (b);
judging whether the nodes in the main abstract syntax tree comprise data of character string types or not;
if the nodes in the main abstract syntax tree do not comprise data of character string types, performing automatic completion and code skip according to the main abstract syntax tree;
if the node in the main abstract syntax tree comprises data of a character string type, judging whether the data of the character string type is a program or not, and judging that the data of the character string type is a Javascript program;
if the data of the character string type is not a program, automatic code completion and code skipping are not carried out;
if the data of the character string type is a program, determining a first sub program language corresponding to the program, wherein the first sub program language is Javascript according to the information given in the step (b) of FIG. 2;
generating a corresponding first auxiliary abstract syntax tree, namely AST corresponding to Javascript, according to the character string and a first auxiliary program language;
determining a node in the first secondary abstract syntax tree where a user cursor is located according to the first secondary abstract syntax tree;
judging whether the nodes in the first secondary abstract syntax tree comprise data of character string types or not;
if the node in the first sub-abstract syntax tree does not include data of a character string type, performing automatic completion and code skipping according to the first sub-abstract syntax tree, and in fig. 2 (b), according to the invention, giving an option of automatic completion of a code given according to "return", for example, a return, readableStreamDefaultController, and the like, corresponding to Javascript;
if the node in the first secondary abstract syntax tree comprises data of a character string type, judging whether the data of the character string type is a program;
if the data of the character string type is not a program, automatic code completion and code skipping are not carried out;
if the data of the character string type is a program, determining a second subprogram language corresponding to the program;
generating a corresponding second secondary abstract syntax tree in the server according to the character string and a second secondary program language;
determining whether to perform automatic code completion and code skipping in the client according to the second abstract syntax tree;
and recursion of the steps is carried out to realize automatic code completion and code skip of any deep mixed programming language.
The invention realizes that when a plurality of different programming languages are positioned in the same source file, the automatic code completion and the code skipping can be simultaneously carried out on the plurality of different programming languages, and the development efficiency of developers can be improved to a great extent. It is to be noted that, those skilled in the art will understand that all or part of the flow of the method implementing the above embodiments is accomplished by instructions issued by a computer, and the instructions may be stored in a readable storage medium of the computer, including a nonvolatile and/or volatile memory. Meanwhile, the above-described embodiment is only one way to complete the present application, and should not be construed as limiting the scope of protection. It should be noted that, for those skilled in the art, various changes and modifications can be made in the invention concept of the present application, and these changes and modifications are all within the scope of the present application. Therefore, the protection scope of the present patent application shall be subject to the claims.

Claims (5)

1. A computer mixed program language source code auxiliary writing method is characterized by comprising the following steps:
step 1: acquiring a source code file;
step 2: determining a program language included in the source code file;
and step 3: recursively establishing an abstract syntax tree corresponding to a program language in the source code file;
and 4, step 4: and performing automatic code completion and code skipping according to the abstract syntax tree.
2. The method of claim 1, wherein step 1 comprises:
creating a single source code file, and determining a main program language corresponding to the source code file according to a file name suffix of the source code file;
and acquiring the source code which is input by the user, wherein the source code exists in the single source code file, and the source code at least comprises two different types of program languages.
3. The method of claim 2, wherein step 2 comprises:
generating a corresponding main abstract syntax tree according to the source code input by the user and the main program language;
according to the main abstract syntax tree, automatically completing codes and skipping codes of the codes corresponding to the main program language;
and establishing one or more auxiliary abstract syntax trees according to different nodes of the main abstract syntax tree where the cursor is positioned, and performing automatic code completion and code skip on codes corresponding to the auxiliary program language according to the auxiliary abstract syntax trees.
4. The method of claim 3, wherein the creating one or more sub-abstract syntax trees according to the cursor located at different nodes of the main abstract syntax tree, and the performing automatic code completion and code jumping for the codes corresponding to the sub-program language according to the sub-abstract syntax trees specifically comprises:
determining a node in a main abstract syntax tree where a user cursor is located according to the main abstract syntax tree;
judging whether the nodes in the main abstract syntax tree comprise data of character string types or not;
if the nodes in the main abstract syntax tree do not comprise data of character string types, performing automatic completion and code skip according to the main abstract syntax tree;
if the nodes in the main abstract syntax tree comprise data of character string types, judging whether the data of the character string types are programs or not;
if the data of the character string type is not a program, not performing automatic code completion and code skipping;
if the data of the character string type is a program, determining a first secondary program language corresponding to the program;
generating a corresponding first sub abstract syntax tree according to the character string and a first sub program language;
determining a node in the first secondary abstract syntax tree where a user cursor is located according to the first secondary abstract syntax tree;
judging whether the nodes in the first secondary abstract syntax tree comprise data of character string types or not;
if the nodes in the first secondary abstract syntax tree do not comprise data of character string types, performing automatic completion and code skipping according to the first secondary abstract syntax tree;
if the node in the first secondary abstract syntax tree comprises data of a character string type, judging whether the data of the character string type is a program;
if the data of the character string type is not a program, automatic code completion and code skipping are not carried out;
if the data of the character string type is a program, determining a second subprogram language corresponding to the program;
generating a corresponding second sub abstract syntax tree according to the character string and a second sub program language;
and determining whether to perform automatic code completion and code skipping in the client according to the second abstract syntax tree.
And recursion of the steps is carried out to realize automatic code completion and code skip of any deep mixed programming language.
5. A computer mixed program language source code assisted writing system, characterized in that the system comprises a client and a server, the client and the server are connected through a network, the network is a local area network, the internet or other proprietary networks, and the system is used for executing the method of any one of claims 1 to 4.
CN202211328152.5A 2022-10-27 2022-10-27 Auxiliary writing method and system for source codes of computer mixed program language Active CN115562649B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211328152.5A CN115562649B (en) 2022-10-27 2022-10-27 Auxiliary writing method and system for source codes of computer mixed program language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211328152.5A CN115562649B (en) 2022-10-27 2022-10-27 Auxiliary writing method and system for source codes of computer mixed program language

Publications (2)

Publication Number Publication Date
CN115562649A true CN115562649A (en) 2023-01-03
CN115562649B CN115562649B (en) 2023-06-16

Family

ID=84768564

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211328152.5A Active CN115562649B (en) 2022-10-27 2022-10-27 Auxiliary writing method and system for source codes of computer mixed program language

Country Status (1)

Country Link
CN (1) CN115562649B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030028364A1 (en) * 2001-07-10 2003-02-06 Borland Software Corp. Development assistance for mixed-language sources
US20110167410A1 (en) * 2007-11-20 2011-07-07 National Ict Australia Limited Multi language software code analysis
US20140282373A1 (en) * 2013-03-15 2014-09-18 Trinity Millennium Group, Inc. Automated business rule harvesting with abstract syntax tree transformation
US20180129517A1 (en) * 2016-11-04 2018-05-10 International Business Machines Corporation Performance acceleration in mixed-language applications
US10656940B1 (en) * 2019-02-04 2020-05-19 Architecture Technology Corporation Systems, devices, and methods for source code generation from binary files
CN113110874A (en) * 2021-04-14 2021-07-13 北京沃东天骏信息技术有限公司 Method and device for generating code structure diagram
CN114585999A (en) * 2019-08-01 2022-06-03 微软技术许可有限责任公司 Multilingual code line completion system
CN114625844A (en) * 2022-05-16 2022-06-14 湖南汇视威智能科技有限公司 Code searching method, device and equipment
CN114675816A (en) * 2022-03-14 2022-06-28 麒麟软件有限公司 Code completion ordering method and system based on user behaviors

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030028364A1 (en) * 2001-07-10 2003-02-06 Borland Software Corp. Development assistance for mixed-language sources
US20110167410A1 (en) * 2007-11-20 2011-07-07 National Ict Australia Limited Multi language software code analysis
US20140282373A1 (en) * 2013-03-15 2014-09-18 Trinity Millennium Group, Inc. Automated business rule harvesting with abstract syntax tree transformation
US20180129517A1 (en) * 2016-11-04 2018-05-10 International Business Machines Corporation Performance acceleration in mixed-language applications
US10656940B1 (en) * 2019-02-04 2020-05-19 Architecture Technology Corporation Systems, devices, and methods for source code generation from binary files
CN114585999A (en) * 2019-08-01 2022-06-03 微软技术许可有限责任公司 Multilingual code line completion system
CN113110874A (en) * 2021-04-14 2021-07-13 北京沃东天骏信息技术有限公司 Method and device for generating code structure diagram
CN114675816A (en) * 2022-03-14 2022-06-28 麒麟软件有限公司 Code completion ordering method and system based on user behaviors
CN114625844A (en) * 2022-05-16 2022-06-14 湖南汇视威智能科技有限公司 Code searching method, device and equipment

Also Published As

Publication number Publication date
CN115562649B (en) 2023-06-16

Similar Documents

Publication Publication Date Title
US11442702B2 (en) Code completion
KR101098718B1 (en) System and method for creating, managing and using code segments
US9213541B2 (en) Creation, generation, distribution and application of self-contained modifications to source code
TWI493464B (en) System and method for late bound programmatic assistance
US8091071B2 (en) Method and system for template-based code generation
US11579856B2 (en) Multi-chip compatible compiling method and device
Wagner et al. Incremental analysis of real programming languages
CN115509514B (en) Front-end data simulation method, device, equipment and medium
US20040154009A1 (en) Structuring program code
CN113065322A (en) Code segment annotation generation method and system and readable storage medium
CN115756433A (en) Code platform migration method and device, electronic equipment and readable storage medium
Zhang et al. Automated extraction of grammar optimization rule configurations for metamodel-grammar co-evolution
CN113885844A (en) Business service arranging method and related device
CN115562649B (en) Auxiliary writing method and system for source codes of computer mixed program language
US11714609B2 (en) Automatic generation of source code implementing a regular expression
Izquierdo et al. Gra2MoL: A domain specific transformation language for bridging grammarware to modelware in software modernization
Dalibor et al. Mind the gap: lessons learned from translating grammars between MontiCore and Xtext
Polenov et al. Intellectualization of the models translation tools for distributed storage of models
CN114527989A (en) Code structure view analyzing and previewing method
CN110727428B (en) Method and device for converting service logic layer codes and electronic equipment
CN113918198A (en) Model-code synchronization method
Jakubovic et al. Ascending the Ladder to Self-Sustainability: Achieving Open Evolution in an Interactive Graphical System
CN113971028B (en) Data processing method, apparatus, device, storage medium and computer program product
Eskelinen Utilizing Code Generation in Single-Page Applications
Harmer et al. Transformations to Restructure and Re–engineer COBOL Programs

Legal Events

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