Programming language processing method and device and electronic equipment
By converting programming languages into specific strings and using pushdown automata for validation, the problem of insufficient front-end error validation is solved, improving the project's operational security and robustness, and reducing the risk of system crashes.
Patent Information
- Application Number
- CN202410444635.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-12
- Publication Date
- 2025-10-21
AI Technical Summary
In existing technologies, front-end error validation cannot fully locate and prompt users about errors, leading to frequent back-end errors, a high risk of system crashes, and complex and time-consuming data validation, making it difficult to guarantee the operational security and robustness of the project.
The structured programming language is converted into a specific string input, and a pushdown automaton obtained by context-free grammar transformation is used for pre-run validation. The target string is validated by predefined context-free grammar rules.
It solves the problem of invalid input at a large granularity, improves the operational security and robustness of the project, and reduces the time for locating errors and network transmission overhead.
Smart Images

Figure CN120821476A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software technology, and in particular to a method, device and electronic device for processing a programming language. Background Art
[0002] For large-scale projects, runtime errors are common and inevitable. Once an error occurs, it takes a significant amount of time to locate and resolve the issue. A high percentage of program errors are caused by user input. However, front-end error checking often fails to fully locate and alert users to errors. When the back-end receives front-end parameters without performing some validation, a series of unavoidable runtime errors often occur, including but not limited to simple request failures, execution termination, and even system crashes. However, data validation is complex and can only be performed on fine-grained data. Fully verifying the legitimacy of data is another challenge in terms of time complexity. Summary of the Invention
[0003] The purpose of this application is to provide a programming language processing method, device and electronic device, which converts a structured programming language into a specific string input and uses a push-down automaton obtained by context-free grammar conversion to perform pre-run verification. This a priori method can solve the problem of illegal input at a larger granularity, and can largely ensure operational security and improve the robustness of the overall project.
[0004] In the first aspect, the present application provides a method for processing a programming language, the method comprising: obtaining a programming language; converting the programming language based on a visual node flowchart edited by a user; performing field detection and conversion on the programming language to obtain a target string; the field corresponds to a grammar structure name in a predefined context-free grammar rule; inputting the target string into a preset push-down automaton so that the push-down automaton verifies whether the target string complies with the context-free grammar rules; the push-down automaton is converted based on the context-free grammar rules; and performing subsequent processing based on the verification result.
[0005] In the second aspect, the present application also provides a programming language processing device, which includes: an acquisition module for acquiring the programming language; the programming language is converted based on a visual node flowchart edited by the user; a conversion module for performing field detection and conversion on the programming language to obtain a target string; the field corresponds to the grammar structure name in the pre-defined context-free grammar rule; a verification module for inputting the target string into a preset push-down automaton so that the push-down automaton verifies whether the target string complies with the context-free grammar rules; the push-down automaton is converted based on the context-free grammar rules; and a processing module for performing subsequent processing based on the verification result.
[0006] In a third aspect, the present application further provides an electronic device comprising a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the methods described in the first and second aspects above.
[0007] In a fourth aspect, the present application also provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the methods described in the first and second aspects above.
[0008] In the programming language processing method, device and electronic device provided by the present application, a programming language is first obtained; the programming language is converted based on a visual node flow chart edited by the user; then the programming language is subjected to field detection and conversion to obtain a target string; wherein the field corresponds to a grammatical structure name in a predefined context-free grammar rule; then the target string is input into a pre-configured push-down automaton so that the push-down automaton verifies whether the target string complies with the context-free grammar rule; the push-down automaton is converted based on the context-free grammar rule; finally, subsequent processing is performed based on the verification result. The present application converts the structured programming language into a specific string input and uses the push-down automaton obtained by the context-free grammar conversion to perform pre-run verification. This a priori method can solve the problem of illegal input at a larger granularity, and can largely ensure operational safety and improve the robustness of the overall project. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the specific implementation methods of the present application or the technical solutions in the prior art, the following is a brief introduction to the drawings required for use in the specific implementation methods or the description of the prior art. Obviously, the drawings described below are some implementation methods of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0010] Figure 1 A flowchart of a programming language processing method provided in an embodiment of the present application;
[0011] Figure 2 A schematic diagram of editing a visual node flow chart provided in an embodiment of the present application;
[0012] Figure 3 A schematic diagram of a method provided in an embodiment of the present application;
[0013] Figure 4 A schematic diagram of a context-free grammar and a pushdown automaton provided in an embodiment of the present application;
[0014] Figure 5 A schematic diagram of a processing process of a programming language provided in an embodiment of the present application;
[0015] Figure 6 A structural block diagram of a programming language processing device provided in an embodiment of the present application;
[0016] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0017] The following will clearly and completely describe the technical solutions of this application in conjunction with the embodiments. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0018] A context-sensitive grammar (CSG) is a type of formal grammar that is more powerful than a context-free grammar (CFG) because it allows the application of rules to depend on contextual information. In a context-sensitive grammar, the application of a production depends not only on the symbol at the position, but also on the context surrounding the symbol.
[0019] It has the following concepts and information:
[0020] 1. Rule Form: CSG rules are more complex than CFG rules. Each rule typically has the following form: αAβ→αγβ, where α and β are sequences of terminals and nonterminals, respectively, A is a nonterminal, and γ is also a sequence of terminals and nonterminals. This means that A can only be replaced by γ if it appears between α and β.
[0021] 2. Context Dependency: CSG has a higher level of context dependency, which means that the application of productions depends on the context information of the symbols. This is different from CFG, where the application of productions is not affected by the context.
[0022] 3. Expressiveness: Because context-sensitive grammars are more flexible, they can represent complex language structures, such as grammatical rules in natural languages and type checking in programming languages. This makes CSGs important in fields such as syntax analysis and compiler design.
[0023] 4. Difficulty: Compared with CFG, CSG is more difficult to analyze and process because it involves more context information. This also means that the language category represented by CS is more powerful than the language category represented by CF.
[0024] Currently, nearly all literature on the generation of visual grammars is based on context-sensitive grammars, and essentially proposes new methods for specific domains and general levels, such as optimizing execution time. However, most generative grammars have a high time complexity, making it costly to catch errors during execution.
[0025] Based on this, the embodiments of the present application provide a method, device and electronic device for processing a programming language. By converting a structured programming language into a specific string input, a push-down automaton obtained by the context-free grammar conversion is used for pre-run verification. This a priori method can solve the problem of illegal input at a larger granularity, and can largely ensure operational safety and improve the robustness of the overall project.
[0026] To facilitate understanding of this embodiment, a processing method for a programming language disclosed in an embodiment of the present application is first introduced in detail.
[0027] Figure 1 This is a flowchart of a programming language processing method provided in an embodiment of the present application. This method can be applied to a client or a server, or some steps can be applied to a client and other steps can be applied to a server, or even multiple servers, without specific limitation here. The method includes the following steps:
[0028] Step S102, obtaining a programming language; the programming language is converted based on the visual node flow chart edited by the user;
[0029] In specific implementation, users can edit the visual node flowchart in the editing area by dragging components in the visual interface or other methods. The visual node flowchart is a multiple node connected in the editing order; each node represents one of the following: entity, attribute, type, method, input parameter, output parameter, logic, parent class. Figure 2 As shown, fill in the corresponding parameters or content in each box. At this time, the client will automatically convert the visual node flowchart into a programming language. If the execution subject is the server, it can receive the programming language sent by the client.
[0030] Step S104: Perform field detection and conversion on the programming language to obtain a target string; the field corresponds to a grammatical structure name in a predefined context-free grammar rule;
[0031] First, let's talk about context-free grammar (CFG). It's a formal grammar used to describe the structure of programming languages, natural language grammars, and other formal languages. It's a key concept in computer science, used to describe the syntactic structure of languages in areas like compiler design, natural language processing, and syntax analysis.
[0032] It has the following concepts and information:
[0033] 1. Grammar Rules: A CFG consists of a set of grammar rules that define how various structures in the language are constructed. Each rule typically consists of a left-hand side and a right-hand side. The left-hand side is a non-terminal symbol (usually representing the name of the grammatical structure), and the right-hand side is a sequence of terminals and / or non-terminal symbols that indicate how one or more grammatical structures should be combined.
[0034] 2. Terminals and non-terminals: Terminals are the most basic symbols in grammar and they are not broken down further. Non-terminals are symbols that can be expanded into other symbols according to grammar rules.
[0035] 3. Productions: Grammar rules are usually expressed in the form of productions. Each production describes how a non-terminal symbol is replaced by a sequence of one or more terminals and / or non-terminal symbols.
[0036] 4. Syntax Tree: CFG can be used to construct a syntax tree, which is a tree-like data structure used to represent grammatical structures. Each node represents a grammatical structure, and the edges represent the inclusion relationship between structures.
[0037] 5. Derivation: Derivation is the process of generating a specific string of characters through a series of substitution operations starting from the starting symbol of the grammar. This string of characters is usually considered to be a valid language sentence.
[0038] 6. Context-dependency: CFG rules are applied without considering the context of the symbol.
[0039] 7. Formal language: CFG is mainly used to describe formal languages, which include programming languages, natural languages, data description languages, etc. The grammatical structure of formal languages can be defined by CFG.
[0040] 8. Application areas: CFGs have a wide range of applications in computer science, including compiler design, syntax analysis, natural language processing, graph processing, model checking, etc. They are the grammatical basis of many programming languages and are used to write parsers and compilers.
[0041] In the embodiment of the present application, context-free grammar rules need to be defined in advance. Taking entities, attributes, methods, etc. as examples, each grammar rule included in the context-free grammar rules includes: a grammar structure name and its corresponding terminal symbol and / or non-terminal symbol; the non-terminal symbol includes at least one grammar structure combination extended from the grammar structure name; see Figure 3 As shown in the first line of grammar rules, the grammar structure name S on the left indicates the start, and the right side indicates that it can be an entity E or a logic L or an attribute P;
[0042] As shown in the second line of grammar rules, the grammar structure name E on the left represents an entity, and its corresponding terminal symbol is e. Non-terminal symbols include the grammar structure combinations EH, EP, EL, and ES that extend from E. H represents the parent class, P represents the attribute, and L represents the logic. In other words, if there is no content following the grammar structure name E, it is represented by the terminal symbol e. If there is content, it can be one of H, P, L, or S. The rules in the following lines are similar.
[0043] According to the above method rules, the target string can be obtained by performing field detection and conversion on the programming language.
[0044] Step S106: Input the target character string into a preset push-down automaton, so that the push-down automaton verifies whether the target character string conforms to the context-free grammar rules; the push-down automaton converts the target character string based on the context-free grammar rules;
[0045] The pushdown automaton may be a module provided in a client, a module provided in a server, a module provided in another server, or a module provided in another client, and no specific limitation is given here.
[0046] The specific process of obtaining the pushdown automaton is as follows:
[0047] First, obtain the predefined context-free grammar rules; each grammar rule contained in the context-free grammar rules includes: a grammatical structure name and a corresponding terminal symbol and at least one grammatical structure combination; then convert the context-free grammar rules into a pushdown automaton, such as Figure 3 Shown on the right.
[0048] A pushdown automaton (PDA) is a finite automaton with enhanced capabilities, designed to process languages generated by context-free grammars (CFGs). It is an abstract computational model consisting of a finite state controller, a stack, and an input string. A pushdown automaton is so called because it can push or pop symbols from the top of the stack.
[0049] The main components of a pushdown automaton are as follows:
[0050] 1. State set (Q): This is the state set in the finite state automaton, used to represent the state of the controller.
[0051] 2. Input alphabet (Σ): This is a finite set of input symbols that the automaton can recognize and process.
[0052] 3. Stack alphabet (Γ): This is the set of symbols on the stack, which usually includes all the symbols that the stack can contain. Γ contains at least one special symbol, which represents an empty stack.
[0053] 4. Transition function (δ): The transition function defines the action that the automaton should take given the state, input symbol, and top stack symbol. This includes state transitions, reading input symbols, and popping and pushing top stack symbols.
[0054] 5. Initial state (q0): represents the starting state of the automaton, which is a state in the finite state set.
[0055] 6. Accepting state set (F): This is a state subset used to represent the accepting state of the automaton. In the accepting state, the automaton can choose to accept the input string, indicating that it approves the input string.
[0056] 7. Stack: Automata use stacks to process languages generated by context-free grammars. Symbols in the stack can be popped or pushed to make state transitions when processing input.
[0057] The pushdown automaton works as follows:
[0058] The automaton starts from the initial state q0 and reads the symbols in the input string.
[0059] Based on the current state, input symbol, and stack top symbol, the automaton uses the transition function δ to transition states and can perform stack operations (such as pop and push).
[0060] The automaton continuously changes its state and stack contents according to the reading of the transition function and input symbols.
[0061] If the automaton reaches a state in the set of accepting states, and the input string has been completely read, then the automaton accepts the input string.
[0062] Pushdown automata are computational equivalents of context-free grammars, with a one-to-one correspondence between them. This means that if there's a language generated by a context-free grammar, an equivalent pushdown automaton can be constructed to recognize that language, and vice versa. Consequently, pushdown automata have broad applications in compiler design, natural language processing, and computational theory.
[0063] Step S108: perform subsequent processing based on the verification result.
[0064] If the verification is successful, the server can send or feedback a prompt message to the client to start generating code, parse the programming language, and generate executable code. If the verification fails, the server can send or feedback a verification failure message and an error message to the client. The error message is used to extract the syntax errors in the user's programming language.
[0065] For the client, after the verification is successful, the prompt information for starting to generate code can be directly displayed, and the programming language can be parsed to generate executable code, or further parsed and generated through the server; after the verification fails, the verification failure information and error prompt information can be directly displayed to remind the user.
[0066] The generation of visual language is achieved by the user continuously expanding and filling in the content in the editing interface. The processing method of the programming language provided in the embodiment of the present application can label the different contents (such as entities, attributes, types, methods, logic, parent classes, etc.) input by the user, that is, the above-mentioned grammatical structure name, and then formulate a context-free grammar rule for its association with other labels, and switch to a push-down automaton, and perform a priori on the programming language input by the user by editing the visual node flow chart, and then convert it into an executable language after successful verification, otherwise remind the client. The embodiment of the present application is converted into a specific string input by converting the structured programming language, and the push-down automaton obtained by the context-free grammar rule conversion is used to perform pre-operation verification. This priori method can solve the problem of illegal input of larger granularity, can ensure operational safety to a large extent, and improve the robustness of the overall project.
[0067] An embodiment of the present application also provides a method for processing a programming language, which is implemented on the basis of the previous embodiment. This embodiment focuses on describing the language conversion process.
[0068] The above-mentioned steps of detecting and converting the target field of the programming language to obtain the target string include:
[0069] Extract fields corresponding to grammatical structure names in context-free grammar rules from the programming language in sequence; convert the extracted fields into corresponding grammatical structure names to obtain an intermediate string; convert each character in the intermediate string into a corresponding terminal symbol in the context-free grammar rule to obtain a target string.
[0070] The generation of any VPL can start from an entity, a logic or an attribute, and continue to expand through user operations until the expansion is completed. Figure 4 As shown, as the user continues to edit the visual node flowchart, field detection is performed in real time according to the programming language converted from the visual node flowchart and converted into grammatical structure names in the context-free grammar rules, as shown on the right side of the figure, from top to bottom S, E, E, EH, EHT, EHTS, EHTP, EHTPT, EHTPTS..., where EHTPTS represents entity, parent class, type, attribute, type..., and finally each grammatical structure name is converted into a terminal symbol to obtain the string "ehtptptlitivtot", which is then input into the pushdown automaton PDA for verification. If the verification result is true, executable code is further generated. If the verification result is false, a reminder message is returned to the client.
[0071] For example, from the content under the attribute P of the programming language converted from the visual node flowchart, the fields corresponding to the grammatical structure name can be detected, such as the default value field "defaultValue" corresponding to D and the type field "schema" corresponding to T ("schema" is the name of the type "type" in DSL, so it corresponds to the grammatical structure name T). Then, the fields whose values corresponding to the above two fields are not empty are retained, that is, the non-empty field "schema"; then the non-empty field "schema" is converted into the corresponding grammatical structure name T, and finally the target string PT is obtained.
[0072] For example, in this embodiment, the rule for attribute P in the context-free grammar rules is defined as: P->PT|PTD|PTS; this rule requires that the non-terminal symbol P must be derived from the non-terminal symbol T, which in this embodiment means that P (attribute) must have T (type); obviously, according to the above rule definition for attribute P, the above target string PT can be verified successfully.
[0073] It should be noted that the rule definition for the attribute P can also be different according to the actual situation. For example, it can be: P->PT|PD|PS, which means that the attribute P can derive a type T at will, with the default value D. According to this rule definition, the target string PT can also be successfully verified.
[0074] For another example, from the content under the attribute P in the programming language converted from the visual node flowchart, the fields corresponding to the grammatical structure name can also be detected, such as the default value field "defaultValue" corresponding to D and the type field "schema" corresponding to T ("schema" is the name of the type "type" in DSL, so it corresponds to the grammatical structure name T), and then the fields whose values corresponding to the above two fields are not empty are retained, that is, the non-empty field "defaultValue"; then the non-empty field "defaultValue" is converted to the corresponding grammatical structure name D, and finally PD is obtained. Assume that a type must be included after defining an attribute in the rule, such as the rule is P->p|PT|PDT. According to the rule definition, the existence of PD alone does not comply with the rule. Therefore, the verification fails, and an error prompt is given for the "defaultValue" that does not comply with the rule.
[0075] The VPL (Visual Programming Language) tool uses context-free grammar to define a set of methods for parsing various operations such as the structure, combination, and data of basic visual graphics elements. Through editing operations in the visual interface, it can be easily converted into a grammar that can be used by multiple terminals.
[0076] Its primary purpose is to combine and arrange basic visualization primitives as the smallest building blocks, then stitch them together using grammar. Combining the scalability of grammar with the ability to add, delete, modify, and query basic primitives allows for rapid generation of VPLs. Because context-free grammars and pushdown automata are mutually convertible, grammars generated by combining basic primitives can be easily validated using pushdown automata, significantly improving the robustness of VPL grammars.
[0077] In the embodiments of the present application, context-free grammar rules are pre-defined based on certain grammatical content. These include, for example, the following: entity classes can be empty or have multiple method attributes; attributes must have types; methods can have input and output parameters and variables that can be empty; and local variables within methods must also have types. Because front-end validation is somewhat unreliable, it's easy to encounter situations outside these rules, such as an attribute without a type or a method containing an entity. These errors can occur in the final part of the entire DSL (Domain Specific Language), leading to the program only discovering the DSL is invalid at the very end of parsing, significantly wasting performance. Therefore, in the embodiments of the present application, after a user edits a visual node flowchart in a visual interface, a corresponding string to be verified is generated according to the node order edited by the user. The context-free grammar rules and the pushdown automaton generated by them verify the string before parsing. Only after successful verification is the string actually passed into the relatively large DSL for parsing and code generation. This a priori approach can address the issue of invalid input at a larger scale, significantly ensuring operational security and improving the robustness of the overall project.
[0078] Based on the above method embodiment, the present application embodiment also provides a programming language processing method, which is applied to the client, see Figure 5 As shown, the method includes the following steps:
[0079] Step S502, responding to the user's editing operation on the visual node flow chart, generating a corresponding programming language according to the editing operation;
[0080] Users can edit the visual node flow chart in the editing area by dragging components in the visual interface or other methods, such as Figure 2 As shown, fill in the corresponding parameters or content in each box. At this time, the client will convert the flowchart nodes edited by the user into DSL language. The converted structure includes the following:
[0081] "uid":"557DataClsTestproperty1","name":"property1","description":"","defaultValue":null,"getter":true,"setter":true,"isStati c":false,"isPersistent":false,"isIndex":false,"schema":{"ref":"557logincustomactor","format":"","namespace":"actor","type":"acto r","typeParams":null.
[0082] The above structure is the DSL representation of the attribute node P in the flowchart. The whole represents P in the above CFG, while the defaultValue and schema in the DSL represent D and T in the CFG respectively.
[0083] Step S504: Perform field detection and conversion on the programming language to obtain a target string;
[0084] After obtaining the programming language, the client performs field detection and conversion. For example, it detects the field "defaultValue" corresponding to the grammar structure name P in the context-free grammar rule and the field "schema" corresponding to the grammar structure name T from top to bottom, and then converts them into PT.
[0085] This process is consistent with the above content and will not be repeated here.
[0086] Step S506, sending the target string to a server configured with a push-down automaton, so that the server inputs the target string into the push-down automaton, so that the push-down automaton verifies whether the target string complies with the context-free grammar rules; and performs subsequent processing based on the verification result; wherein, the push-down automaton is obtained based on the conversion of the context-free grammar rules; the fields correspond to the grammatical structure names in the pre-defined context-free grammar rules.
[0087] The specific verification process can be found in the above content and will not be repeated here.
[0088] In addition, the above method also includes: receiving a prompt message for starting to generate code fed back by the server after successful verification, or receiving a verification failure message and an error prompt message sent by the server after failed verification; and displaying the verification failure message and the error prompt message to remind the user.
[0089] In an embodiment of the present application, after the client automatically converts the programming language based on the visual node flowchart, it is also automatically converted into a target string based on the programming language verification, and then the target string is sent to the server for pre-verification. If the verification fails, the user is directly prompted to modify the flowchart. After the verification is successful, the actual programming language is transmitted to the server. This can reduce the volume of data transmission. Compared with the existing technology of directly transmitting the programming language and then finding an error, it saves a lot of network transmission overhead.
[0090] Based on the above method embodiment, the present application embodiment also provides a programming language processing device, see Figure 6 As shown, the device includes:
[0091] An acquisition module 62 is used to acquire a programming language; the programming language is converted based on a user-edited visual node flow chart;
[0092] The conversion module 64 is used to detect and convert the fields of the programming language to obtain a target string; the fields correspond to the grammatical structure names in the predefined context-free grammar rules;
[0093] Verification module 66, configured to input a target string into a preset pushdown automaton, so that the pushdown automaton verifies whether the target string complies with context-free grammar rules; the pushdown automaton is converted based on the context-free grammar rules;
[0094] The processing module 68 is used to perform subsequent processing based on the verification result.
[0095] Furthermore, the above-mentioned device also includes: an automaton acquisition module, which is used to execute the following push-down automaton acquisition process: obtaining pre-defined context-free grammar rules; each grammar rule contained in the context-free grammar rules includes: a grammar structure name and its corresponding terminal symbol and / or non-terminal symbol; the non-terminal symbol includes at least one grammar structure combination extended from the grammar structure name; converting the context-free grammar rules into a push-down automaton.
[0096] Furthermore, the above-mentioned conversion module 64 is used to sequentially extract non-empty fields corresponding to the grammatical structure names in the context-free grammar rules from the programming language; convert the non-empty fields extracted in sequence into the corresponding grammatical structure names to obtain an intermediate string; and convert each character in the intermediate string into a corresponding terminal symbol in the context-free grammar rules to obtain a target string.
[0097] Furthermore, the processing module 68 is used to feedback and / or display a prompt message to start generating code after the verification is successful, and to parse the programming language to generate executable code; after the verification fails, feedback and / or display verification failure information and error prompt information.
[0098] Furthermore, the above error prompt information is used to prompt the user of grammatical errors in the programming language.
[0099] Furthermore, the above-mentioned visual node flowchart is a plurality of nodes connected in an editing order; each node represents one of the following: entity, attribute, type, method, input parameter, output parameter, logic, and parent class.
[0100] The device provided in the embodiment of the present application has the same implementation principle and technical effects as those in the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the embodiment of the device, reference can be made to the corresponding content in the aforementioned method embodiment.
[0101] The present application also provides an electronic device, such as Figure 7 FIG. 1 is a schematic diagram of the structure of the electronic device, wherein the electronic device includes a processor 71 and a memory 70. The memory 70 stores computer-executable instructions that can be executed by the processor 71. The processor 71 executes the computer-executable instructions to implement the following method:
[0102] Obtaining a programming language; the programming language is converted based on a user-edited visual node flow chart;
[0103] Perform field detection and conversion on the programming language to obtain the target string; the field corresponds to the grammatical structure name in the pre-defined context-free grammar rules;
[0104] Input the target string into a preset push-down automaton, so that the push-down automaton verifies whether the target string conforms to the context-free grammar rules; the push-down automaton is converted based on the context-free grammar rules;
[0105] Perform subsequent processing based on the verification results.
[0106] Furthermore, the acquisition process of the above-mentioned push-down automaton is as follows: obtain pre-defined context-free grammar rules; each grammar rule contained in the context-free grammar rules includes: a grammar structure name and its corresponding terminal symbol and / or non-terminal symbol; the non-terminal symbol includes at least one grammar structure combination extended from the grammar structure name; convert the context-free grammar rules into a push-down automaton.
[0107] Furthermore, the above step of detecting and converting the programming language fields to obtain the target string includes:
[0108] Non-empty fields corresponding to grammatical structure names in context-free grammar rules are sequentially extracted from the programming language; the sequentially extracted non-empty fields are converted into corresponding grammatical structure names to obtain an intermediate string; each character in the intermediate string is converted into a corresponding terminal symbol in the context-free grammar rule to obtain a target string.
[0109] Furthermore, the above-mentioned steps of performing subsequent processing based on the verification results include: after the verification is successful, sending a prompt signal to the client to start generating code, parsing the programming language, and generating executable code; after the verification fails, sending verification failure information and error prompt information to the client.
[0110] Furthermore, the above error prompt information is used to prompt the user of grammatical errors in the programming language.
[0111] Furthermore, the above-mentioned visual node flowchart is a plurality of nodes connected in an editing order; each node represents one of the following: entity, attribute, type, method, input parameter, output parameter, logic, and parent class.
[0112] exist Figure 7 In the illustrated embodiment, the electronic device further includes a bus 72 and a communication interface 73 , wherein the processor 71 , the communication interface 73 and the memory 70 are connected via the bus 72 .
[0113] Among them, the memory 70 may include a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 73 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 72 can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 72 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0114] The processor 71 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor 71 or by software instructions. The above processor 71 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of the present application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor 71 reads the information in the memory and completes the steps of the method of the above embodiment in combination with its hardware.
[0115] An embodiment of the present application further provides a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the following method:
[0116] Obtaining a programming language; the programming language is converted based on a user-edited visual node flow chart;
[0117] Perform field detection and conversion on the programming language to obtain the target string; the field corresponds to the grammatical structure name in the pre-defined context-free grammar rules;
[0118] Input the target string into a preset push-down automaton, so that the push-down automaton verifies whether the target string conforms to the context-free grammar rules; the push-down automaton is converted based on the context-free grammar rules;
[0119] Perform subsequent processing based on the verification results.
[0120] Furthermore, the acquisition process of the above-mentioned push-down automaton is as follows: obtain pre-defined context-free grammar rules; each grammar rule contained in the context-free grammar rules includes: a grammar structure name and its corresponding terminal symbol and / or non-terminal symbol; the non-terminal symbol includes at least one grammar structure combination extended from the grammar structure name; convert the context-free grammar rules into a push-down automaton.
[0121] Furthermore, the above step of detecting and converting the programming language fields to obtain the target string includes:
[0122] Non-empty fields corresponding to grammatical structure names in context-free grammar rules are sequentially extracted from the programming language; the sequentially extracted non-empty fields are converted into corresponding grammatical structure names to obtain an intermediate string; each character in the intermediate string is converted into a corresponding terminal symbol in the context-free grammar rule to obtain a target string.
[0123] Furthermore, the above-mentioned step of performing subsequent processing based on the verification result includes: after the verification is successful, parsing the programming language and generating executable code; after the verification fails, sending a verification failure message and an error prompt message to the client.
[0124] Furthermore, the above error prompt information is used to prompt the user of grammatical errors in the programming language.
[0125] Furthermore, the above-mentioned visual node flowchart is a plurality of nodes connected in an editing order; each node represents one of the following: entity, attribute, type, method, input parameter, output parameter, logic, and parent class.
[0126] The computer program products of the methods, devices, and electronic devices provided in the embodiments of the present application include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the previous method embodiments. For specific implementation, please refer to the method embodiments and will not be repeated here.
[0127] Unless otherwise specifically stated, the relative steps, numerical expressions and values of the components and steps set forth in these embodiments do not limit the scope of the present application.
[0128] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling 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 method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0129] In the description of this application, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended solely to facilitate the description of this application and simplify the description. They do not indicate or imply that the devices or components referred to must have a specific orientation, be constructed, or operate in a specific orientation. Therefore, they should not be construed as limitations on this application. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0130] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The scope of protection of the present application is not limited thereto. Although the present application has been described in detail with reference to the above-described embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above-described embodiments within the technical scope disclosed in the present application, or perform equivalent replacements for some of the technical features thereof. These modifications, changes, or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the scope of protection of the claims.
Claims
1. A method for processing a programming language, characterized in that: The method comprises: Obtaining a programming language; the programming language is converted based on a visual node flow chart edited by a user; Performing field detection and conversion on the programming language to obtain a target character string; the field corresponds to a grammatical structure name in a predefined context-free grammar rule; Inputting the target character string into a preset pushdown automaton, so that the pushdown automaton verifies whether the target character string conforms to the context-free grammar rules; the pushdown automaton is converted based on the context-free grammar rules; Perform subsequent processing based on the verification results.
2. The method according to claim 1, characterized in that The acquisition process of the pushdown automaton is as follows: Obtaining predefined context-free grammar rules; each grammar rule contained in the context-free grammar rules includes: a grammar structure name and its corresponding terminal symbol and / or non-terminal symbol; the non-terminal symbol includes at least one grammar structure combination extended from the grammar structure name; The context-free grammar rules are converted into a pushdown automaton.
3. The method according to claim 2, characterized in that The step of detecting and converting the target field of the programming language to obtain the target string includes: Sequentially extracting non-empty fields corresponding to grammatical structure names in the context-free grammar rules from the programming language; Convert the non-empty fields extracted in sequence into corresponding grammatical structure names to obtain an intermediate string; Each character in the intermediate character string is converted into a corresponding terminal symbol in the context-free grammar rule to obtain a target character string.
4. The method according to claim 1, wherein The subsequent processing steps based on the verification results include: After the verification is successful, feedback and / or display of a prompt message to start code generation, and parsing the programming language to generate executable code; After the verification fails, feedback and / or display of verification failure information and error prompt information.
5. The method according to claim 4, characterized in that The error prompt information is used to prompt the user of grammatical errors in the programming language.
6. The method according to claim 1, characterized in that Steps to acquire a programming language include: In response to a user's editing operation on the visual node flow chart, a corresponding programming language is generated according to the editing operation.
7. The method according to claim 1, characterized in that The visual node flowchart is a plurality of nodes connected in an editing order; each node represents one of the following: entity, attribute, type, method, input parameter, output parameter, logic, and parent class.
8. A programming language processing device, characterized in that: The device comprises: An acquisition module, configured to acquire a programming language; the programming language is converted based on a user-edited visual node flow chart; a conversion module, configured to perform field detection and conversion on the programming language to obtain a target string; the field corresponds to a grammatical structure name in a predefined context-free grammar rule; A verification module, configured to input the target string into a preset pushdown automaton, so that the pushdown automaton verifies whether the target string complies with the context-free grammar rules; the pushdown automaton is converted based on the context-free grammar rules; The processing module is used to perform subsequent processing based on the verification results.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the method according to any one of claims 1 to 7.
