A language element analysis method, device, electronic device and storage medium

By adding line numbers to the source code, identifying and replacing preset paragraphs, processing preset symbols and implementing single-line processing, the problem of difficulty in extracting source code language elements in the prior art is solved, and a relatively accurate language element extraction is achieved.

CN114443128BActive Publication Date: 2025-04-25DOUYIN VISION CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011190547.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-30
Publication Date
2025-04-25
Estimated Expiration
2040-10-30

AI Technical Summary

Technical Problem

It is difficult for prior art to extract language elements accurately from source code.

Method used

By obtaining the source code file of the preset programming language, adding line numbers, identifying and replacing the preset paragraphs, identifying and processing preset symbols, the single-line processing of the source code is realized, thereby accurately extracting language elements.

Benefits of technology

It realizes the extraction of language elements from the source code more accurately, reduces the impact of preset paragraphs on analysis, and avoids the problem of the same language element being distributed in multiple lines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443128B_ABST
    Figure CN114443128B_ABST
Patent Text Reader

Abstract

The embodiments of the present disclosure disclose a method, device, electronic device and storage medium for analyzing language elements. The present disclosure obtains a source code file of a preset programming language, and adds a line number to each line of source code in the multiple lines of source code included in the source code file. The line number can be used as auxiliary information to better distinguish each line of source code. In addition, on this basis, the preset paragraphs in the multiple lines of source code are identified, and the preset paragraphs are replaced with a first preset identifier, thereby reducing the influence of the preset paragraphs on the analysis of language elements. Further, the preset symbols in the multiple lines of source code are identified, and part of the source code associated with the preset symbols is processed into a single line, so that the same language element can be distributed in the same line, avoiding the same language element being distributed in multiple lines and affecting the analysis of the language element. Furthermore, the language element is identified based on the multiple lines of source code after the single-line processing, thereby realizing a method that can more accurately extract language elements from the source code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a language element analysis method, device, electronic device and storage medium. Background Art

[0002] Computer programs in the prior art may be source codes written in a specific programming language, which need to go through stages such as preprocessing, compiling, linking, and running from source code to execution.

[0003] Programming languages ​​include many elements, for example, basic elements such as classes, variables, enumerations, functions, etc. The elements of a programming language can be referred to as language elements or morphemes.

[0004] The language elements in the prior art can have multiple applications, but it is relatively difficult to extract the language elements from the source code. Summary of the invention

[0005] In order to solve the above technical problems or at least partially solve the above technical problems, the embodiments of the present disclosure provide a language element analysis method, device, electronic device and storage medium to implement a method for extracting language elements from source code more accurately.

[0006] The present disclosure provides a method for analyzing language elements, including:

[0007] Obtaining a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0008] Adding a line number to each line of the source code;

[0009] Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier;

[0010] On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol;

[0011] Determine the language elements in the multiple lines of source code after the single-line processing.

[0012] The present disclosure also provides a language element analysis method, including:

[0013] Obtaining a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0014] Adding a line number to each line of the source code;

[0015] Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier;

[0016] On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol;

[0017] Determining annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations;

[0018] An interface element corresponding to the language element is displayed in the user interface.

[0019] The present disclosure also provides a language element analysis device, including:

[0020] An acquisition module, used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0021] A line number adding module, used for adding a line number to each line of the multiple lines of source code;

[0022] an identification module, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added;

[0023] A replacement module, used for replacing a preset paragraph in the plurality of lines of source code with a first preset identifier;

[0024] The recognition module is further used to: recognize the preset symbols in the multiple lines of source code on the basis that the replacement module replaces the preset paragraphs in the multiple lines of source code with the first preset identifier;

[0025] A processing module, used for processing a portion of source code associated with the preset symbol in the multiple source code lines into a single line;

[0026] A determination module is used to determine the language elements in the multiple lines of source code after the single-line processing.

[0027] The present disclosure also provides a language element analysis device, including:

[0028] An acquisition module, used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0029] A line number adding module, used for adding a line number to each line of the multiple lines of source code;

[0030] an identification module, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added;

[0031] A replacement module, used for replacing a preset paragraph in the plurality of lines of source code with a first preset identifier;

[0032] The recognition module is further used to: recognize the preset symbols in the multiple lines of source code on the basis that the replacement module replaces the preset paragraphs in the multiple lines of source code with the first preset identifier;

[0033] A processing module, used for processing a portion of source code associated with the preset symbol in the multiple source code lines into a single line;

[0034] A determination module, used for determining annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations;

[0035] The display module is used to display the interface elements corresponding to the language elements in the user interface.

[0036] The present disclosure also provides an electronic device, the electronic device comprising:

[0037] one or more processors;

[0038] A storage device for storing one or more programs;

[0039] When the one or more programs are executed by the one or more processors, the one or more processors implement the language element analysis method as described above.

[0040] The embodiment of the present disclosure further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the language element analysis method described above is implemented.

[0041] Compared with the prior art, the technical solution provided by the embodiment of the present disclosure has the following advantages: the language element analysis method provided by the embodiment of the present disclosure obtains a source code file of a preset programming language, and adds a line number to each line of source code in the multiple lines of source code included in the source code file. The line number can be used as auxiliary information to better distinguish each line of source code. In addition, on this basis, the preset paragraph in the multiple lines of source code is identified, and the preset paragraph is replaced with a first preset identifier. Since the preset paragraph may be relatively long, and the first preset identifier is relatively short, the influence of the preset paragraph on the language element analysis can be reduced by replacing the preset paragraph with the first preset identifier. Further, on the basis of replacing the preset paragraph in the multiple lines of source code with the first preset identifier, the preset symbol in the multiple lines of source code is identified, and the part of the source code associated with the preset symbol is processed into a single line, so that the same language element can be distributed in the same line, avoiding the same language element being distributed in multiple lines and affecting the analysis of the language element. Further, the language element is identified on the basis of the multiple lines of source code after the single line processing, thereby realizing a method for extracting language elements from the source code more accurately. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0043] Figure 1 is a flow chart of a language element analysis method in an embodiment of the present disclosure;

[0044] Figure 2 is a flowchart of another language element analysis method in an embodiment of the present disclosure;

[0045] Figure 3 A schematic diagram of an application scenario in an embodiment of the present disclosure;

[0046] Figure 4 is a schematic diagram of a user interface in an embodiment of the present disclosure;

[0047] Figure 5 is a flowchart of another language element analysis method in an embodiment of the present disclosure;

[0048] Figure 6 is a flowchart of another language element analysis method in an embodiment of the present disclosure;

