Operating method and operating device for programming language character string

By checking object types and creating variable object classes in the abstract syntax tree of C++ language programs, using operator processors and functional functions to operate strings, the problem of high complexity of string operation in C++ language programs is solved, reducing the compilation time cost, and improving the compilation flexibility and stability of programming language programs.

CN120406953APending Publication Date: 2025-08-01BEIJING SIMING QICHUANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510495204.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-18
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

In C++ programming language programs, string operation is complex, especially after cross-platform conversion processing, it is difficult to adapt to younger students, and the difficulty of operation increases the time cost of programming language compilation.

Method used

By checking object types in the abstract syntax tree of programming language programs and creating variable object classes, temporarily storing target variables, using operator processors and functional functions to operate, reduce underlying details interference, and focus on core logic.

Benefits of technology

It reduces the difficulty of programming language string operation, reduces the cost of compilation time, and improves the compilation flexibility and stability of programming language programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120406953A_ABST
    Figure CN120406953A_ABST
Patent Text Reader

Abstract

The invention provides an operation method and device for a programming language character string, and the method comprises the steps: carrying out the interpretive execution of an abstract syntax tree corresponding to an externally inputted programming language program, calling a definition variable component to check whether the object type of each object in the abstract syntax tree is a target character string type or not; for a target variable under each target object of which the object type is the target character string type, creating a variable object class and temporarily storing the target variable into the variable object class so as to mark and declarate the target variable; and in the variable object class, based on an operation mode corresponding to the logic execution statement, calling a performance function corresponding to the operator processor or the target character string type to perform operation for the target object. Through the method, the difficulty of operating the programming language character string is reduced, and the time cost of programming language compiling by developers or users is further reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of programming languages, and particularly to a method and device for operating on programming language strings. Background Art

[0002] After performing cross-platform conversion processing on a programming language program including the C++ language, since the standard library of the C++ language does not provide a string class and the operations on strings are encapsulated, for example, in the teaching scenario of the C++ language programming language, the complexity of operating on strings is relatively high and it is difficult to adapt to young students.

[0003] Currently, in a programming language program including the C++ language, there is no alternative method for operating on strings. For various programming language usage scenarios, the operations on strings after cross-platform conversion processing are essential. For example, for the "char" type of a string, statements must be written to specify the array size and ensure that the array does not go out of bounds. To concatenate a "char" type of string, other operation methods need to be referenced and the operator cannot be directly used for operation. This greatly increases the difficulty of operating on programming language strings, and further increases the time cost for developers or users to perform programming language compilation. Summary of the Invention

[0004] In view of this, the purpose of this application is to provide a method and device for operating on programming language strings. During the process of interpreting and executing the abstract syntax tree corresponding to an externally input programming language program, it is checked whether the object type of each object is the target string type to determine the target variable under each target object, and the target variable is temporarily stored in the created variable object class to mark and declare the target variable. Then, the operations on the target object are performed according to the operation method corresponding to the logical execution statement, enabling developers or users to focus on the core logic of operating on strings rather than being disturbed by the complex implementation of underlying details, reducing the difficulty of operating on programming language strings, and further reducing the time cost for developers or users to perform programming language compilation.

[0005] An embodiment of this application provides a method for operating on programming language strings, and the operation method includes:

[0006] During the process of interpreting and executing the abstract syntax tree corresponding to an externally input programming language program by using a preset running component, a preset variable definition component is called to check whether the object type of each object in the abstract syntax tree is the target string type;

[0007] For each target variable under each target object whose object type is the target string type, create a variable object class and temporarily store the target variable in the variable object class to mark and declare the target variable;

[0008] In the variable object class, in response to the programming language program being interpreted and executed to the logical execution statement for the target object, based on the operation mode corresponding to the logical execution statement, call a preset operator processor or a function corresponding to the target string type to perform an operation on the target object.

[0009] Further, the following steps are used to interpret and execute the abstract syntax tree corresponding to the externally input programming language program by using a preset running component:

[0010] In response to obtaining an externally input programming language program, use a preset cross-platform parsing tool to compile a predefined syntax file to obtain a parsing file corresponding to the cross-platform parsing tool;

[0011] Use the parsing file and the cross-platform parsing tool to parse and transform the programming language program to generate an abstract syntax tree corresponding to the programming language program;

[0012] For each object included in the abstract syntax tree, based on the recursive access function corresponding to the object type of each object, use a preset running component to interpret and execute the expression under each object type.

[0013] In this way, by interpreting and executing the abstract syntax tree corresponding to the externally input programming language program, the compilation flexibility of the programming language program can be improved, and the comprehensiveness and stability of debugging the programming language program can be improved.

[0014] Further, the step of calling a preset variable definition component to check whether the object type of each object in the abstract syntax tree is the target string type includes:

[0015] Use a preset definition function to call and execute a preset variable definition component to determine the name attribute corresponding to the object type of each object in the abstract syntax tree through the variable definition component;

[0016] Check whether the name attribute of each object is the target string type;

[0017] If the name attribute of the object is the target string type, determine the object as a target object.

[0018] In this way, by checking whether the name attribute of each of the said objects is of the target string type, it is beneficial for the user to accurately determine the target string in the programming language and perform corresponding operations on the target string.

[0019] Furthermore, for each target variable under each target object whose object type is the target string type, creating a variable object class and temporarily storing the target variable in the variable object class to make a labeled declaration for the target variable includes:

