Program text processing method and device, medium, computer equipment and program product
By using delimiters and formatted string templates to process robot programming instructions, the problem of robots being unable to parse complex instructions is solved, improving the readability and parsing accuracy of program text and ensuring the stability and efficiency of robot execution.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-09
- Publication Date
- 2026-04-03
AI Technical Summary
Non-standard robot programming instruction formats prevent the robot from parsing them, and complex instruction text in computer-based programming environments makes recognition difficult, affecting execution efficiency and stability.
The program text is split using pre-set delimiters to generate a string set, and then formatted using a format string template, including wildcard string replacement and syntax analysis, to ensure that the instructions are standardized.
This enables robots to accurately recognize and execute program text with a uniform format and clear structure, improving execution efficiency and stability, and reducing unforeseen consequences.
Smart Images

Figure CN121785602A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of control, and more particularly to a method, apparatus, medium, computer equipment, and program product for processing program text. Background Technology
[0002] In robot programming simulations of related technologies, users directly generate programs by clicking on instructions on the teach pendant according to the needs of the work scenario. Users cannot modify the instructions except for parameters. Simultaneously, the robot controller strictly adheres to the program instruction format during compilation and execution. In these technologies, the user's programming environment for the robot has shifted from the teach pendant to a computer. Using editors or text editors on a computer to write program instructions provides a more flexible editing environment than on a teach pendant, allowing for copying and pasting code, editing within the same line of code, and inserting characters at any point. This results in more complex program instruction text, which some robots may not be able to recognize, potentially leading to unpredictable consequences. Summary of the Invention
[0003] The main objective of this invention is to overcome the deficiencies of the aforementioned related technologies and provide a program text processing method, apparatus, medium, computer equipment, and program product to solve the problem that non-standard robot programming instruction formats cause robots to be unable to parse them in the related technologies.
[0004] The present invention provides a method for processing program text, comprising: acquiring program text to be processed; segmenting statements in the program text according to a pre-set delimiter to generate a corresponding string set; and formatting the generated string set to obtain a corresponding formatted string set.
[0005] Optionally, the statements in the program text are segmented according to a pre-set delimiter to generate a corresponding string set, including: splitting the program text line by line, and for each line of statements in the program text, segmenting it according to the pre-set delimiter to generate a string set for each line of statements.
[0006] Optionally, for each line of statements in the program text, the text is segmented according to the preset delimiter to generate a string set for each line of statements, including: for each line of statements, reading each character one by one and caching it into a character buffer; whenever the preset delimiter is detected, saving the currently cached character as a string unit into the string set, clearing the character buffer, and continuing to read each character one by one until all characters of the current line of statements are read, thus obtaining the string set of the current line of statements.
[0007] Optionally, the generated string set is formatted to obtain a corresponding formatted string set, including: formatting the string set of each generated line of statement to obtain a formatted string set for each line of statement.
[0008] Optionally, the string set of each generated line statement is formatted to obtain a set of formatted strings for each line statement, including: matching the string set of the current line statement with two or more preset formatted string templates to determine the formatted string template that matches the string set of the current line statement; and formatting the string set of the current line statement according to the determined formatted string template that matches the string set of the current line statement to obtain the formatted string of the current line statement.
[0009] Optionally, the string set of the current line statement is matched with two or more preset format string templates to determine the format string template that matches the string set of the current line statement. This includes: first determining the statement type of the current line statement, and then matching the string set of the current line statement with the format string template corresponding to the statement type of the current line statement to determine the format string template that matches the string set of the current line statement.
[0010] Optionally, the formatted string template includes: a set of strings with a preset format; the set of strings with a preset format includes a preset string and a wildcard string composed of strings combined according to the preset format; the wildcard string can match strings of all letter combinations; according to the determined formatted string template that matches the set of strings of the current line statement, the set of strings of the current line statement is formatted to obtain the formatted string of the current line statement, including: replacing the wildcard string in the determined formatted string template that matches the set of strings of the current line statement with the string at the corresponding position in the set of strings of the current line statement, to obtain the set of formatted strings of the current line statement.
[0011] Optionally, it also includes: if the string set of any line statement is matched with two or more preset format string templates and no format string template matching the string set of the current line statement is found, then the current line statement is analyzed based on its syntax structure to determine the potential error type.
[0012] Optionally, it also includes: formatting the generated string set to obtain a corresponding formatted string set, and then adjusting the format of the obtained formatted string set according to the context.
[0013] Another aspect of the present invention provides a program text processing apparatus, comprising: an acquisition unit for acquiring program text to be processed; a generation unit for segmenting statements in the program text according to a pre-set delimiter to generate a corresponding string set; and a processing unit for formatting the string set generated by the generation unit to obtain a corresponding formatted string set.
[0014] Optionally, the generation unit divides the statements in the program text according to a pre-set delimiter to generate a corresponding string set, including: splitting the program text by line, and for each line of statements in the program text, dividing it according to the pre-set delimiter to generate a string set for each line of statements.
[0015] Optionally, the generation unit, for each line of statement in the program text, divides it according to the preset delimiter to generate a string set for each line of statement, including: for each line of statement, reading each character one by one and caching it into a character buffer; whenever the preset delimiter is detected, saving the currently cached character as a string unit into the string set, clearing the character buffer, and continuing to read each character one by one until all characters of the current line of statement are read, thereby obtaining the string set of the current line of statement.
[0016] Optionally, the processing unit performs formatting processing on the generated string set to obtain a corresponding formatted string set, including: performing formatting processing on the string set of each generated line of statement to obtain a formatted string set for each line of statement.
[0017] Optionally, the processing unit performs formatting processing on the string set of each generated line statement to obtain a formatted string set for each line statement, including: matching the string set of the current line statement with two or more preset formatted string templates to determine the formatted string template that matches the string set of the current line statement; and formatting the string set of the current line statement according to the determined formatted string template that matches the string set of the current line statement to obtain the formatted string of the current line statement.
[0018] Optionally, the processing unit matches the string set of the current line statement with two or more preset format string templates to determine the format string template that matches the string set of the current line statement, including: first determining the statement type of the current line statement, and then matching the string set of the current line statement with the format string template corresponding to the statement type of the current line statement to determine the format string template that matches the string set of the current line statement.
[0019] Optionally, the formatted string template includes: a set of strings with a preset format; the set of strings with a preset format includes a preset string and a wildcard string composed of strings combined according to the preset format; the wildcard string can match strings of all letter combinations; the processing unit formats the set of strings of the current line statement according to the determined formatted string template that matches the set of strings of the current line statement to obtain the formatted string of the current line statement, including: replacing the wildcard string in the determined formatted string template that matches the set of strings of the current line statement with the string at the corresponding position in the set of strings of the current line statement to obtain the set of formatted strings of the current line statement.
[0020] Optionally, it also includes: an analysis unit, used to analyze the current line statement based on its syntax structure and determine potential error types if the string set of any line statement is matched with two or more preset format string templates and no format string template matching the string set of the current line statement is found.
[0021] Optionally, it further includes: an adjustment unit, which adjusts the format of the obtained format string set according to the context after the processing unit performs format processing on the generated string set to obtain a corresponding format string set.
[0022] In another aspect, the present invention provides a storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the methods described above.
[0023] In another aspect, the present invention provides a computer device including a processor, a memory, and a computer program stored in the memory that can run on the processor, wherein the processor executes the program to implement the steps of any of the methods described above.
[0024] In another aspect, the present invention provides a computer device including any of the processing devices described above.
[0025] In another aspect, the present invention provides a computer program product, including a computer program that, when executed by a processor, implements the steps of any of the methods described above.
[0026] According to the technical solution of the present invention, by recognizing the pre-set delimiters, program statements can be segmented according to the actual syntax structure, and statements of different formats (instruction statements and variable statements) can be effectively recognized.
[0027] According to the technical solution of the present invention, by constructing and matching format string templates, various statement structures can be flexibly adapted, thereby improving the accuracy of formatting.
[0028] According to the technical solution of the present invention, by using line-by-line processing and wildcard replacement strategies, a formatted result that conforms to the specifications can be automatically generated, thereby improving the readability and parsing accuracy of the program. Attached Figure Description
[0029] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings: Figure 1 This is a schematic diagram of an embodiment of the program text processing method provided by the present invention; Figure 2 This diagram illustrates how statements in program text are segmented based on delimiters. Figure 3 This shows a specific example of splitting a statement into a set of strings based on a delimiter; Figure 4 A specific example of determining the type of each line of statements is shown; Figure 5 A diagram illustrating the formatting process of the matching statement is shown. Figure 6 This is a structural block diagram of an embodiment of the program text processing device provided by the present invention. Detailed Implementation
[0030] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0031] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0032] In related technologies, writing robot program instructions on a computer results in more complex instruction text. Some robots may be unable to recognize complex instruction text, leading to unpredictable consequences. Furthermore, a disordered order of instruction writing makes robot program reading unintuitive for users, hindering efficient robot programming.
[0033] This invention provides a method for processing program text. This method is particularly suitable for writing robot program instructions.
[0034] Figure 1 This is a schematic diagram of an embodiment of the program text processing method provided by the present invention.
[0035] like Figure 1 As shown, according to an embodiment of the present invention, the program text processing method includes at least steps S110, S120 and S130.
[0036] Step S110: Obtain the program text to be processed.
[0037] Specifically, after the user finishes editing the program and triggers the formatting operation, the program text that the user has edited is obtained.
[0038] Step S120: The statements in the program text are segmented according to the pre-set delimiters to generate corresponding string sets.
[0039] Specifically, a pre-set delimiter is retrieved, which is used to split program statements. The delimiter can be set by the user. For example, the user can set the delimiter and define the standard format of the programming statements in the system interface. There can be one or more delimiters. The delimiter can be a non-alphabetic symbol, such as at least one of a space, comma, and semicolon.
[0040] After obtaining the pre-set delimiter, the statements in the program text are segmented according to the delimiter to form a set of format strings. In one specific embodiment, the program text is split line by line. For each line of statements in the program text, it is segmented according to the pre-set delimiter to generate a string set for each line of statements. Specifically, for each line of statements, each character is read and cached in a character buffer. Whenever the pre-set delimiter is detected, the currently cached character is saved as a string unit to the string set, and the character buffer is cleared. The process of reading characters one by one continues until all characters of the current line of statements have been read, thus obtaining the string set of the current line of statements.
[0041] Figure 2 This diagram illustrates how statements in program text are segmented according to delimiters. (Reference) Figure 2 As shown, the program text includes variable configuration files and instruction configuration files, separated by spaces " ", commas "," and semicolons ";", beginning with the statement "MovJ ( <var>, <var>For example, ");" would be segmented into "MovJ", " ", "(", and " "". <var>”、",”、" <var>"," ",")",";",in," <var>The quotation mark (") represents any letter string, meaning it can match any combination of letter types. Space strings are not matched and are only used as statement formatting. Figure 3 This shows a concrete example of splitting a statement into a set of strings based on a delimiter. (Reference) Figure 3 As shown, using a space " " as the delimiter, the statement "BoolTest = TRUE;" will generate a string of characters within the box.
[0042] Step S130: Format the generated string set to obtain a corresponding formatted string set.
[0043] Specifically, the string set of each generated line of statement is formatted to obtain the formatted string set of each line of statement.
[0044] In one specific implementation, the string set of the current line statement is matched with two or more preset format string templates to determine the format string template that matches the string set of the current line statement; based on the determined format string template that matches the string set of the current line statement, the string set of the current line statement is formatted to obtain the format string of the current line statement.
[0045] Preferably, different statement types correspond to different format string templates. Matching the string set of the current line statement with two or more preset format string templates to determine the format string template that matches the string set of the current line statement can further include: first determining the statement type of the current line statement, and then, based on the determined statement type, matching the string set of the current line statement with the format string template corresponding to that statement type to determine the format string template that matches the string set of the current line statement. Variable statements and instruction statements handle the same symbol differently. For example, spaces are added before and after "=" in variable statements, but not in instruction statements. Furthermore, in some machine programming languages, variable statements can be placed at the beginning of the entire program file. Distinguishing statement types helps to achieve this better.
[0046] In one specific implementation, the first string of the string set of the current line statement is identified to determine the statement type. For example, it can be determined whether each line statement belongs to a variable statement, an instruction statement, or a statement that needs to be skipped. The first string of a variable statement indicates the type of the corresponding variable, and the first string of an instruction statement indicates the type of the corresponding instruction. Therefore, it is possible to confirm whether the statement belongs to the corresponding statement type by traversing the variable range and instruction range.
[0047] Figure 4 A concrete example of determining the type of each line of statements is shown. For example... Figure 4 As shown, the variable set includes "Bool", "String", and "Num", and the instruction set includes "Movc", "Movl", and "Movp". Therefore, the first line of the statement "BoolTest = TRUE;" has "Bool" as its first string, indicating it's a variable statement. The second line of the statement "BoolTest = TRUE;" has "BoolTest" as its first string, which is neither an instruction nor a variable statement, so it's determined to be a statement that needs to be skipped. The third line of the statement "NUMTest = TRUE;" has "NUM" as its first string, indicating it's a variable statement. The fourth line of the statement "Movc(A, B);" has "Movc" as its first string, indicating it's an instruction statement.
[0048] The formatted string template includes: a set of strings with a preset format, which includes: preset strings combined according to the preset format and wildcard strings. The wildcard strings can match strings containing all letter combinations. The string set of the current line is matched one by one with the preset formatted string template. During the matching process, case sensitivity and the use of Chinese and English punctuation are disregarded. After determining the formatted string template that matches the string set of the current line, the wildcard string in the formatted string template is replaced with the string at the corresponding position in the string set of the current line, thus obtaining the formatted string set of the current line.
[0049] For example, the wildcard string is " <var>The string can match any combination of letters to form a string. The set of strings to be formatted is "Bool Test=TRUE;", and the format string template that matches it is "Bool". <var>= <var>When the set of strings to be formatted is successfully matched, the semicolon in the matched format string template is used. <var>The string will be replaced with the corresponding string in the string to be formatted, generating a set of formatted strings. See the reference for the process. Figure 5 The diagram shows the formatting process of the matching statement.
[0050] According to the above embodiments of the present invention, each line of program instructions is processed sequentially, ultimately outputting program text that is uniformly formatted, clearly structured, and highly readable. When reading this formatted program, the robot controller can accurately identify the instruction structure, improving execution efficiency and stability.
[0051] Furthermore, if the string set of any line statement is matched with two or more preset format string templates, and no format string template matching the string set of the current line statement is found, then the current line statement is analyzed based on its syntax structure to determine the potential error type.
[0052] Specifically, if any line of statement fails to match, the system enters the error detection and correction phase. Based on the syntax structure, it analyzes the potential error types of the current line of statement. These potential error types may include, for example, at least one of the following: missing delimiter, missing parameters, or incorrect symbols. Simultaneously, suggested formats or interactive correction options can be provided for the user to choose from. For example, if the user enters "Bool test TRUE;", after splitting the string according to the delimiter, and determining that the first string is a variable statement, the system searches for a matching format string template in the variable statement's format string template. The matched format string template is "Bool <var>= <var>By comparing each ";", we can find that "TRUE" and "=" do not match, indicating that the equals sign may be missing, i.e., the parameter is missing. We can then prompt "parameter is missing" and also suggest the format: "Booltest = TRUE;".
[0053] Optionally, the error patterns of the current line of statements can be recorded in an error pattern library for subsequent optimization of formatting templates and improvement of matching accuracy.
[0054] Taking "Bool test TRUE;" as an example, the system defaults to reporting a missing parameter. Users can add the description of the error as "missing equal sign". Subsequent errors will then be reported as "missing equal sign", further improving accuracy.
[0055] Optionally, the generated string set is formatted to obtain a corresponding set of formatted strings. Then, the format of the obtained set of formatted strings is adjusted according to the context. That is, after obtaining the set of formatted strings for each line of the program text, the format of the string set for each line of the text is adjusted based on the context.
[0056] Specifically, after formatting all statements in the program text, the formatting rules for each line of statement are dynamically adjusted based on its context. For example, instructions within loop structures are automatically indented, and blank lines are added before and after conditional statements to enhance readability. By analyzing the program structure and intelligently adjusting formatting rules, the program logic becomes clearer, making it easier for humans to read and maintain.
[0057] The present invention also provides a program text processing device. This device is particularly suitable for writing robot program instructions.
[0058] Figure 6 This is a structural block diagram of an embodiment of the program text processing device provided by the present invention. Figure 6 As shown, the program text processing device 100 includes: an acquisition unit 110, a generation unit 120, and a processing unit 130.
[0059] Acquisition unit 110 is used to acquire the program text to be processed.
[0060] Specifically, after the user finishes editing the program and triggers the formatting operation, the program text that the user has edited is obtained.
[0061] The generation unit 120 is used to segment the statements in the program text according to a pre-set delimiter and generate a corresponding string set.
[0062] Specifically, a pre-set delimiter is retrieved, which is used to split program statements. The delimiter can be set by the user. For example, the user can set the delimiter and define the standard format of the programming statements in the system interface. There can be one or more delimiters. The delimiter can be a non-alphabetic symbol, such as at least one of a space, comma, and semicolon.
[0063] After obtaining the pre-set delimiter, the statements in the program text are segmented according to the delimiter to form a set of format strings. In one specific embodiment, the program text is split line by line. For each line of statements in the program text, it is segmented according to the pre-set delimiter to generate a string set for each line of statements. Specifically, for each line of statements, each character is read and cached in a character buffer. Whenever the pre-set delimiter is detected, the currently cached character is saved as a string unit to the string set, and the character buffer is cleared. The process of reading characters one by one continues until all characters of the current line of statements have been read, thus obtaining the string set of the current line of statements.
[0064] Figure 2 This diagram illustrates how statements in program text are segmented according to delimiters. (Reference) Figure 2 As shown, the program text includes variable configuration files and instruction configuration files, separated by spaces " ", commas "," and semicolons ";", and begins with the statement "MovJ ( <var>, <var>For example, ");" would be segmented into "MovJ", " ", "(", and " "". <var>”、",”、" <var>"," ",")",";",in," <var>The quotation mark (") represents any letter string, meaning it can match any combination of letter types. Space strings are not matched and are only used as statement formatting. Figure 3 This shows a concrete example of splitting a statement into a set of strings based on a delimiter. (Reference) Figure 3 As shown, using a space " " as the delimiter, the statement "BoolTest = TRUE;" will generate a string of characters within the box.
[0065] The processing unit 130 is used to format the string set generated by the generation unit to obtain a corresponding formatted string set.
[0066] Specifically, the string set of each generated line of statement is formatted to obtain the formatted string set of each line of statement.
[0067] In one specific implementation, the string set of the current line statement is matched with two or more preset format string templates to determine the format string template that matches the string set of the current line statement; based on the determined format string template that matches the string set of the current line statement, the string set of the current line statement is formatted to obtain the format string of the current line statement.
[0068] Preferably, different statement types correspond to different format string templates. Matching the string set of the current line statement with two or more preset format string templates to determine the format string template that matches the string set of the current line statement can further include: first determining the statement type of the current line statement, and then, based on the determined statement type, matching the string set of the current line statement with the format string template corresponding to that statement type to determine the format string template that matches the string set of the current line statement. Variable statements and instruction statements handle the same symbol differently. For example, spaces are added before and after "=" in variable statements, but not in instruction statements. Furthermore, in some machine programming languages, variable statements can be placed at the beginning of the entire program file. Distinguishing statement types helps to achieve this better.
[0069] In one specific implementation, the first string of the string set of the current line statement is identified to determine the statement type. For example, it can be determined whether each line statement belongs to a variable statement, an instruction statement, or a statement that needs to be skipped. The first string of a variable statement indicates the type of the corresponding variable, and the first string of an instruction statement indicates the type of the corresponding instruction. Therefore, it is possible to confirm whether the statement belongs to the corresponding statement type by traversing the variable range and instruction range.
[0070] Figure 4 A concrete example of determining the type of each line of statements is shown. For example... Figure 4 As shown, the variable set includes "Bool", "String", and "Num", and the instruction set includes "Movc", "Movl", and "Movp". Therefore, the first line of the statement "BoolTest = TRUE;" has "Bool" as its first string, indicating it's a variable statement. The second line of the statement "BoolTest = TRUE;" has "BoolTest" as its first string, indicating it's a statement that needs to be skipped. The third line of the statement "NUM Test = TRUE;" has "NUM" as its first string, indicating it's a variable statement. The fourth line of the statement "Movc(A, B);" has "Movc" as its first string, indicating it's an instruction statement.
[0071] The formatted string template includes: a set of strings with a preset format, which includes: preset strings combined according to the preset format and wildcard strings. The wildcard strings can match strings containing all letter combinations. The string set of the current line is matched one by one with the preset formatted string template. During the matching process, case sensitivity and the use of Chinese and English symbols are disregarded. After determining the formatted string template that matches the string set of the current line, the wildcard string in the formatted string template is replaced with the string at the corresponding position in the string set of the current line, thus obtaining the formatted string set of the current line.
[0072] For example, the wildcard string is " <var>The string can match any combination of letters to form a string. The set of strings to be formatted is "Bool Test=TRUE;", and the format string template that matches it is "Bool". <var>= <var>When the set of strings to be formatted is successfully matched, the semicolon in the matched format string template is used. <var>The string will be replaced with the corresponding string in the string to be formatted, generating a set of formatted strings. See the reference for the process. Figure 5 The diagram shows the formatting process of the matching statement.
[0073] According to the above embodiments of the present invention, each line of program instructions is processed sequentially, ultimately outputting program text that is uniformly formatted, clearly structured, and highly readable. When reading this formatted program, the robot controller can accurately identify the instruction structure, improving execution efficiency and stability.
[0074] Optionally, the device 100 further includes an analysis unit (not shown), configured to analyze the current line statement based on its syntax structure and determine potential error types if the string set of any line statement is matched with two or more preset format string templates and no format string template matching the string set of the current line statement is found.
[0075] Specifically, if any line of statement fails to match, the system enters the error detection and correction phase. Based on the syntax structure, it analyzes the potential error types of the current line of statement. These potential error types may include, for example, at least one of the following: missing delimiter, missing parameters, or incorrect symbols. Simultaneously, suggested formats or interactive correction options can be provided for the user to choose from. For example, if the user enters "Bool test TRUE;", after splitting the string according to the delimiter, and determining that the first string is a variable statement, the system searches for a matching format string template in the variable statement's format string template. The matched format string template is "Bool <var>= <var>By comparing each ";", we can find that "TRUE" and "=" do not match, indicating that the equals sign may be missing, i.e., the parameter is missing. We can then prompt "parameter is missing" and also suggest the format: "Booltest = TRUE;".
[0076] Optionally, the analysis unit can also record the error patterns of the current line statement to an error pattern database for subsequent optimization of formatting templates and improvement of matching accuracy. Taking "Bool test TRUE;" as an example, the system defaults to reporting a missing parameter error. Users can supplement the error description as "missing equal sign," and subsequent encounters with the corresponding error will be reported as "missing equal sign," further improving accuracy.
[0077] Optionally, the apparatus 100 further includes an adjustment unit (not shown), configured to adjust the format of the generated string set according to the context after the processing unit performs formatting processing on the string set to obtain a corresponding formatted string set. That is, after obtaining the formatted string set for each line of the program text, the string set for each line of the statement is formatted in conjunction with the context.
[0078] Specifically, after formatting all statements in the program text, the formatting rules for each line of statement are dynamically adjusted based on its context. For example, instructions within loop structures are automatically indented, and blank lines are added before and after conditional statements to enhance readability. By analyzing the program structure and intelligently adjusting formatting rules, the program logic becomes clearer, making it easier for humans to read and maintain.
[0079] The present invention also provides a storage medium corresponding to the program text processing method, wherein a computer program is stored thereon, and when the program is executed by a processor, it implements the steps of any of the aforementioned methods.
[0080] The present invention also provides a computer device corresponding to the program text processing method, including a processor, a memory, and a computer program stored in the memory that can run on the processor, wherein the processor executes the program to implement the steps of any of the aforementioned methods.
[0081] The present invention also provides a computer device corresponding to the program text processing apparatus, including any of the aforementioned program text processing apparatuses.
[0082] The present invention also provides a computer program product corresponding to the program text processing method, comprising a computer program that, when executed by a processor, implements the steps of any of the aforementioned methods.
[0083] Accordingly, the solution provided by this invention performs statement segmentation based on pre-set delimiters to achieve automatic recognition of statement structure and construction of format string sets; introduces a wildcard-based statement matching and replacement mechanism to improve format adaptation capability; and adopts line-by-line processing and character caching technology to achieve efficient formatting processing of program text, supports unified recognition of uppercase and lowercase letters and Chinese and English symbols, and enhances system compatibility and robustness.
[0084] The functions described herein can be implemented in hardware, software executed by a processor, firmware, or any combination thereof. If implemented in software executed by a processor, the functions can be stored as one or more instructions or codes on or transmitted via a computer-readable medium. Other examples and embodiments are within the scope and spirit of this invention and the appended claims. For example, due to the nature of software, the functions described above can be implemented using software executed by a processor, hardware, firmware, hardwired, or any combination thereof. Furthermore, the functional units can be integrated into a single processing unit, or each unit can exist physically separately, or two or more units can be integrated into a single unit.
[0085] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0086] The units described as separate components may or may not be physically separate. Similarly, the components of the control device may or may not be physical units; they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0087] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to related technologies, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0088] The above description is merely an embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of the claims of the present invention.< / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var> < / var>
Claims
1. A method for processing program text, characterized in that, include: Obtain the program text to be processed; The program text is segmented according to a pre-set delimiter to generate a corresponding string set; The generated string set is formatted to obtain a corresponding formatted string set.
2. The method according to claim 1, characterized in that, The program text is segmented according to a pre-set delimiter to generate a corresponding string set, including: The program text is split line by line. For each line of the program text, it is split according to the pre-set delimiter to generate a string set for each line of the text.
3. The method according to claim 2, characterized in that, For each line of statement in the program text, it is split according to the preset delimiter to generate a string set for each line of statement, including: For each line of statement, read each character one by one and cache them in the character buffer. Whenever the pre-set delimiter is detected, save the currently cached character as a string unit to the string set and clear the character buffer. Continue reading each character one by one until all characters of the current line of statement have been read, and obtain the string set of the current line of statement.
4. The method according to claim 2 or 3, characterized in that, The generated string set is formatted to obtain a corresponding set of formatted strings, including: The string set of each generated line of statement is formatted to obtain the formatted string set of each line of statement.
5. The method according to claim 4, characterized in that, The string set for each generated line of statement is formatted to obtain a set of formatted strings for each line of statement, including: Match the string set of the current line statement with two or more preset format string templates to determine the format string template that matches the string set of the current line statement; Based on the determined format string template that matches the string set of the current line statement, the string set of the current line statement is formatted to obtain the format string of the current line statement.
6. The method according to claim 5, characterized in that, Match the string set of the current line statement with two or more predefined format string templates to determine the format string template that matches the string set of the current line statement, including: First, determine the statement type of the current line statement. Then, match the string set of the current line statement with the format string template corresponding to the statement type of the current line statement to determine the format string template that matches the string set of the current line statement.
7. The method according to claim 5 or 6, characterized in that, The formatted string template includes: a set of strings with preset formats; the set of strings with preset formats includes preset strings combined according to preset formats and wildcard strings; the wildcard strings can match strings with all letter combinations. Based on the determined format string template that matches the string set of the current line statement, the string set of the current line statement is formatted to obtain the format string of the current line statement, including: The wildcard string in the format string template that matches the string set of the current line statement is replaced with the string at the corresponding position in the string set of the current line statement, thus obtaining the format string set of the current line statement.
8. The method according to claim 2 or 3, characterized in that, Also includes: If the string set of any line statement is matched with two or more preset format string templates, and no format string template matching the string set of the current line statement is found, then the current line statement is analyzed based on its syntax structure to determine the potential error type.
9. The method according to any one of claims 1-3, characterized in that, Also includes: The generated string set is formatted to obtain a corresponding set of formatted strings. The format of the obtained set of formatted strings is then adjusted according to the context.
10. A program text processing device, characterized in that, include: The acquisition unit is used to acquire the program text to be processed; The generation unit is used to segment the statements in the program text according to a pre-set delimiter and generate a corresponding string set; The processing unit is used to format the string set generated by the generation unit to obtain a corresponding formatted string set.
11. A storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the steps of the method according to any one of claims 1-9.
12. A computer device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory that can run on the processor, wherein the processor executes the program to implement the steps of any of the methods of claims 1-9, or includes the processing apparatus of claim 10.
13. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the steps of the method according to any one of claims 1-9.