[0049] Figure 7 is a structural schematic diagram of a language element analysis device in an embodiment of the present disclosure;

[0050] Figure 8 is a structural schematic diagram of another language element analysis device in an embodiment of the present disclosure;

[0051] Fig. 9 It is a structural schematic diagram of an electronic device in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0052] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0053] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.

[0054] The term "including" and its variations used herein are open inclusions, i.e., "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0055] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.

[0056] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".

[0057] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.

[0058] Figure 1This is a flow chart of a language element analysis method in an embodiment of the present disclosure. This embodiment is applicable to the case where language element analysis is performed in a client. The method can be executed by a language element analysis device. The device can be implemented in software and / or hardware. The device can be configured in an electronic device, such as a mobile terminal, specifically including a mobile phone, a computer or a tablet computer. Alternatively, this embodiment is applicable to the case where language element analysis is performed in a server. The method can be executed by a language element analysis device. The device can be implemented in software and / or hardware. The device can be configured in an electronic device, such as a server.

[0059] like Figure 1 As shown, the method may specifically include:

[0060] S101. Obtain a source code file of a preset programming language, wherein the source code file includes multiple lines of source code.

[0061] In the embodiment of the present disclosure, the preset programming language may be, for example, the C++ programming language. The language element analysis device may pre-store a plurality of source code files, each of which includes a plurality of lines of source code. Alternatively, the language element analysis device may obtain a plurality of source code files from other terminals or servers, each of which includes a plurality of lines of source code. Specifically, the language element analysis device may analyze the plurality of lines of source code in each source code file using the method described in the present embodiment, thereby determining the language elements in each source code file.

[0062] S102: Add a line number to each line of the multiple lines of source code.

[0063] For example, a line number is added to each line of source code, for example, the line number can be added at the beginning of each line of source code, or the line number can be added at the end of each line of source code. In addition, the present embodiment does not specifically limit the identifier of the line number.

[0064] It is understandable that in some other embodiments, it is not limited to adding line numbers in the source code file. For example, other information may be added. The other information may specifically include the processing time of the source code file, the module to which the source code file belongs, the file path of the source code file, and the message digest algorithm (Message-Digest Algorithm, MD5), the last modification time (LastModifyTime, LMT) and other information. Among them, if the last modification time has not changed, it means that the program source code has not changed. In this case, the source code file can be accelerated.

[0065] S103: Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier.

[0066] For example, the language element analysis device can identify a preset paragraph in multiple lines of source code with the line numbers added. Optionally, the preset paragraph includes at least one of the following: a long comment, a short comment, a string, a native string, and a character. Specifically, when the language element analysis device identifies a preset paragraph in multiple lines of source code, the preset paragraph can be replaced with a first preset identifier, for example, the first preset identifier can be recorded as a token.

[0067] Specifically, a long comment may be content identified by symbols such as " / ** / ". Specifically, a short comment may be content identified by symbols such as " / / ". A string may be, for example, a combination of letters, numbers, and other symbols. A native string may be, for example, a string with the letter R added before it. A character may be, for example, a letter, etc.

[0068] When the language element analysis device identifies a preset paragraph in the multi-line source code with the line number added, the preset paragraph in the multi-line source code can be replaced with a first preset identifier. For example, the language element analysis device can also replace the string ""Base / AlgorithmBuffer.h"" with a first preset identifier, such as [String-0]. After the above processing, the multi-line source code is equivalent to a file reorganization based on the initial one, and the line number may change during the file reorganization process. For example, lines 4 to 6 in the initial source code become one line, i.e., line 4, after processing.

[0069] It is understandable that the one-to-one correspondence between the replaced part and the replacement part in the source code can be recorded, and the processed source code can be restored to the source code in the original state according to the correspondence.

[0070] S104: on the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbols in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbols.

[0071] For example, based on replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, the language element analysis device can further convert the multiple lines of source code into single lines and strengthen the parts with weaker grammatical features in the multiple lines of source code.

[0072] In a possible implementation, a preset symbol in the multiple lines of source code is identified, and a portion of source code associated with the preset symbol in the multiple lines of source code is processed into a single line, including: identifying a first preset symbol and a second preset symbol that are mutually associated with each other in the multiple lines of source code, and adjusting a portion of source code between the first preset symbol and the second preset symbol, the first preset symbol, and the second preset symbol to be on the same line.

[0073] For example, the first preset symbol may be a left bracket "(", and the second preset symbol may be a right bracket ")". The language element analysis device may identify mutually related left brackets "(" and right brackets ")" in multiple lines of source code. Further, the language element analysis device may adjust the portion of the source code between the left bracket "(" and the right bracket ")", the left bracket "(", and the right bracket ")" to be on the same line. That is, no line break occurs before the left bracket "(" encounters the right bracket ")". For example, assuming that the left bracket "(" in line 34 of the source code and the right bracket ")" in line 38 are mutually related, according to the method in the embodiment of the present disclosure, lines 34-38 may be adjusted to be on the same line. For example, assuming that lines 34-38 are a function declaration that occupies multiple lines, the function declaration may be made single-lined by adjusting lines 34-38 to be on the same line. In addition, the single-line processing of annotations is similar to the single-line processing of function declarations, which will not be repeated here.

[0074] In another possible implementation, a preset symbol in the multiple lines of source code is identified, and a portion of source code in the multiple lines of source code that is associated with the preset symbol is processed into a single line, including: identifying a keyword in the multiple lines of source code and a third preset symbol that is closest to the keyword, and adjusting a portion of the source code between the keyword and the third preset symbol, the keyword, and the third preset symbol to be in the same line.

[0075] For example, the third preset symbol may be "{". The language element analysis device may identify keywords in multiple lines of source code, and the "{" that is closest to the keyword. For example, the keywords may be enum, class, void, bool, etc. Taking class as an example, when the language element analysis device identifies the keyword class in the source code, and the "{" that is closest to the keyword class, the partial source code between the keyword class and "{", the keyword class, and "{" may be adjusted to the same line. If the keyword class and "{" are already on the same line, no adjustment is required at this time. If in some embodiments, the "{" that is closest to class is on the next line of class, the partial source code between the keyword class and "{", the keyword class, and "{" need to be adjusted to the same line. For example, assuming that line 15 in the source code is a class declaration, the class declaration may be made single-line by adjusting the partial source code between the keyword class and "{", the keyword class, and "{" to the same line. In addition, it is not limited to single-line processing of class declarations. For example, structures and other source codes similar to structures and class declarations may also be made single-line in a manner similar to class declarations, which will not be described one by one here.