[0020] For each target variable under each target object whose object type is the target string type, creating a variable object class; wherein, the variable object class includes a type attribute and a variable data attribute;

[0021] Temporarily storing the target variable in the variable object class to make a labeled declaration for the target variable;

[0022] Storing the variable object class in a preset virtual memory according to the keyword format corresponding to the variable object class.

[0023] In this way, by temporarily storing the target variable in the variable object class and storing the variable object class in a preset virtual memory to make a labeled declaration for the target variable, it not only helps to improve the quality and maintainability of the program, but also lays a good foundation for subsequent function expansion and performance optimization.

[0024] Furthermore, in the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, based on the operation mode corresponding to the logical execution statement, calling a preset operator processor or a function corresponding to the target string type to perform an operation on the target object includes:

[0025] In the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, determining the operation mode corresponding to the logical execution statement;

[0026] In response to the operation mode being an operator operation, determining the operator included in the logical execution statement and calling a preset operator processor to perform an operation on the target object corresponding to the operator;

[0027] In response to the operation mode being a logical function operation, determining the function class corresponding to the target string type included in the logical execution statement and calling the function corresponding to the function class to perform an operation on the target object corresponding to the function class.

[0028] In this way, by performing operations corresponding to statements based on the logic, calling a preset operator processor or a function corresponding to the target string type to perform operations on the target object, the feasibility and stability of performing corresponding operations on the target object can be improved.

[0029] Further, the operation of calling a preset operator processor to perform an operation corresponding to the operator on the target object includes:

[0030] When the operator is an equality comparison operator, call a preset operator processor to perform an array comparison on the target object to determine whether the contents of the target object are the same, and return the determination result;

[0031] When the operator is a string concatenation operator, call a preset operator processor to convert the target object into a target string and concatenate the target strings;

[0032] When the operator is an assignment operator, convert the value of the right operand in the target object into the type of the left operand in the target object using a preset conversion function, and assign the value of the right operand to the left operand.

[0033] In this way, by performing an operation corresponding to the operator on the target object through a preset operator processor, the accuracy and stability of performing an operation corresponding to the operator on the target object can be ensured under different operation requirements.

[0034] Further, register the function corresponding to the target string type in advance through the following steps:

[0035] Determine the function corresponding to each logical function operation among multiple logical function operations;

[0036] Use a preset class mounting method to correspond and bind the function class corresponding to the target string type with the function to register the function to the target string type.

[0037] In this way, by registering the function corresponding to the target string type in advance, the accuracy and efficiency of the operation can be better improved when performing corresponding operations on the target object.

[0038] The embodiment of the present application also provides an operation device for a programming language string, and the operation device includes:

[0039] ​

[0040] A variable marking module, which is used to create a variable object class for each target variable under each target object whose object type is the target string type, and temporarily store the target variable in the variable object class to make a marking declaration for the target variable;

[0041] A string operation module, which is used to, in the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, based on the operation method corresponding to the logical execution statement, call a preset operator processor or a function corresponding to the target string type to perform an operation on the target object.

[0042] Further, when the string checking module is used to interpret and execute the abstract syntax tree corresponding to an externally input programming language program by using a preset running component, the string checking module is used to:

[0043] In response to obtaining an externally input programming language program, compile a predefined syntax file by using a preset cross-platform parsing tool to obtain a parsing file corresponding to the cross-platform parsing tool;

[0044] Use the parsing file and the cross-platform parsing tool to parse and transform the programming language program to generate an abstract syntax tree corresponding to the programming language program;

[0045] For each object included in the abstract syntax tree, based on the recursive access function corresponding to the object type of each object, use a preset running component to interpret and execute the expressions under each object type.

[0046] Further, when the string checking module is used to call a preset defined variable component to check whether the object type of each object in the abstract syntax tree is the target string type, the string checking module is used to:

[0047] Use a preset defined function to call and execute a preset defined variable component to determine the name attribute corresponding to the object type of each object in the abstract syntax tree through the defined variable component;

[0048] Check whether the name attribute of each object is the target string type;

[0049] If the name attribute of the object is the target string type, determine the object as a target object.

[0050] Further, when the variable marking module is used to create a variable object class for each target variable under each target object of which the object type is the target string type, and temporarily store the target variable in the variable object class to perform a marking declaration on the target variable, the variable marking module is used for:

[0051] Create a variable object class for each target variable under each target object of which the object type is the target string type; wherein, the variable object class includes a type attribute and a variable data attribute;

[0052] Temporarily store the target variable in the variable object class to perform a marking declaration on the target variable;

[0053] Store the variable object class in a preset virtual memory according to the keyword format corresponding to the variable object class.

[0054] Further, when the string operation module is used to, in the variable object class, in response to the programming language program interpreting and executing to a logical execution statement for the target object, based on the operation method corresponding to the logical execution statement, call a preset operator processor or a function function corresponding to the target string type to perform an operation on the target object, the string operation module is used for:

[0055] In the variable object class, in response to the programming language program interpreting and executing to a logical execution statement for the target object, determine the operation method corresponding to the logical execution statement;

[0056] In response to the operation method being an operator operation, determine the operator included in the logical execution statement, and call a preset operator processor to perform an operation corresponding to the operator on the target object;

[0057] In response to the operation method being a logical function operation, determine the function class corresponding to the target string type included in the logical execution statement, and call the function function corresponding to the function class to perform an operation corresponding to the function class on the target object.

[0058] Further, when the string operation module is used to call a preset operator processor to perform an operation corresponding to the operator on the target object, the string operation module is used for:

[0059] When the operator is an equality comparison operator, call a preset operator processor to perform an array comparison on the target object to determine whether the contents of the target object are the same, and return a judgment result;

[0060] When the operator is a string concatenation operator, call a preset operator processor to convert the target object into a target string, and concatenate the target strings;

[0061] When the operator is an assignment operator, use a preset conversion function to convert the value of the right operand in the target object into the type of the left operand in the target object, and assign the value of the right operand to the left operand.

[0062] Further, when the string operation module is used to pre-register a function corresponding to the target string type, the string operation module is used to:

[0063] Determine a function corresponding to each logical function operation among multiple logical function operations;

[0064] Use a preset class mounting method to bind the function class corresponding to the target string type to the function, so as to register the function to the target string type.

[0065] An embodiment of the present application further provides an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps of the operation method of the programming language string as described above are executed.

[0066] An embodiment of the present application further provides a computer-readable storage medium. A computer program is stored on the computer-readable storage medium. When the computer program is run by a processor, the steps of the operation method of the programming language string as described above are executed.

[0067] The operation method and operation device of the programming language string provided by the embodiment of the present application. The operation method includes: in the process of interpreting and executing an abstract syntax tree corresponding to an externally input programming language program by using a preset running component, calling a preset definition variable component to check whether the object type of each object in the abstract syntax tree is a target string type; for each target variable under each target object whose object type is a target string type, create a variable object class, and temporarily store the target variable in the variable object class to mark and declare the target variable; in the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, based on the operation mode corresponding to the logical execution statement, call a preset operator processor or a function corresponding to the target string type to perform an operation on the target object.

[0068] Compared with the methods with relatively high complexity of operating using string types such as "char" and "wchar_t" in the prior art, by checking whether the object type of each object is the target string type during the process of interpreting and executing the abstract syntax tree corresponding to the programming language program of the external input, to determine the target variables under each target object, and temporarily storing the target variables into the created variable object class to mark and declare the target variables, and then performing operations on the target objects according to the operation modes corresponding to the logical execution statements, enabling developers or users to focus on the core logic of operating strings rather than being interfered by the complex implementation of underlying details, reducing the difficulty of operating programming language strings, and further reducing the time cost of developers or users for programming language compilation.

[0069] To make the above objects, features, and advantages of the present application more obvious and understandable, the following specifically gives preferred embodiments and, in conjunction with the accompanying drawings, makes a detailed description as follows. Brief Description of the Drawings

[0070] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present application and should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.

[0071] Figure 1 It is a flowchart of a method for operating programming language strings provided by an embodiment of the present application;

[0072] Figure 2 It is a schematic structural diagram of an apparatus for operating programming language strings provided by an embodiment of the present application;

[0073] Figure 3 It is a schematic structural diagram of an electronic device provided by an embodiment of the present application. Detailed Embodiments

[0074] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of this application. Apparently, the described embodiments are only a part rather than all of the embodiments of this application. Components of the embodiments of this application described and illustrated in the accompanying drawings here can be arranged and designed in various different configurations. Therefore, the detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. Based on the embodiments of this application, every other embodiment obtained by those skilled in the art without creative efforts belongs to the scope of protection of this application.

[0075] Through research, it is found that currently, in programming language programs including the C++ language, there is no alternative method for string operation methods, which is very important for various programming language usage scenarios. Operations on strings after cross-platform conversion are also essential. For example, for the "char" type of strings, statements must be written to specify the array size and ensure that the array does not go out of bounds. To concatenate "char"-type strings, other operation methods need to be referenced, and operators cannot be directly used for operations. This greatly increases the difficulty of operating on programming language strings, and further increases the time cost for developers or users to compile programming languages.

[0076] Based on this, the embodiments of this application provide an operation method for programming language strings. During the process of interpreting and executing the abstract syntax tree corresponding to an externally input programming language program, it is checked whether the object type of each object is the target string type to determine the target variables under each target object, and the target variables are temporarily stored in the created variable object class to mark and declare the target variables. Then, operations on the target objects are performed according to the operation methods corresponding to the logical execution statements, enabling developers or users to focus on the core logic of operating strings rather than being interfered by the complex implementation of underlying details, reducing the difficulty of operating on programming language strings, and further reducing the time cost for developers or users to compile programming languages.

[0077] Please refer to Figure 1 , Figure 1 which is a flowchart of an operation method for programming language strings provided by the embodiments of this application. As Figure 1 shown in

[0078] S101. During the process of interpreting and executing the abstract syntax tree corresponding to an externally input programming language program using a preset running component, call a preset variable definition component to check whether the object type of each object in the abstract syntax tree is the target string type.

[0079] It should be noted that the operation method of the programming language string provided in the embodiments of the present application is generally applied to a programming language interpreter that can run in a JavaScript environment. Through the cross-platform characteristics of the Web in the JavaScript environment, cross-platform operation can be achieved, and the language interface can be unified across multiple platforms. For example, the programming language interpreter supports running on the browser of a Pad or executing in WeChat H5.

[0080] Among them, the programming language interpreter running in the JavaScript environment refers to a tool or library that can convert the code of other programming languages into JavaScript code and execute it in the JavaScript runtime environment.

[0081] In the embodiments of the present application, the programming language program includes, but is not limited to, C language programs, C++ language programs, C# language programs, etc.