[0076] Optionally, the method further includes: identifying a fourth preset symbol associated with the third preset symbol in the multiple lines of source code, and adding a new line below the fourth preset symbol. Optionally, the content of the same line obtained after the partial source code between the keyword and the third preset symbol, the keyword and the third preset symbol are adjusted to be the same line is the same as the content of the new line.

[0077] For example, the fourth preset symbol may be “}”. Since the grammatical features of the end point are weak and difficult to identify through pattern matching, a new line may be added after “}” to identify the end point, thereby strengthening the features of the end point.

[0078] Optionally, the method further includes: when the keyword is a target keyword, adding a second preset identifier in each line of source code between the third preset symbol and the fourth preset symbol.

[0079] For example, if the features of the enumeration items included in the enumeration enum in a line of the source code are weak, the features of the enumeration items can be enhanced by adding a second preset identifier. For example, the second preset identifier can be, for example, an asterisk. That is to say, the part including the asterisk represents the enumeration item. Specifically, enum can be used as a target keyword. When the language element analysis device recognizes the keyword in the source code and determines that the keyword is the target keyword enum, the "{" and "}" closest to the enum can be determined, and an asterisk can be added to each line of source code between "{" and "}", thereby enhancing the features of the enumeration items.

[0080] It is understandable that the single-line processing and feature enhancement of source code are not limited to the above-mentioned cases, but may also include other cases, which will not be described in detail here.

[0081] S105: Determine the language elements in the multiple lines of source code after the single-line processing.

[0082] Optionally, determining the language elements in the multiple lines of source code after the single-line processing includes: determining the language elements in the multiple lines of source code after the single-line processing by using a regular expression.

[0083] It is understandable that after the source code is processed through S101-S104, the language elements in the source code are made into a single line, that is, the same language element is in one line, and the same language element is not distributed in multiple lines. In this case, a regular expression can be used to match the language elements in the multiple lines of source code after the single-line processing.

[0084] In addition, it can be understood that the number of language elements that a line of source code may include is not limited to one.

[0085] Optionally, the language element includes at least one of the following: annotation, class, variable, enumeration, enumeration item, function.

[0086] In this embodiment, annotations include runtime type information (RTTI) annotations and user interface (UI) annotations. Among them, RTTI can specifically refer to the behavior of saving the type information of variables in the C++ source code when the C++ source code is running. RTTI can be used for code automation, such as automatic generation of interface elements, automatic preservation of data, etc. In different programming languages, annotations and RTTI may have different names. For example, RTTI, reflection, runtime type identification, and runtime type information are synonyms and can all refer to RTTI. Java annotations, C# attributes, Qt meta-objects, Go tags, and Python decorators are similar concepts and can be collectively referred to as annotations.

[0087] An enumeration item can also be called an enumeration subitem. A class includes a class declaration, a variable includes a single variable declaration, a function includes a function declaration, an enumeration includes an enumeration declaration, and an enumeration item includes an enumeration subitem declaration. Specifically, examples of each of RTTI annotations, UI annotations, class declarations, single variable declarations, function declarations, enumeration declarations, and enumeration subitem declarations are shown in Table 1 below:

[0088] Table 1

[0089] Language elements Example RTTI annotations (for example, XXX_RTTI) XXX_RTTI(name="foo") UI annotations (e.g., XXX_UI) XXX_UI(Display="foo") Class Declaration class A{ Single VarDecl int a = 0; Function Declaration (FuncDecl) void foo(); Enumeration Declaration (EnumDecl) enum A{ Enumeration sub-item declaration (E-Item Decl) RIGIDBODY_STATIC

[0090] The language element analysis method provided by the embodiment of the present disclosure obtains a source code file of a preset programming language, and adds a line number to each line of source code in the multiple lines of source code included in the source code file. The line number can be used as auxiliary information to better distinguish each line of source code. In addition, on this basis, the preset paragraph in the multiple lines of source code is identified, and the preset paragraph is replaced with a first preset identifier. Since the preset paragraph may be relatively lengthy, and the first preset identifier is relatively short, the influence of the preset paragraph on the language element analysis can be reduced by replacing the preset paragraph with the first preset identifier. Further, on the basis of replacing the preset paragraph in the multiple lines of source code with the first preset identifier, the preset symbol in the multiple lines of source code is identified, and the part of the source code associated with the preset symbol is processed into a single line, so that the same language element can be distributed in the same line, avoiding the same language element being distributed in multiple lines and affecting the analysis of the language element. Further, the language element is identified on the basis of the multiple lines of source code after the single line processing, thereby realizing a method that can more accurately extract language elements from the source code.

[0091] Based on the above embodiment, after determining the language elements in the multiple lines of source code after the single-line processing, the method further includes: Figure 2 The following steps are shown:

[0092] S201: Replace the language elements in the multiple lines of source code after the single-line processing with a third identifier.

[0093] For example, after the language element analysis device determines the language elements in multiple lines of source code, it can further extract the language elements in the multiple lines of source code and replace the language elements in the multiple lines of source code with a third identifier, which can be a token. Among them, language elements such as classes, enumerations, dual morphemes of classes or enumerations, and functions include a body, that is, a code block wrapped by {}, and the remaining language elements are all single lines. Specifically, for a function, the body can be folded into the declaration line.

[0094] S202: Determine the association relationship between the language elements according to the third identifier.

[0095] For example, the language element analysis device can determine the association relationship between language elements according to the third identifier, and the association relationship includes a CDA relationship and an inclusion relationship. Among them, CDA is the abbreviation of Comment, Declare, and Annotation. In the programming process, comments, declarations, and annotations can be continuous. For example, the previous line of a language element declaration can be a comment, and the next line of the language element declaration can be an annotation. In addition, it can be understood that the previous line of a language element declaration can also be uncommented, and / or the next line of a language element declaration can also be uncommented. In the embodiment of the present disclosure, the CDA relationship can be, for example, the relationship between the comment, annotation, and declaration of a class. In addition, the inclusion relationship in the embodiment of the present disclosure can be, for example, "Enum-0" contains "EItem-0" and "EItem-1".

[0096] It is understandable that the analysis method for language elements in other source code files is similar to this, and will not be repeated here. When a warehouse includes multiple source code files, each source code file in the warehouse can be traversed, and the language element analysis method described in the embodiment of the present disclosure can be used to analyze each source code file in the warehouse.

[0097] In some embodiments, the method according to the embodiment of the present disclosure can further output an intermediate format file, which is easy to analyze and can include source code after formatting and token replacement. In addition, the correspondence between language elements and tokens, and the correspondence between preset paragraphs and tokens can also be output.

[0098] The language element analysis method provided by the embodiment of the present disclosure further improves the accuracy of analyzing the language elements by replacing the language elements in the multiple lines of source code after the single-line processing with a third identifier and determining the association relationship between the language elements according to the third identifier.

[0099] It is understandable that after analyzing the language elements in the C++ source code according to the method described in the above embodiment, the language elements can be used in many aspects. Figure 3As shown, the parsing algorithm that can extract annotations can specifically be the language element analysis method described above. The input of the parsing algorithm that can extract annotations is the C++ source code with annotations. The output of the parsing algorithm that can extract annotations is the language elements. In some embodiments, RTTI can also be generated based on the language elements, and the RTTI can be applied in many aspects, for example, the RTTI can be applied in the generation of user interfaces, document generation, code change checking, etc. In some other embodiments, language elements can also be directly applied in the generation of user interfaces, document generation, code change checking, etc. Taking language elements as an example, the following introduces the process of language elements being directly applied in the generation of user interfaces, document generation, code change checking, etc.

[0100] Optionally, after determining the language elements in the multiple lines of source code after the single-line processing, the method further includes: generating interface elements in a user interface according to the language elements.

[0101] For example, after the language element analysis device determines the language elements in multiple lines of source code, it further generates interface elements in the user interface based on the language elements. For example, each language element in the C++ source code can correspond to an interface element in the user interface. Among them, the interface elements may include, for example, buttons and data display areas. The embodiments of the present disclosure do not limit the specific forms of buttons and data display areas in the user interface. Among them, the data display area can have multiple forms. Optionally, the data display area includes at least one of the following: an input box, a drop-down box, a slider, a color palette, and a button. Among them, the color palette is used for color selection. The button may include at least one of a button for function execution and a plus and minus button, and the plus and minus buttons can be used to add or delete arrays.

[0102] In a feasible implementation, generating an interface element in a user interface according to the language element includes: generating a button in the user interface according to a member function of a class associated with the annotation.

[0103] For example, when the language element analysis device identifies a member function of a class associated with an annotation in a C++ source code, a button in the user interface can be generated. When the button is operated, such as being clicked, double-clicked, long pressed, voice controlled, gesture controlled, expression controlled, etc., the function corresponding to the interface element will be executed.

[0104] In another feasible implementation, generating an interface element in a user interface according to the language element includes: generating a data display area in the user interface according to a variable or enumeration associated with the annotation.

[0105] For example, when the language element analysis device identifies a variable or enumeration associated with an annotation in a C++ source code, a data display area in a user interface may be generated.

[0106] When the language element analysis device identifies an enumeration associated with an annotation in a C++ source code, a drop-down box in a user interface may be generated, and the options in the drop-down box may be specifically generated based on the enumeration items included in the enumeration.

[0107] When the language element analysis device identifies a variable associated with an annotation in a C++ source code, it can generate a data display area corresponding to the type of the variable. For example, when the type of the variable is a character, string, or floating point type, the language element analysis device can generate an input box in the user interface, which can be a text input box, so that the user can set the specific value of the variable in the text input box. When the type of the variable is an integer type, the language element analysis device can generate a slider in the user interface, which can be a slider, Figure 4 The slider shown, Figure 4 The type of the variable Var1 shown is an integer, the minimum value of the variable Var1 is -9, and the maximum value of the variable Var1 is 9. Accordingly, the minimum and maximum values ​​of the variable Var1 can be set in the C++ source code. The language element analysis device can determine the value corresponding to the vertex at the leftmost end of the slider and the value corresponding to the vertex at the rightmost end of the slider according to the minimum and maximum values ​​of the variable Var1. For example, the value corresponding to the vertex at the leftmost end of the slider is -9, and the value corresponding to the vertex at the rightmost end of the slider is 9. Accordingly, the user can edit the specific value of the variable by sliding the slider.

[0108] Optionally, after determining the language elements in the multiple lines of source code after the single-line processing, the method further includes: automatically generating a document.

[0109] For example, when the language element analysis device identifies a variable or enumeration associated with an annotation in a C++ source code, a document may be automatically generated, and the document may include the content of the class and the content of the enumeration.

[0110] Optionally, the source code file of the preset programming language is a source code file of the first version; after determining the language elements in the multiple lines of source code after the single-line processing, the method further includes: Figure 5 The following steps are shown:

[0111] S501: Obtain language elements in a source code file of the second version.

[0112] For example, the source code file as described above is a source code file of the first version. Accordingly, the C++ source code in the source code file may be the C++ source code of the first version. Specifically, the first version may be written by a programmer at a certain time. In some application scenarios, the programmer may also modify the C++ source code of the first version at another time to obtain the C++ source code of the second version, and the C++ source code of the second version may be recorded as the source code in the source code file of the second version.

[0113] In order to be able to check C++ source code changes, for example, API interface changes, the language element analysis device can, after determining the language elements in the first version of the source code file, obtain the second version of the source code file and use the language element analysis method described above to determine the language elements in the second version of the source code file.

[0114] S502: Determine the difference between the first version of the source code file and the second version of the source code file by comparing the language elements in the first version of the source code file with the language elements in the second version of the source code file.

[0115] For example, the language element analysis device can compare the language elements in the source code file of the first version with the language elements in the source code file of the second version, and determine the difference between the source code file of the first version and the source code file of the second version by comparison, thereby realizing cross-version code change check. For example, with the first version as the new version and the second version as the old version, when there are differences between the source code file of the new version and the source code file of the old version, there may be accidental deletion, that is, part of the code in the old version may be accidentally deleted in the new version. In this case, the cross-version code change check described in the embodiment of the present disclosure can detect the accidental deletion, and an alarm can be issued in advance for the accidental deletion, thereby effectively avoiding the problem of program crash caused by the inability to call part due to accidental deletion.

[0116] In some other embodiments, the language element analysis device can also perform a correctness check on the C++ source code of the first version based on the language elements in the source code file of the first version, or can perform a correctness check on the C++ source code of the second version based on the language elements in the source code file of the second version, thereby realizing code change checking within the version.

[0117] The language element analysis method provided by the embodiment of the present disclosure generates interface elements in the user interface according to the language elements after determining the language elements in multiple lines of source code, so that the user can set the specific value of the variable in the C++ source code through the interface elements, thereby improving the automatic setting and flexibility of the variable. In addition, by comparing the language elements in the source code file of the first version and the language elements in the source code file of the second version, the difference between the source code file of the first version and the source code file of the second version can also be determined, thereby realizing the cross-version code change check. Since there are many C++ source codes included in the source code file, if the C++ source codes in the two source code files are directly compared, the efficiency of the code change check will be low. However, the embodiment greatly improves the efficiency of the code change check by extracting the language elements in the two source code files and further comparing the language elements in the two source code files. In addition, the correctness check of the C++ source code of the first version can be performed according to the language elements in the source code file of the first version, or the correctness check of the C++ source code of the second version can be performed according to the language elements in the source code file of the second version, thereby realizing the code change check within the version, thereby improving the reliability and accuracy of the C++ source code.

[0118] Figure 6 FIG. 1 is a flow chart of another language element analysis method in an embodiment of the present disclosure. Figure 6 As shown, the method of this embodiment is applied in a terminal or a server, and specifically includes:

[0119] S601: Obtain a source code file of a preset programming language, wherein the source code file includes multiple lines of source code.

[0120] Specifically, the implementation process and specific principles of S601 and S101 are the same, and will not be repeated here.

[0121] S602: Add a line number to each line of the multiple lines of source code.

[0122] Specifically, the implementation process and specific principles of S602 and S102 are consistent and will not be repeated here.

[0123] S603: Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier.

[0124] Specifically, the implementation process and specific principles of S603 and S103 are consistent and will not be repeated here.

[0125] S604: on the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbols in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbols.

[0126] Specifically, the implementation process and specific principles of S604 and S104 are the same, and will not be repeated here.

[0127] S605: Determine the annotations in the multiple lines of source code after the single-line processing, and the language elements related to the annotations.

[0128] For example, the language element analysis device can determine the association relationship between language elements, thereby determining the annotations in the C++ source code and the language elements related to the annotations.

[0129] S606: Displaying an interface element corresponding to the language element in the user interface.

[0130] For example, each language element in the C++ source code may correspond to an interface element in the user interface. After the language element analysis device determines the language elements in the multiple lines of source code, the interface elements in the user interface are further generated according to the language elements.

[0131] For example, when the language element analysis device identifies a member function of a class associated with an annotation in a C++ source code, a button in a user interface can be generated. When the language element analysis device identifies a variable or enumeration associated with an annotation in a C++ source code, a data display area in a user interface can be generated.

[0132] When the language element analysis device identifies an enumeration associated with an annotation in a C++ source code, a drop-down box in a user interface may be generated, and the options in the drop-down box may be specifically generated based on the enumeration items included in the enumeration.

[0133] When the language element analysis device identifies a variable associated with an annotation in a C++ source code, it can generate a data display area corresponding to the type of the variable. For example, when the type of the variable is a character, string, or floating point type, the language element analysis device can generate an input box in the user interface, which can be a text input box, so that the user can set the specific value of the variable in the text input box. When the type of the variable is an integer type, the language element analysis device can generate a slider in the user interface, which can be a slider, Figure 4 The slider shown, Figure 4The type of the variable Var1 shown is an integer, the minimum value of the variable Var1 is -9, and the maximum value of the variable Var1 is 9. Accordingly, the minimum and maximum values ​​of the variable Var1 can be set in the C++ source code. The language element analysis device can determine the value corresponding to the vertex at the leftmost end of the slider and the value corresponding to the vertex at the rightmost end of the slider according to the minimum and maximum values ​​of the variable Var1. For example, the value corresponding to the vertex at the leftmost end of the slider is -9, and the value corresponding to the vertex at the rightmost end of the slider is 9. Accordingly, the user can edit the specific value of the variable by sliding the slider.

[0134] The language element analysis method provided by the embodiment of the present disclosure obtains a source code file of a preset programming language, and adds a line number to each line of source code in the multiple lines of source code included in the source code file. The line number can be used as auxiliary information to better distinguish each line of source code. In addition, on this basis, the preset paragraph in the multiple lines of source code is identified, and the preset paragraph is replaced with a first preset identifier. Since the preset paragraph may be relatively lengthy, and the first preset identifier is relatively short, the influence of the preset paragraph on the language element analysis can be reduced by replacing the preset paragraph with the first preset identifier. Further, on the basis of replacing the preset paragraph in the multiple lines of source code with the first preset identifier, the preset symbol in the multiple lines of source code is identified, and the part of the source code associated with the preset symbol is processed into a single line, so that the same language element can be distributed in the same line, avoiding the same language element being distributed in multiple lines and affecting the analysis of the language element. Further, the language element is identified on the basis of the multiple lines of source code after the single line processing, thereby realizing a method that can more accurately extract language elements from the source code. In addition, after determining the language elements in multiple lines of source code, interface elements in the user interface are generated according to the language elements, so that users can set specific values ​​of variables in the C++ source code through interface elements, thereby improving the automatic setting and setting flexibility of variables.

[0135] Figure 7 Schematic diagram of the structure of a language element analysis device in an embodiment of the present disclosure. The language element analysis device provided in the embodiment of the present disclosure can be configured in a client, or can be configured in a server, and the language element analysis device 70 specifically includes:

[0136] An acquisition module 71 is used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0137] A line number adding module 72, used for adding a line number to each line of the plurality of lines of source code;

[0138] An identification module 73, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added;

[0139] A replacement module 74, used to replace the preset paragraphs in the multiple lines of source code with a first preset identifier;

[0140] The identification module 73 is further used to: identify the preset symbols in the multiple lines of source code on the basis that the replacement module 74 replaces the preset paragraphs in the multiple lines of source code with the first preset identifier;

[0141] A processing module 75, configured to convert a portion of the source code lines associated with the preset symbol into a single line;

[0142] The determination module 76 is used to determine the language elements in the multiple lines of source code after the single-line processing.

[0143] Optionally, the identification module 73 is specifically used to: identify the first preset symbol and the second preset symbol that are mutually related in the multiple lines of source code, and the processing module 75 is specifically used to: adjust the partial source code between the first preset symbol and the second preset symbol, the first preset symbol and the second preset symbol to the same line.

[0144] Optionally, the identification module 73 is specifically used to: identify keywords in the multiple lines of source code, and a third preset symbol that is closest to the keyword, and the processing module 75 is specifically used to: adjust part of the source code between the keyword and the third preset symbol, the keyword and the third preset symbol to the same line.

[0145] Optionally, the identification module 73 is further used to: identify a fourth preset symbol associated with the third preset symbol in the multiple lines of source code, and the processing module 75 is further used to: add a new line to the next line of the fourth preset symbol.

[0146] Optionally, the partial source code between the keyword and the third preset symbol, and the content of the same line obtained after the keyword and the third preset symbol are adjusted to be in the same line are the same as the content of the new line.

[0147] Optionally, the processing module 75 is further configured to: when the keyword is a target keyword, add a second preset identifier in each line of source code between the third preset symbol and the fourth preset symbol.

[0148] Optionally, the determination module 76 is specifically configured to determine the language elements in the multiple lines of source code after the single-line processing by using a regular expression.

[0149] Optionally, the processing module 75 is further used to: after the determination module 76 determines the language elements in the multiple lines of source code after the single-line processing, replace the language elements in the multiple lines of source code after the single-line processing with a third identifier; the determination module 76 is further used to: determine the association relationship between the language elements according to the third identifier.

[0150] Optionally, the preset paragraph includes at least one of the following:

[0151] Long comment, short comment, string, raw string, character.

[0152] Optionally, the language element includes at least one of the following:

[0153] Annotation, class, variable, enumeration, enumerator, function.

[0154] Optionally, the language element analysis device 70 further includes: a generating module 77, which is used to generate interface elements in the user interface according to the language elements in the multiple lines of source code after the determining module 76 determines the language elements in the single-line processing.

[0155] Optionally, the generating module 77 is specifically used to generate a button in the user interface according to a member function of a class associated with the annotation.

[0156] Optionally, the generating module 77 is specifically used to generate a data display area in the user interface according to a variable or enumeration associated with the annotation.

[0157] Optionally, the data display area includes at least one of the following:

[0158] Input box, drop-down box, slider, color palette, button.

[0159] Optionally, the source code file of the preset programming language is a source code file of the first version; the acquisition module 71 is also used to: after the determination module 76 determines the language elements in the multiple lines of source code after the single-line processing, obtain the language elements in the source code file of the second version; the determination module 76 is also used to: determine the difference between the source code file of the first version and the source code file of the second version by comparing the language elements in the source code file of the first version with the language elements in the source code file of the second version.

[0160] The language element analysis device provided in the embodiment of the present disclosure can execute the steps executed by the client or server in the language element analysis method provided in the embodiment of the method of the present disclosure, and the execution steps and beneficial effects are no longer repeated here.

[0161] Figure 8Schematic diagram of the structure of a language element analysis device in an embodiment of the present disclosure. The language element analysis device provided in the embodiment of the present disclosure can be configured in a client, or can be configured in a server, and the language element analysis device 80 specifically includes:

[0162] An acquisition module 81 is used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0163] A line number adding module 82, used for adding a line number to each line of the plurality of lines of source code;