[0082] Here, the preset running component is a running tool or compiler that interprets and executes the abstract syntax tree corresponding to the programming language program, and is used to provide a common running component interface for the abstract syntax tree corresponding to the programming language program. For example, type conversion, type verification, value comparison, throwing exceptions, etc.

[0083] In the embodiments of the present application, the abstract syntax tree (AST) corresponding to the programming language program is a data structure, usually used to represent the syntax structure of source code (programming languages, markup languages, etc.). It is a tree structure, and the nodes in it represent elements in the syntax structure, such as variables, function calls, operators, etc.

[0084] In an implementation manner of the present application, in specific implementation, the step of using a preset running component to interpret and execute the abstract syntax tree corresponding to an externally input programming language program in step S101 may include:

[0085] S1011. In response to obtaining an externally input programming language program, use a preset cross-platform parsing tool to compile a predefined syntax file to obtain a parsing file corresponding to the cross-platform parsing tool.

[0086] In the embodiments of the present application, the preset cross-platform parsing tool includes a PEG.js tool. The PEG.js tool is a JavaScript parser generator that provides a PEG.js language (Parser Expression Grammar JavaScript). The PEG.js language is a language for defining syntax parsers and generates parser code that can be directly used in JavaScript. For example, to generate a js file, first define a syntax rule for PEG.js, and then use the compiler of PEG.js to compile it into JavaScript code.

[0087] In this way, the PEG.js tool can parse and generate a cross-platform programming language program from the compiled file according to the parsing expression grammar (PEG) provided by the PEG.js tool, enabling developers to easily create parsers for parsing specific languages or formats, thus simplifying language processing tasks.

[0088] In this step, in specific implementation, first, in response to obtaining a programming language program input externally, a syntax file corresponding to the cross-platform parsing tool is predefined and created; then, the predefined syntax file is compiled using the cross-platform parsing tool; finally, a parsing file corresponding to the cross-platform parsing tool is obtained.

[0089] As an example of predefined and creating a syntax file corresponding to a cross-platform parsing tool, when the syntax file is an "ast.pegjs" file, part of the content of the syntax file includes: "{function buildRecursiveBinop(a, b) { var ret = a; for (var i = 0; i < b.length; i++) { ret = addPositionInfo({ type: 'BinOpExpression', left: ret, op: b[i][0], right: b[i][1]});} return ret;};".

[0090] In the embodiments of the present application, when using the "pegjs ast.pegjs ast.js" command and using the cross-platform parsing tool to compile the predefined syntax file, the parsing file "ast.js" is obtained.

[0091] S1012. Use the parsing file and the cross-platform parsing tool to parse and convert the programming language program to generate an abstract syntax tree corresponding to the programming language program.

[0092] In this step, in specific implementation, first, the generated parsing file is introduced, and a cross-platform parsing tool is called; then, the programming language program is parsed and converted using the parsing file and the cross-platform parsing tool to generate an abstract syntax tree corresponding to the programming language program; finally, it is determined whether there are any lexical errors during the parsing process.

[0093] In the embodiment of the present application, the generated parsing file is introduced through the statement "const ast = require(' / ast.js'); const code;" the cross-platform parsing tool is called through the statement "import * as PEGUtil from \"pegjs-util\";" the abstract syntax tree corresponding to the programming language program is generated through the statement "const result = PEGUtil.parse(ast, code); interpreter.run(result.ast, code);"

[0094] Among them, "result.ast" represents the abstract syntax tree corresponding to the programming language program; result.ast is the AST abstract syntax tree parsed by the cross-platform parsing tool peg.JS, and a JS iterator object (Generator Function, which can pause during the step-by-step execution and resume execution later) can be obtained through the "interpreter.run" method.

[0095] Here, when the abstract syntax tree is logically running, the lexical units (such as operators, expressions, method calls, etc.) in the abstract syntax tree are repeatedly parsed and executed through the iterator object (Generator Function). The relationship between each lexical unit is a tree structure, and the call form of each lexical unit is a method call.

[0096] S1013. For each object included in the abstract syntax tree, based on the recursive access function corresponding to the object type of each object, the expressions under each object type are interpreted and executed using a preset running component.

[0097] In the embodiment of the present application, since the abstract syntax tree is a tree structure and includes multiple layers, and each layer is an object, and each object corresponds to an object type, therefore, the abstract syntax tree includes multiple object types. Among them, the object type represents the expressions and their parameters included in this layer in the abstract syntax tree.

[0098] For example, assume that a certain layer of the abstract syntax tree includes 4 object types, specifically including: the TranslationUnit, FunctionDefinition, ExpressionStatement, and JumpStatement_return object types; among them, "TranslationUnit" is an inherent entry, indicating that the program starts to enter the interpretation unit; "FunctionDefinition" refers to the declaration of a function; "ExpressionStatement" refers to the declaration of a cout statement; and JumpStatement_return refers to the return value.

[0099] In this step, in specific implementation, first, for the multiple first object types corresponding to the domain program in the abstract syntax tree, based on the recursive access function corresponding to each first object type, call a preset running component to loop-interpret and execute the expressions under each first object type, obtaining a second execution result and a registration method for caching; then, use the running component to cache the registration method, and based on the second execution result, determine whether there is an error in the domain program. If there is an error, directly throw an exception; finally, if there is no error in the domain program, for the multiple second object types corresponding to the entry main function program in the abstract syntax tree, based on the recursive access function corresponding to each second object type, call the running component to interpret and execute the expressions under each second object type.