[0164] An identification module 83, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added;

[0165] A replacement module 84, used to replace the preset paragraphs in the multiple lines of source code with a first preset identifier;

[0166] The recognition module 83 is further used to: recognize the preset symbols in the multiple lines of source code on the basis that the replacement module 84 replaces the preset paragraphs in the multiple lines of source code with the first preset identifier;

[0167] A processing module 85, configured to convert a portion of the source code lines associated with the preset symbol into a single line;

[0168] A determination module 86, configured to determine annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations;

[0169] The display module 87 is used to display the interface elements corresponding to the language elements in the user interface.

[0170] The language element analysis device provided in the embodiment of the present disclosure can execute the steps executed by the client or server in the language element analysis method provided in the embodiment of the method of the present disclosure, and the execution steps and beneficial effects are no longer repeated here.

[0171] Fig. 9 Schematic diagram of the structure of an electronic device in the embodiment of the present disclosure. Fig. 9 , which shows a schematic diagram of the structure of an electronic device 900 suitable for implementing the embodiment of the present disclosure. The electronic device 900 in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0172] like Fig. 9 As shown, the electronic device 900 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage device 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the electronic device 900 are also stored. The processing device 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0173] Typically, the following devices may be connected to the I / O interface 905: an input device 906 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 908 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 909. The communication device 909 may allow the electronic device 900 to communicate with other devices wirelessly or by wire to exchange data. Although Fig. 9 The electronic device 900 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0174] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 909, or installed from a storage device 908, or installed from a ROM 902. When the computer program is executed by the processing device 901, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0175] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0176] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0177] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0178] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains a source code file in a preset programming language, the source code file includes multiple lines of source code;

[0179] Adding a line number to each line of the source code;

[0180] Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier;

[0181] On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol;

[0182] Determine the language elements in the multiple lines of source code after the single-line processing.

[0183] Optionally, the electronic device may also perform other steps as described in the above embodiments.

[0184] Alternatively, the computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device:

[0185] Obtaining a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0186] Adding a line number to each line of the source code;

[0187] Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier;

[0188] On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol;

[0189] Determining annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations;

[0190] An interface element corresponding to the language element is displayed in the user interface.

[0191] Optionally, the electronic device may also perform other steps as described in the above embodiments.

[0192] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0193] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0194] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a unit does not, in some cases, constitute a limitation on the unit itself.

[0195] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0196] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0197] According to one or more embodiments of the present disclosure, the present disclosure provides a language element analysis method, including:

[0198] Obtaining a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0199] Adding a line number to each line of the source code;

[0200] Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier;

[0201] On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol;

[0202] Determine the language elements in the multiple lines of source code after the single-line processing.

[0203] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, identifying a preset symbol in the multiple lines of source code, and performing single-line processing on a portion of the source code associated with the preset symbol in the multiple lines of source code, includes:

[0204] A first preset symbol and a second preset symbol associated with each other in the multiple lines of source code are identified, and a portion of the source code between the first preset symbol and the second preset symbol, the first preset symbol and the second preset symbol are adjusted to be in the same line.

[0205] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, identifying a preset symbol in the multiple lines of source code, and performing single-line processing on a portion of the source code associated with the preset symbol in the multiple lines of source code, includes:

[0206] A keyword in the multiple lines of source code and a third preset symbol closest to the keyword are identified, and a portion of the source code between the keyword and the third preset symbol, the keyword and the third preset symbol are adjusted to be in the same line.

[0207] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, the method further includes:

[0208] A fourth preset symbol associated with the third preset symbol in the multiple lines of source code is identified, and a new line is added next to the fourth preset symbol.

[0209] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, the partial source code between the keyword and the third preset symbol, and the content of the same line obtained after the keyword and the third preset symbol are adjusted to be in the same line are the same as the content of the new line.

[0210] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, the method further includes:

[0211] When the keyword is a target keyword, a second preset identifier is added to each line of source code between the third preset symbol and the fourth preset symbol.