[0100] In an implementation manner of the present application, in specific implementation, the step of calling a preset definition variable component in step S101 to check whether the object type of each object in the abstract syntax tree is the target string type may include:

[0101] S1014. Use a preset definition function to call and execute a preset definition variable component to determine the name attribute corresponding to the object type of each object in the abstract syntax tree through the definition variable component.

[0102] In an embodiment of the present application, the definition function may include a "defFunc function" for defining a function corresponding to a string and registering or reloading it into each object of the abstract syntax tree.

[0103] Among them, the definition variable component may include a "defVar" component for defining and initializing variables of multiple objects and defining the name attribute corresponding to the object type of each object.

[0104] Exemplarily, the name attribute corresponding to the object type of each object in the abstract syntax tree, that is, the "name" of the value of "type" defined in "AST".

[0105] S1015. Check whether the name attribute of each object is of the target string type.

[0106] In the embodiments of the present application, the target string type may include, but is not limited to, a "string" type. The "string" type is used to represent a class of strings. The "string" type is immutable. That is, once a "string" object is created, its value cannot be changed. Any operation on a "string" string (such as concatenation, replacement, etc.) will generate a new "string" object without modifying the original object.

[0107] In this way, based on the target string type, it is beneficial for users to operate on strings in programming languages.

[0108] Exemplarily, if the name attribute corresponding to the object type of each object defined in the abstract syntax tree is "string", it indicates that the syntax used in the code of the programming language program is "string variableName = xxx"; in this way, it can be determined whether the type of the code of the programming language program at the lexical stage is "string" by checking whether the name attribute corresponding to the object type of each object in the abstract syntax tree is "string".

[0109] S1016. If the name attribute of the object is of the target string type, determine the object as a target object.

[0110] In this step, if the name attribute of the object defined in the abstract syntax tree is of the target string type, it indicates that operations under the embodiments of the present application can be performed on the string type of the object, that is, determine the object as a target object.

[0111] S102. For each target variable under each target object whose object type is of the target string type, create a variable object class and temporarily store the target variable in the variable object class to make a marker declaration for the target variable.

[0112] In the embodiments of the present application, the purposes of making a marker declaration for the target variable may include: standardizing the storage format, unifying the storage methods of all string variables, facilitating subsequent processing and parsing; quickly retrieving, positioning, and operating on variables; adapting to different context requirements. If the program logic needs to process strings according to different scopes or contexts, this structured storage method provides flexibility.

[0113] In an implementation manner of the present application, in specific implementation, step S102 may include:

[0114] S1021. Create a variable object class for each target variable under each target object whose object type is the target string type; wherein, the variable object class includes a type attribute and a variable data attribute.

[0115] In an embodiment of the present application, the variable object class may include a "VariableObject" class, which is used to encapsulate the specific information of each target variable under each target object. The variable object class includes a type attribute and a variable data attribute; wherein, the variable data attribute stores the binary data after UTF-8 encoding of the string.

[0116] S1022. Temporarily store the target variable in the variable object class to make a marker declaration for the target variable.

[0117] In this step, the target variable under each target object is temporarily stored in the created variable object class, that is, a reference stored in virtual memory, to temporarily store the current variable and make a marker declaration for the target variable, so as to facilitate the instructions of the programming language program to read or modify the target variable.

[0118] S1023. Store the variable object class in a preset virtual memory according to the keyword format corresponding to the variable object class.

[0119] In an embodiment of the present application, the target variable is temporarily stored in the variable object class ("VariableObject" class), and the variable object class is stored in a preset virtual memory (for example, runtime.scope) according to the keyword format (key) corresponding to the variable object class; wherein runtime.scope simulates a simple runtime scope manager and can add and retrieve variables in different scopes.

[0120] Exemplarily, assuming that a variable "test" is created in the main function, the storage format should be "scope:[{\"main\":variables:{test:VariableObject}}]".

[0121] S103. In the variable object class, in response to the programming language program interpreting and executing a logic execution statement for the target object, based on the operation mode corresponding to the logic execution statement, call a preset operator processor or a function corresponding to the target string type to perform an operation on the target object.

[0122] In this step, after temporarily storing the target variables under each object in the abstract syntax tree into the variable object class to mark and declare the target variables, in response to the programming language program being interpreted and executed to the logical execution statement for the target object, determine the operation mode corresponding to the logical execution statement, which includes an operator or a functional class; then, perform the operation on the target object corresponding to the target string type.

[0123] In the embodiment of the present application, the operation mode corresponding to the logical execution statement may include, but is not limited to, operator operations and logical function operations.

[0124] In an implementation manner of the present application, in specific implementation, step S103 may include:

[0125] S1031. In the variable object class, in response to the programming language program being interpreted and executed to the logical execution statement for the target object, determine the operation mode corresponding to the logical execution statement.

[0126] In this step, when interpreting and executing the logical execution statement of the target object in the programming language program in the variable object class, determine the operation mode corresponding to the logical execution statement according to the code content of the logical execution statement.

[0127] Among them, the operation mode may include, but is not limited to, operator operations and logical function operations.

[0128] S1032. In response to the operation mode being an operator operation, determine the operator included in the logical execution statement, and call a preset operator processor to perform the operation corresponding to the operator on the target object.

[0129] In the embodiment of the present application, the operator may include, but is not limited to, an equality comparison operator, a string concatenation operator, an assignment operator, etc.

[0130] Exemplarily, the equality comparison operator can be represented by "==" to perform the equality comparison operation on the target string; the string concatenation operator can be represented by "+" to perform the string concatenation operation on the target string; the assignment operator can be represented by "=" to perform the assignment operation on the target string.