[0212] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, determining the language elements in the multiple lines of source code after the single-line processing includes:

[0213] The language elements in the multiple lines of source code after the single-line processing are determined by using regular expressions.

[0214] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, after determining the language elements in the multiple lines of source code after the single-line processing, the method further includes:

[0215] Replacing the language elements in the multiple lines of source code after the single-line processing with a third identifier;

[0216] The association relationship between the language elements is determined according to the third identifier.

[0217] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, the preset paragraph includes at least one of the following:

[0218] Long comment, short comment, string, raw string, character.

[0219] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, the language element includes at least one of the following:

[0220] Annotation, class, variable, enumeration, enumerator, function.

[0221] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, after determining the language elements in the multiple lines of source code after the single-line processing, the method further includes:

[0222] An interface element in a user interface is generated according to the language element.

[0223] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, generating an interface element in a user interface according to the language element includes:

[0224] A button in the user interface is generated according to a member function of a class associated with the annotation.

[0225] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, generating an interface element in a user interface according to the language element includes:

[0226] A data display area in the user interface is generated according to the variable or enumeration associated with the annotation.

[0227] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, the data display area includes at least one of the following:

[0228] Input box, drop-down box, slider, color palette, button.

[0229] According to one or more embodiments of the present disclosure, in the language element analysis method provided by the present disclosure, the source code file of the preset programming language is a source code file of a first version;

[0230] After determining the language elements in the multiple lines of source code after the single-line processing, the method further includes:

[0231] Get the language elements in the second version of the source code file;

[0232] By comparing the language elements in the source code file of the first version with the language elements in the source code file of the second version, the difference between the source code file of the first version and the source code file of the second version is determined.

[0233] According to one or more embodiments of the present disclosure, the present disclosure provides a language element analysis method, including:

[0234] Obtaining a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0235] Adding a line number to each line of the source code;

[0236] Identify a preset paragraph in the multiple lines of source code to which the line numbers are added, and replace the preset paragraph in the multiple lines of source code with a first preset identifier;

[0237] On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol;

[0238] Determining annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations;

[0239] An interface element corresponding to the language element is displayed in the user interface.

[0240] According to one or more embodiments of the present disclosure, the present disclosure provides a language element analysis device, including:

[0241] An acquisition module, used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0242] A line number adding module, used for adding a line number to each line of the multiple lines of source code;

[0243] an identification module, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added;

[0244] A replacement module, used for replacing a preset paragraph in the plurality of lines of source code with a first preset identifier;

[0245] The recognition module is further used to: recognize the preset symbols in the multiple lines of source code on the basis that the replacement module replaces the preset paragraphs in the multiple lines of source code with the first preset identifier;

[0246] A processing module, used for processing a portion of source code associated with the preset symbol in the multiple source code lines into a single line;

[0247] A determination module is used to determine the language elements in the multiple lines of source code after the single-line processing.

[0248] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the identification module is specifically used to: identify the first preset symbol and the second preset symbol that are mutually related in the multiple lines of source code, and the processing module is specifically used to: adjust the partial source code between the first preset symbol and the second preset symbol, the first preset symbol and the second preset symbol to the same line.

[0249] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the recognition module is specifically used to: identify keywords in the multiple lines of source code, and a third preset symbol that is closest to the keyword, and the processing module is specifically used to: adjust part of the source code between the keyword and the third preset symbol, the keyword, and the third preset symbol to the same line.

[0250] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the identification module is also used to: identify a fourth preset symbol associated with the third preset symbol in the multiple lines of source code, and the processing module is also used to: add a new line below the fourth preset symbol.

[0251] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the partial source code between the keyword and the third preset symbol, the content of the same line obtained after the keyword and the third preset symbol are adjusted to be in the same line are the same as the content of the new line.

[0252] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the processing module is also used to: when the keyword is a target keyword, add a second preset identifier in each line of source code between the third preset symbol and the fourth preset symbol.

[0253] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the determination module is specifically used to: determine the language elements in the multiple lines of source code after the single-line processing by using regular expressions.

[0254] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the processing module is further used to: after the determination module determines the language elements in the multiple lines of source code after the single-line processing, replace the language elements in the multiple lines of source code after the single-line processing with a third identifier; the determination module is further used to: determine the association relationship between the language elements according to the third identifier.

[0255] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the preset paragraph includes at least one of the following:

[0256] Long comment, short comment, string, raw string, character.

[0257] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the language element includes at least one of the following:

[0258] Annotation, class, variable, enumeration, enumerator, function.

[0259] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the language element analysis device also includes: a generation module, which is used to generate interface elements in the user interface according to the language elements after the determination module determines the language elements in the multiple lines of source code after the single-line processing.

[0260] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the generation module is specifically used to: generate a button in the user interface according to a member function of a class associated with the annotation.

[0261] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the generation module is specifically used to: generate a data display area in the user interface according to variables or enumerations associated with annotations.

[0262] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the data display area includes at least one of the following:

[0263] Input box, drop-down box, slider, color palette, button.

[0264] According to one or more embodiments of the present disclosure, in the language element analysis device provided by the present disclosure, the source code file of the preset programming language is a source code file of a first version; the acquisition module is further used to: after the determination module determines the language elements in the multiple lines of source code after the single-line processing, obtain the language elements in the source code file of a second version; the determination module is further used to: determine the difference between the source code file of the first version and the source code file of the second version by comparing the language elements in the source code file of the first version with the language elements in the source code file of the second version.

[0265] According to one or more embodiments of the present disclosure, the present disclosure provides a language element analysis device, including:

[0266] An acquisition module, used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code;

[0267] A line number adding module, used for adding a line number to each line of the multiple lines of source code;

[0268] an identification module, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added;

[0269] A replacement module, used for replacing a preset paragraph in the plurality of lines of source code with a first preset identifier;

[0270] The recognition module is further used to: recognize the preset symbols in the multiple lines of source code on the basis that the replacement module replaces the preset paragraphs in the multiple lines of source code with the first preset identifier;

[0271] A processing module, used for processing a portion of source code associated with the preset symbol in the multiple source code lines into a single line;

[0272] A determination module, used for determining annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations;

[0273] The display module is used to display the interface elements corresponding to the language elements in the user interface.

[0274] According to one or more embodiments of the present disclosure, the present disclosure provides an electronic device, including:

[0275] one or more processors;

[0276] A memory for storing one or more programs;

[0277] When the one or more programs are executed by the one or more processors, the one or more processors implement any language element analysis method provided in the present disclosure.