[0131] In the embodiment of the present application, the preset operator processor may include a "string op handler" tool. By designing a class and creating a string operator processor (StringOpHandler), this class can receive two strings and an operator, and then perform corresponding operations according to the given operator. For example, enumerations can be used to define the supported operators, and the operator method can be called to process the operations on the target string.

[0132] Among them, the operator processor may include an "operate" method that accepts two strings and an operator, and then performs the corresponding operator operation.

[0133] In an implementation manner of this application, during specific implementation, the step of calling a preset operator processor to perform an operation corresponding to the operator on the target object in step S1032 may include:

[0134] S10321. When the operator is an equality comparison operator, call a preset operator processor to perform an array comparison on the target object to determine whether the contents of the target object are the same, and return the judgment result.

[0135] In this step, when the operator is an equality comparison operator, first, check whether the first target object (the first operand) and the second target object (the second operand) are of array type. When one of the target objects is not an array, an exception will be thrown; then, if both target objects are of array type (i.e., ptrType = "array"), their contents will be converted to strings for comparison, and the array will be converted to a string through the "rt.getStringFromCharArray()" function, and then the strings of the two target objects will be compared using "=="; finally, if the array contents of the two target objects are the same, an equal result will be returned, otherwise a failure result will be returned, and the returned result type is of boolean (bool) type.

[0136] S10322. When the operator is a string concatenation operator, call a preset operator processor to convert the target object into a target string and concatenate the target strings.

[0137] In this step, when the operator is a string concatenation operator, first, check whether the first target object (the first operand) and the second target object (the second operand) are of array type. When one of the target objects is not an array, an exception will be thrown; then, convert them into strings through the "rt.getStringFromCharArray()" function, and then concatenate the two strings; finally, the concatenated string will be converted back to the character array format through the "rt.makeCharArrayFromString()" function, and the concatenation result will be returned.

[0138] S10323. When the operator is an assignment operator, convert the value of the right operand in the target object to the type of the left operand in the target object using a preset conversion function, and assign the value of the right operand to the left operand.

[0139] In this step, when the operator is an assignment operator, first, check whether the first target object (left operand) located on the left side of the code line is an lvalue (i.e., a variable that can be assigned a value). Determine whether the first target object (left operand) is an lvalue by judging whether "l.left" is true; then, if the first target object is an lvalue, convert the value of the second target object (right operand) located on the right side of the code line to the type of the left operand through the "rt.cast()" function, and assign its value to the variable value of the left operand; finally, if the first target object (left operand) is not an lvalue (i.e., "l.left" is false), then throw an exception with a prompt message "The first target object is not an lvalue".

[0140] S1033. In response to the operation mode being a logical function operation, determine the function class corresponding to the target string type included in the logical execution statement, and call the function corresponding to the function class to perform the operation corresponding to the function class on the target object.

[0141] In the embodiment of the present application, the logical function operation may include, but is not limited to, finding the position where a substring first appears (find), finding the position where a substring last appears (rfind), and obtaining the length of a string (length), etc.

[0142] In this step, when the operation mode is determined to be a logical function operation, first, determine the function class corresponding to the target string type included in the logical execution statement (for example, find, rfind, or length); then, call the function corresponding to the function class to perform the operation corresponding to the function class on the target object; finally, return the execution result of performing the operation corresponding to the function class.

[0143] In an implementation manner of the present application, in specific implementation, the step of pre-registering the function corresponding to the target string type in step S103 may include:

[0144] Step A. Determine the function corresponding to each logical function operation in multiple logical function operations.

[0145] In this step, a library named "string" is injected. When this library is introduced, the class mounting method for execution is registered. Specifically, first, the string type and its methods are registered using the statement "const stringType = rt.newClass('string', [])"; then, the string type is defined using the statement "const stringClassT = {t: stringType, v: {members: {}}, left: false}; rt.scope[0].variables['string'] = stringClassT;"; and finally, the function corresponding to each logical function operation among multiple logical function operations is determined.

[0146] Step B: Use the preset class mounting method to bind the functional class corresponding to the target string type to the functional function, so as to register the functional function to the target string type.

[0147] In this step, the preset class mounting method is used to add a binding functional function to the custom "string" class. Each functional function defines an operation logic (for example, the "_find" functional function uses "indexOf" to find the last occurrence position of a substring), and the functional function is registered to the target string type.

[0148] Here, when registering the functional function to the target string type, the name of the functional function, the parameter type (for example, character pointer "pchar"), and the return value type (for example, integer type) need to be declared.

[0149] In this way, the operation method of the programming language string provided in the embodiment of the present application integrates the characteristics of including JavaScript and C languages. By the running component in the interpretation and execution virtual runtime of the programming language program, the C language-style string pointer and the class concept of modern programming languages are combined to help understand the internal implementation of the programming language. For example, the operations of strings are encapsulated into methods.

[0150] Furthermore, the embodiment of the present application can customize the function extension of the string type, that is, convert the target string type (string type) into an operable object through the code in the programming language, and the methods corresponding to the functional functions can be called. These methods encapsulate common string operation logics, making programming more efficient and more readable, achieving the effect of abstracting string functions into object methods (for example, myString.find("abc")), approaching the style of object-oriented programming and being convenient for understanding and extension.

[0151] The operation method of programming language strings provided by the embodiments of the present application checks whether the object type of each object is the target string type during the process of interpreting and executing the abstract syntax tree corresponding to the externally input programming language program, so as to determine the target variables under each target object, and temporarily stores the target variables into the created variable object class to mark and declare the target variables, and then performs operations on the target objects according to the operation methods corresponding to the logical execution statements, enabling developers or users to focus on the core logic of operating strings rather than being disturbed by the complex implementation of underlying details, reducing the difficulty of operating programming language strings, and further reducing the time cost of developers or users for programming language compilation.

[0152] Please refer to Figure 2 , Figure 2 which is a schematic structural diagram of an operation device for programming language strings provided by the embodiments of the present application. As Figure 2 shown in

[0153] The string check module 210 is configured to call a preset defined variable component to check whether the object type of each object in the abstract syntax tree is the target string type during the process of interpreting and executing the abstract syntax tree corresponding to the externally input programming language program by using a preset running component;

[0154] The variable marking module 220 is configured to create a variable object class for the target variables under each target object whose object type is the target string type, and temporarily store the target variables into the variable object class to mark and declare the target variables;

[0155] The string operation module 230 is configured to, in the variable object class, in response to the programming language program being interpreted and executed to the logical execution statement for the target object, based on the operation method corresponding to the logical execution statement, call a preset operator processor or a function corresponding to the target string type to perform an operation on the target object.

[0156] Further, when the string check module 210 is used to interpret and execute the abstract syntax tree corresponding to the externally input programming language program by using a preset running component, the string check module 210 is configured to:

[0157] In response to obtaining an externally input programming language program, compile a predefined syntax file by using a preset cross-platform parsing tool to obtain a parsing file corresponding to the cross-platform parsing tool;

[0158] Use the parsing file and the cross-platform parsing tool to parse and convert the programming language program to generate an abstract syntax tree corresponding to the programming language program;

[0159] For each object included in the abstract syntax tree, based on the recursive access function corresponding to the object type of each said object, use a preset running component to interpret and execute the expressions under each said object type.

[0160] Further, when the string check module 210 is used to call a preset defined variable component to check whether the object type of each object in the abstract syntax tree is the target string type, the string check module 210 is used for:

[0161] Call and execute a preset defined variable component by using a preset defined function to determine the name attribute corresponding to the object type of each object in the abstract syntax tree;

[0162] Check whether the name attribute of each said object is the target string type;

[0163] If the name attribute of the object is the target string type, determine the object as a target object.

[0164] Further, when the variable marking module 220 is used to create a variable object class for the target variables under each target object whose object type is the target string type, and temporarily store the target variables in the variable object class to mark and declare the target variables, the variable marking module 220 is used for:

[0165] Create a variable object class for the target variables under each target object whose object type is the target string type; wherein, the variable object class includes a type attribute and a variable data attribute;

[0166] Temporarily store the target variables in the variable object class to mark and declare the target variables;

[0167] Store the variable object class in a preset virtual memory according to the keyword format corresponding to the variable object class.

[0168] Further, when the string operation module 230 is used to, in the variable object class, in response to the programming language program interpreting and executing to a logical execution statement for the target object, based on the operation method corresponding to the logical execution statement, call a preset operator processor or a function corresponding to the target string type to perform an operation on the target object, the string operation module 230 is used for:

[0169] In the variable object class, in response to the programming language program interpreting and executing to a logical execution statement for the target object, determine the operation method corresponding to the logical execution statement;

[0170] In response to the operation mode being an operator operation, determine the operator included in the logic execution statement, and call a preset operator processor to perform the operation corresponding to the operator on the target object;

[0171] In response to the operation mode being a logical function operation, determine the function class corresponding to the target string type included in the logic execution statement, and call the function corresponding to the function class to perform the operation corresponding to the function class on the target object.

[0172] Further, when the string operation module 230 is used to call a preset operator processor to perform the operation corresponding to the operator on the target object, the string operation module 230 is used to:

[0173] When the operator is an equality comparison operator, call a preset operator processor to perform an array comparison on the target object to determine whether the contents of the target object are the same, and return the determination result;

[0174] When the operator is a string concatenation operator, call a preset operator processor to convert the target object into a target string and concatenate the target strings;

[0175] When the operator is an assignment operator, convert the value of the right operand in the target object into the type of the left operand in the target object by using a preset conversion function, and assign the value of the right operand to the left operand.

[0176] Further, when the string operation module 230 is used to pre-register the function corresponding to the target string type, the string operation module 230 is used to:

[0177] Determine the function corresponding to each logical function operation among multiple logical function operations;

[0178] Use a preset class mounting method to bind the function class corresponding to the target string type to the function, so as to register the function to the target string type.

[0179] The operating device for programming language strings provided by the embodiments of the present application checks whether the object type of each object is the target string type during the process of interpreting and executing the abstract syntax tree corresponding to the externally input programming language program, to determine the target variables under each target object, and temporarily stores the target variables into the created variable object class to mark and declare the target variables, and then performs operations on the target object according to the operation method corresponding to the logical execution statement, so that developers or users can focus on the core logic of operating strings, rather than being interfered by the complex implementation of underlying details, reducing the difficulty of operating programming language strings, and further reducing the time cost of developers or users for programming language compilation.

[0180] Please refer to Figure 3 , Figure 3 which is a schematic structural diagram of an electronic device provided by the embodiments of the present application. As Figure 3 shown in