[0278] According to one or more embodiments of the present disclosure, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the language element analysis method as described in any one of the present disclosure is implemented.

[0279] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.

[0280] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.

[0281] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. A language element analysis method, characterized in that: The method comprises: Obtaining a source code file of a preset programming language, wherein the source code file includes multiple lines of source code; Adding a line number to each line of the source code; Identifying a preset paragraph in the multiple lines of source code to which the line numbers are added, and replacing the preset paragraph in the multiple lines of source code with a first preset identifier, wherein replacing the preset paragraph in the multiple lines of source code with the first preset identifier is used to lighten the preset paragraph in the multiple lines of source code; On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol; Determine the language elements in the multiple lines of source code after the single-line processing.

2. The method according to claim 1, characterized in that Identifying a preset symbol in the multiple lines of source code, and performing single-line processing on a portion of the multiple lines of source code associated with the preset symbol, including: A first preset symbol and a second preset symbol associated with each other in the multiple lines of source code are identified, and a portion of the source code between the first preset symbol and the second preset symbol, the first preset symbol and the second preset symbol are adjusted to be in the same line.

3. The method according to claim 1, characterized in that Identifying a preset symbol in the multiple lines of source code, and performing single-line processing on a portion of the multiple lines of source code associated with the preset symbol, including: A keyword in the multiple lines of source code and a third preset symbol closest to the keyword are identified, and a portion of the source code between the keyword and the third preset symbol, the keyword and the third preset symbol are adjusted to be in the same line.

4. The method according to claim 3, characterized in that The method further comprises: A fourth preset symbol associated with the third preset symbol in the multiple lines of source code is identified, and a new line is added next to the fourth preset symbol.

5. The method according to claim 4, characterized in that The partial source code between the keyword and the third preset symbol, and the content of the same line obtained after the keyword and the third preset symbol are adjusted to be in the same line are the same as the content of the new line.

6. The method according to claim 4, characterized in that The method further comprises: When the keyword is a target keyword, a second preset identifier is added in each line of source code between the third preset symbol and the fourth preset symbol.

7. The method according to claim 1, characterized in that Determining the language elements in the multiple lines of source code after the single-line processing includes: The language elements in the multiple lines of source code after the single-line processing are determined by using regular expressions.

8. The method according to claim 1, characterized in that After determining the language elements in the multiple lines of source code after the single-line processing, the method further includes: Replacing the language elements in the multiple lines of source code after the single-line processing with a third identifier; The association relationship between the language elements is determined according to the third identifier.

9. The method according to any one of claims 1 to 8, characterized in that: The preset paragraphs include at least one of the following: Long comment, short comment, string, raw string, character.

10. The method according to any one of claims 1 to 8, characterized in that: The language elements include at least one of the following: Annotation, class, variable, enumeration, enumerator, function.

11. The method according to claim 1, characterized in that After determining the language elements in the multiple lines of source code after the single-line processing, the method further includes: An interface element in a user interface is generated according to the language element.

12. The method according to claim 11, characterized in that Generating interface elements in the user interface according to the language elements includes: A button in the user interface is generated according to a member function of a class associated with the annotation.

13. The method according to claim 11, characterized in that Generating interface elements in the user interface according to the language elements includes: A data display area in the user interface is generated according to the variable or enumeration associated with the annotation.

14. The method according to claim 13, characterized in that The data display area includes at least one of the following: Input box, drop-down box, slider, color palette, button.

15. The method according to claim 1, characterized in that The source code file of the preset programming language is a source code file of the first version; After determining the language elements in the multiple lines of source code after the single-line processing, the method further includes: Get the language elements in the second version of the source code file; By comparing the language elements in the source code file of the first version with the language elements in the source code file of the second version, the difference between the source code file of the first version and the source code file of the second version is determined.

16. A method for analyzing language elements, characterized in that: The method comprises: Obtaining a source code file of a preset programming language, wherein the source code file includes multiple lines of source code; Adding a line number to each line of the source code; Identifying a preset paragraph in the multiple lines of source code to which the line numbers are added, and replacing the preset paragraph in the multiple lines of source code with a first preset identifier, wherein replacing the preset paragraph in the multiple lines of source code with the first preset identifier is used to lighten the preset paragraph in the multiple lines of source code; On the basis of replacing the preset paragraphs in the multiple lines of source code with the first preset identifier, identifying the preset symbol in the multiple lines of source code, and performing single-line processing on a portion of source code in the multiple lines of source code associated with the preset symbol; Determining annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations; An interface element corresponding to the language element is displayed in the user interface.

17. A language element analysis device, characterized in that: include: An acquisition module, used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code; A line number adding module, used for adding a line number to each line of the multiple lines of source code; an identification module, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added; A replacement module, used for replacing the preset paragraphs in the multiple lines of source code with a first preset identifier, wherein replacing the preset paragraphs in the multiple lines of source code with the first preset identifier is used to lighten the preset paragraphs in the multiple lines of source code; The recognition module is further used to: recognize the preset symbols in the multiple lines of source code on the basis that the replacement module replaces the preset paragraphs in the multiple lines of source code with the first preset identifier; A processing module, used for processing a portion of source code associated with the preset symbol in the multiple source code lines into a single line; A determination module is used to determine the language elements in the multiple lines of source code after the single-line processing.

18. A language element analysis device, characterized in that: include: An acquisition module, used to acquire a source code file of a preset programming language, wherein the source code file includes multiple lines of source code; A line number adding module, used for adding a line number to each line of the multiple lines of source code; an identification module, used for identifying a preset paragraph in the plurality of source code lines to which the line numbers are added; A replacement module, used for replacing the preset paragraphs in the multiple lines of source code with a first preset identifier, wherein replacing the preset paragraphs in the multiple lines of source code with the first preset identifier is used to lighten the preset paragraphs in the multiple lines of source code; The recognition module is further used to: recognize the preset symbols in the multiple lines of source code on the basis that the replacement module replaces the preset paragraphs in the multiple lines of source code with the first preset identifier; A processing module, used for processing a portion of source code associated with the preset symbol in the multiple source code lines into a single line; A determination module, used for determining annotations in the multiple lines of source code after the single-line processing, and language elements related to the annotations; The display module is used to display the interface elements corresponding to the language elements in the user interface.

19. An electronic device, characterized in that: The electronic device comprises: one or more processors; A storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 16.

20. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 16 is implemented.

Citation Information

Patent Citations

  • Method and device for automatically analyzing source file information

    CN103927212A

  • Compiling method and device of quantum program

    CN111767055A