[0181] The memory 320 stores machine-readable instructions executable by the processor 510. When the electronic device 300 runs, the processor 310 communicates with the memory 320 through the bus 330. When the machine-readable instructions are executed by the processor 310, the steps of the operation method of programming language strings in the method embodiments as described above can be executed. The specific implementation manners can be referred to the method embodiments and will not be elaborated herein. Figure 1 shown.

[0182] The embodiments of the present application further provide a computer-readable storage medium. A computer program is stored on the computer-readable storage medium. When the computer program is run by a processor, the steps of the operation method of programming language strings in the method embodiments as described above can be executed. The specific implementation manners can be referred to the method embodiments and will not be elaborated herein. Figure 1 shown.

[0183] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.

[0184] In several embodiments provided in the present application, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some communication interfaces. The indirect couplings or communication connections of the devices or units can be in electrical, mechanical, or other forms.

[0185] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0186] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.

[0187] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this 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 enable a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.

[0188] Finally, it should be noted that the above-described embodiments are only specific embodiments of the present application, used to illustrate the technical solutions of the present application, rather than limiting it. The protection scope of the present application is not limited thereto. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that any person skilled in the art within the technical scope disclosed by the present application can still modify the technical solutions described in the foregoing embodiments or can easily think of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be covered within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A method for operating on a programming language string, characterized in that, The described operation method includes: During the process of interpreting and executing the abstract syntax tree corresponding to an externally input programming language program using a preset running component, calling a preset variable definition component to check whether the object type of each object in the abstract syntax tree is the target string type; For each target variable under each target object whose object type is the target string type, creating a variable object class and temporarily storing the target variable in the variable object class to mark and declare the target variable; In the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, based on the operation method corresponding to the logical execution statement, calling a preset operator processor or a function corresponding to the target string type to perform an operation on the target object.

2. The method according to claim 1, wherein The process of interpreting and executing the abstract syntax tree corresponding to an externally input programming language program using a preset running component includes the following steps: In response to obtaining an externally input programming language program, using a preset cross-platform parsing tool to compile a predefined syntax file to obtain a parsing file corresponding to the cross-platform parsing tool; Using the parsing file and the cross-platform parsing tool to parse and transform the programming language program to generate an abstract syntax tree corresponding to the programming language program; For each object included in the abstract syntax tree, based on the recursive access function corresponding to the object type of each object, using a preset running component to interpret and execute the expression under each object type.

3. The method according to claim 1, wherein The step of calling a preset variable definition component to check whether the object type of each object in the abstract syntax tree is the target string type includes: Using a preset definition function to call and execute a preset variable definition component to determine the name attribute corresponding to the object type of each object in the abstract syntax tree through the variable definition component; Checking whether the name attribute of each object is the target string type; If the name attribute of the object is the target string type, determining the object as a target object.

4. The method according to claim 1, characterized in that The step of creating a variable object class for each target variable under each target object whose object type is the target string type and temporarily storing the target variable in the variable object class to mark and declare the target variable includes: For each target variable under each target object whose object type is the target string type, creating a variable object class; wherein, the variable object class includes a type attribute and a variable data attribute; Temporarily storing the target variable in the variable object class to mark and declare the target variable; Storing the variable object class in a preset virtual memory according to the keyword format corresponding to the variable object class.

5. The method according to claim 1, wherein The step of, in the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, based on the operation method corresponding to the logical execution statement, calling a preset operator processor or a function corresponding to the target string type to perform an operation on the target object includes: In the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, determine the operation mode corresponding to the logical execution statement; In response to the operation mode being an operator operation, determine the operator included in the logical execution statement, and call a preset operator processor to perform the operation corresponding to the operator on the target object; In response to the operation mode being a logical function operation, determine the function class corresponding to the target string type included in the logical execution statement, and call the function function corresponding to the function class to perform the operation corresponding to the function class on the target object.

6. The method according to claim 5, wherein The calling a preset operator processor to perform the operation corresponding to the operator on the target object includes: When the operator is an equality comparison operator, call a preset operator processor to perform an array comparison on the target object to determine whether the contents of the target object are the same, and return the determination result; When the operator is a string concatenation operator, call a preset operator processor to convert the target object into a target string and concatenate the target string; When the operator is an assignment operator, convert the value of the right operand in the target object into the type of the left operand in the target object by using a preset conversion function, and assign the value of the right operand to the left operand.

7. The method according to claim 1, wherein The function functions corresponding to the target string type are pre-registered through the following steps: Determine the function functions corresponding to each logical function operation among multiple logical function operations; Use a preset class mounting method to correspondingly bind the function class corresponding to the target string type to the function function, so as to register the function function to the target string type.

8. An operating device for programming language strings, characterized in that, The operating device includes: A string check module, configured to call a preset defined variable component to check whether the object type of each object in the abstract syntax tree is a target string type during the process of interpreting and executing the abstract syntax tree corresponding to the externally input programming language program by using a preset running component; A variable marking module, configured to create a variable object class for the target variable under each target object whose object type is a target string type, and temporarily store the target variable in the variable object class to perform a marking declaration on the target variable; A string operation module, configured to, in the variable object class, in response to the programming language program being interpreted and executed to a logical execution statement for the target object, call a preset operator processor or the function function corresponding to the target string type to perform an operation on the target object based on the operation mode corresponding to the logical execution statement.

9. An electronic device, characterized in that, Includes: A processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are run by the processor, the steps of the operation method of the programming language string according to any one of claims 1 to 7 are executed.

10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is run by a processor, it executes the steps of the operation method of the programming language string according to any one of claims 1 to 7.