Code generation method and device based on script syntax, equipment and medium

Through the code generation method based on script syntax, the automatic conversion requirement document's configuration word enable condition judgment logic is C++ code, which solves the problem of high communication costs, repetitive brain labor and inconsistent code style in software development, and achieves more efficient and standardized code generation.

CN120104112AInactive Publication Date: 2025-06-06AUTOLINK INFORMATION TECHNOLOGY CO LTD

Patent Information

Application Number
CN202510600434.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-12
Publication Date
2025-06-06
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

During the software development process, converting the configuration word enable condition judgment logic in the requirement document into C++ logic code has high communication costs, repetitive mental labor and inconsistent code style, which affects development efficiency and code quality.

Method used

Using a code generation method based on script syntax, the configuration word enable logic code that complies with C++ standards is automatically generated by obtaining target text, segmentation processing, generating syntax trees and conversion processing based on preset rules.

Benefits of technology

It realizes the rapid and efficient generation of more standard and unified C++ enable judgment logic code, which reduces communication costs and mental labor, and improves code quality and development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120104112A_ABST
    Figure CN120104112A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method, device and equipment based on script grammar and a medium, and the method comprises the steps that firstly, a target text in an editing area is acquired, and the grammar of the target text is script grammar; segmenting the target text to generate at least one character string, and constructing a corresponding syntax tree for each character string to form a syntax tree queue; and finally, traversing the syntax tree queue, and converting each syntax tree into a target code according to a preset grammar and code conversion rule. According to the method, more standard and unified C + + enabling judgment logic codes can be quickly and efficiently generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of code conversion technology, and in particular to a code generation method, device, equipment and medium based on script syntax. Background Art

[0002] In the software development process, programmers often face the task of converting the configuration word enable condition judgment logic in the requirements document into C++ logic code. However, this work has significant pain points, which seriously affects development efficiency and code quality. The primary problem is the high communication cost. Since the description of the requirements document may not be clear enough, programmers often need to communicate with system engineers repeatedly to accurately grasp the intention of the requirements. This kind of communication is not only time-consuming, but may also cause emotional burdens on both parties, thereby affecting the atmosphere of team collaboration.

[0003] Secondly, this task involves a lot of repetitive mental work. Programmers need to analyze the text content in the document line by line, including sentence splitting, keyword recognition, semantic understanding and grammatical reorganization, and finally convert it into C++ logical statements and manually input them into the development environment. Although this process follows certain rules and patterns, facing the enable condition judgments of dozens or even hundreds of signals in the requirements document, each condition may involve a complex logical combination of multiple configuration words, and the work can easily become boring and error-prone. Programmers may miss some configuration word condition judgments or misjudge the priority of logical operators. In addition, due to differences in individual programmers' abilities, the generated code style is often not uniform, which not only reduces the readability of the code and hinders the platformization process of the code, but also brings additional manpower and time costs for subsequent upgrades and modifications. Summary of the invention

[0004] In view of this, the embodiments of the present application provide a code generation method, apparatus, device and medium based on script syntax, which can quickly and efficiently generate more standard and unified C++ enabling judgment logic code.

[0005] The technical solution of the embodiment of the present application is implemented as follows: In a first aspect, an embodiment of the present application provides a code generation method based on script grammar, the method comprising: Acquire the target text in the editing area; wherein the syntax of the target text is script syntax; Segmenting the target text to obtain at least one character string, and generating a corresponding syntax tree for each character string in the at least one character string to obtain a syntax tree queue; The syntax tree queue is traversed, and each syntax tree in the syntax tree queue is converted based on preset syntax and code conversion rules to obtain target code.

[0006] In a second aspect, an embodiment of the present application further provides a code generation device based on script grammar, the device comprising: An acquisition module is used to acquire a target text in an editing area; wherein the syntax of the target text is a script syntax; A generation module, configured to segment the target text to obtain at least one string, and generate a corresponding syntax tree for each string in the at least one string to obtain a syntax tree queue; The conversion module is used to traverse the syntax tree queue and convert each syntax tree in the syntax tree queue based on preset syntax and code conversion rules to obtain target code.

[0007] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium through the bus, and the processor executes the machine-readable instructions to execute the script syntax-based code generation method described in any one of the first aspects.

[0008] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the code generation method based on script syntax described in any one of the first aspects is executed.

[0009] The embodiments of the present application have the following beneficial effects: Compared with the traditional method of relying on the programmer's brain to analyze the configuration word enabling logic in the document, the embodiment of the present application can quickly and efficiently input the logic script that complies with the rules (judgment of the function configuration word and the power state enabling condition), and then the coding system interprets and generates the configuration word enabling logic code that complies with the C++ standard according to the grammatical rules of the logic script. The embodiment of the present application has the functions of clear and complete syntax tree rule (structure) checking, syntax error backtracking, automatic derivation of prompt words, and continuous learning and optimization of prompt word pop-up priority according to the context, which can generate more standard and unified C++ enabling judgment logic code. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0011] Figure 1is a flowchart of steps S101-S103 provided in an embodiment of the present application; Figure 2 It is a flowchart of steps S201-S202 provided in an embodiment of the present application; Figure 3 This is an interface diagram of all enumeration names corresponding to the recommended enumeration types through a drop-down list pop-up window provided in an embodiment of the present application; Figure 4 It is a flowchart of steps S401-S404 provided in an embodiment of the present application; Figure 5 It is a flowchart of steps S501-S503 provided in an embodiment of the present application; Figure 6a This is a diagram of a keyword prompting interface of an automatic derivation system provided in an embodiment of the present application; Figure 6b This is an interface diagram of a recommender provided in an embodiment of the present application that preferentially displays prompt words with higher weights (more occurrences); Figure 6c This is a diagram of an interface for automatically deriving a list of prompt words for a right-value structure member provided in an embodiment of the present application; Figure 7 This is an interface diagram of a grammar prompt box for a keyword that pops up after the mouse is hovered over, provided in an embodiment of the present application; Figure 8 This is how to generate a C++ code interface diagram through a script's syntax tree parsing rules provided by an embodiment of the present application; Fig. 9 It is a structural diagram of a code generation device based on script grammar provided in an embodiment of the present application; Fig.10 It is a schematic diagram of the composition structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0012] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of explanation and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn in real proportion. The flowchart used in this application shows the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowchart can be implemented out of order, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart under the guidance of the content of the present application, or remove one or more operations from the flowchart.

[0013] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0014] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.

[0015] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0016] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.

[0017] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0018] When implementing the embodiments of the present application, the applicant discovered that the prior art has the following problems: With the rapid development of the new energy vehicle intelligent cockpit system software industry, more and more vehicle system modules are involved in the research and development of enterprises, such as air conditioning control systems, reversing image systems, instrument display systems, etc. With this, more and more system requirement documents are accumulated. The requirement document describes the functional description and implementation details of the vehicle submodule. The very important content that requires a lot of space to describe is the judgment logic of the function configuration word and the power state enabling condition. The logic content describes the normal use and disabled configuration word conditions and power state conditions of the module. Generally, it is jointly formulated by the system engineer responsible for the module and the customer. Although there are some soft regulations and industry requirements for the format of the system requirement document at the industry or enterprise level, it is limited by the technical ability and professional quality of each system engineer, and the content writing format of the system requirement document they participate in is also different. After the system engineer formulates the system requirement document, the project level will hand over the system requirement document to the programmer (R&D engineer) to implement it with program code.

[0019] The content of function configuration words and power state enabling condition judgment in the requirement document is generally in the form of a table, and then the function configuration words (configuration words are digital codes used to determine whether the function is supported) and the enabling judgment logic of the power state conditions are described line by line in written text. Programmers need to "translate" the table content into C++ / C language logic code that can be recognized by computers based on experience and their own "brains".

[0020] For programmers, converting the logic content of the configuration word enable condition judgment in the requirement document into C++ logic code is a repetitive and brain-consuming task. This task has the following three pain points: The first is the high communication cost. If the content of the document is not clear, the programmer may need to communicate with the system engineer repeatedly to clarify the true intention of the document. This consumes time and emotional costs for both parties.

[0021] The second is repetitive mental work. Programmers need to analyze the text content of the function configuration words and power state enable conditions line by line in their brains (statement splitting, keyword analysis, semantic analysis, grammatical reorganization), then convert them into C++ logical statements, and finally manually enter the code in the development environment. This is a series of regular, patterned, and experienced workflows performed by the human brain. Often, there will be dozens or hundreds of signal enable condition judgments in a requirement document, and each condition judgment may involve multiple different logical (AND or NOT) combinations of configuration words. Handling this task is boring and prone to errors for programmers. There is also the risk that programmers occasionally miss a configuration word condition judgment, and there is also the possibility of mistaking the priority of AND or NOT.

[0022] The last pain point is that the C++ logic code style processed and output by the human brain is not uniform. Due to the differences in the abilities of each programmer, the code styles they write are not uniform. Different code styles may reduce the overall code reading level and hinder the platformization of code. Subsequent upgrades and modifications will also cost a lot of manpower and time.

[0023] In order to solve the above three pain points of how to efficiently and standardizedly convert the table contents of the system requirement document (judgment of function configuration words and power state enabling conditions) into standard C++ code that can be used in the project, the patent of this invention realizes an auxiliary coding system for SQL to C++ with syntax self-checking and dynamic prompts. Why is it necessary to choose a scripting language similar to SQL to solve the current scenario? First, compared with high-level languages ​​such as C++, the syntax of SQL statements is relatively simple and easy to learn. Second, the query condition statements in SQL are suitable for scenarios with complex logical condition judgments. For example, many SQL statements involve logical condition combination judgments of multiple tables and multiple fields.

[0024] Query SQL statements involving multiple fields are also very suitable for scenarios where function configuration words and power state enable conditions are judged. We will draw on the grammatical rules of SQL to create a set of SQL-like grammatical rules and structures suitable for scenarios where function configuration words and power state enable conditions are judged, and create a set of encoder systems and methods that can assist in code writing for the grammatical rules. The system and method need to have the core functions of grammar checking, error reporting, and automatic derivation of prompt words, and also need to have the function of being able to interpret and generate C++ logic code. In this way, system engineers can use the system to quickly write script statements with SQL-like syntax during the system requirements document design phase, and then generate C++ logic code from the SQL statement (judgment of function configuration words and power state enable conditions). Subsequent programmers can directly copy the generated code to the project and use it after fine-tuning.

[0025] At present, the logic for enabling the availability of configuration word functions in documents needs to be analyzed by the programmer’s brain through a series of analyses (table content understanding -> column analysis / row analysis -> vocabulary splitting -> syntax analysis -> adaptation of C++ syntax rules -> syntax optimization) before it can be turned into C++ code that can be used in the project. The starting point of this patent invention is to review and summarize the process and method of the brain thinking and solving such problems, simulate the human brain through computer programs to analyze lexical syntax, and optimize logical statements, and finally output relatively standard C++ code, which can effectively reduce the burden on R&D personnel and provide code blocks that can be referenced or even directly used. For such regular and highly repetitive tasks, they can be effectively extended and replaced by the methods and system models of this patent technology.

[0026] Considering the unfamiliarity of system engineers with the syntax of the C++ high-level programming language, the embodiment of the present application allows users to input Sql statements with fixed rules, which can interpret and output C++ logic code. The system has its own unique and concise syntax rules. The engine can automatically match the appropriate syntax parser according to the characters input by the user in real time. If it cannot match, a syntax error will be reported. If a suitable syntax parser is matched, the syntax parser will derive the prompt word of the next level node associated with the current syntax node in real time and prompt the user to enter the next step through a drop-down list pop-up window. The engine can automatically adjust the recommended priority of the prompt word in the drop-down list according to the input habits of the user context. The data types supported by this coding system are compatible with the Int64 (64-bit integer), Float64 (64-bit floating point), String (string), and Enum (enumeration value) types of the C++ programming language. It can not only support the numerical type judgment of the vehicle configuration word, but also support customized enumeration types. The enumeration value type is a right value data type for assigning values ​​to variables. It has the characteristics of being easy to read and easy to parse. It is suitable for scenarios where the field value range is fixed and appears frequently (such as state enumeration and function availability enumeration).

[0027] See also Figure 1 , Figure 1 is a flowchart of steps S101-S103 of the code generation method based on script syntax provided in an embodiment of the present application, which will be combined with Figure 1 Steps S101-S103 are shown for explanation.

[0028] In step S101, a target text in an editing area is obtained; wherein the grammar of the target text is a script grammar.

[0029] In step S102, the target text is segmented to obtain at least one character string, and a corresponding syntax tree is generated for each character string in the at least one character string to obtain a syntax tree queue.

[0030] In step S103, the syntax tree queue is traversed, and each syntax tree in the syntax tree queue is converted based on preset syntax and code conversion rules to obtain target code.

[0031] Here, the script syntax text input by the user is obtained from the editing area. The target text follows specific script syntax rules. As the input source for code generation, the script syntax defines the structure and logic of the code. Next, the target text is segmented into several strings according to the rules of the script syntax, such as by line, by syntax unit (such as statement, expression), etc. The segmentation method may be based on the tokenization process of the syntax analyzer (Parser). For each string, a corresponding abstract syntax tree (AST, Abstract SyntaxTree) is generated by a syntax analyzer (such as a Parser based on context-free grammar). Each syntax tree represents the syntax structure of the corresponding string, which is convenient for subsequent code generation. Finally, a syntax tree queue is output, which contains syntax trees corresponding to all segmented strings. Each syntax tree in the syntax tree queue is processed in turn, and the syntax tree is converted into the target code based on the preset syntax and code conversion rules. The conversion rules may include: mapping of syntax tree nodes to code statements (such as assignment statements, conditional statements, loop statements, etc.), mapping of syntax tree attributes to code parameters (such as variable names, function names, parameter lists, etc.), and mapping of syntax tree structures to code structures (such as nested structures, parallel structures, etc.). Finally, the code text is output in a specific programming language or code format.

[0032] The above method supports multiple script syntaxes. You only need to define the corresponding syntax and code conversion rules. It is easy to expand and can add new syntax rules or conversion rules. The syntax tree represents the structure of the script syntax, which is convenient for complex code generation and optimization. The syntax tree can be used as an intermediate representation to support a variety of subsequent processing (such as code optimization and code analysis), and realizes the automatic conversion from script syntax to target code, which improves development efficiency, reduces the workload of manual code writing, and reduces the risk of errors.

[0033] In some embodiments, the script syntax includes at least DECLARE syntax and UPDATE-WHERE syntax; The DECLARE syntax is used to declare variables and assign values. The form of the DECLARE syntax is: DECLARE variable name = value data; wherein the value data includes basic numerical types, built-in enumeration types and string types; During parsing, the type of the variable name is automatically identified based on the data type of the value data; The UPDATE-WHERE syntax is used to update variable values. The form of the UPDATE-WHERE syntax is: UPDATE variable assignment statement, variable assignment statement…variable assignment statement WHERE=conditional statement 1 [comparison operator] conditional statement 2 [comparison operator]…conditional statement N; wherein N is a positive integer, and the syntax of the variable assignment statement is: variable name=[numeric type data] or [enumeration type data] or [string type data]; the comparison operator at least includes equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to, in the numerical set, and not in the numerical set; During parsing, the conditional statement is split into multiple sub-expressions to generate a logical judgment tree.

[0034] Here, the embodiment of the present application supports the syntax format of the scripting language. In the embodiment of the present application, two formats are provided, as follows: The first is the DECLARE syntax: DECLARE variable name = [numeric type data] | [enumeration type data] | [string type data]; Note: This syntax starts with the keyword DECLARE. DECLARE is a built-in syntax keyword of this system, which is used to identify that the syntax of the current statement complies with the DECLARE syntax. Multiple spaces can be placed on the left and right of the = (equal sign). The left side of the equal sign is the user-defined variable name, and the right side of the equal sign is the value data field. There are three types of supported fields (basic numeric type, built-in enumeration type, and string type). The statement of the DECLARE syntax is used to declare a variable name and assign a value to the variable. There is no need to declare the type of the variable (like most scripting languages, there is no need to indicate the type of the variable, because the scripting language is a weakly typed language syntax, and it needs to perform dynamic syntax parsing to know the actual type of the variable). The system will automatically identify the type of the variable name according to the data type of the field on the right side of the equal sign. Note: Each time a variable name appears in the coding system, it will be recorded by the system and weighted in the prompt word recommender. The prompt words with high weights will be sorted by the system according to the weights the next time the user is ready to enter the variable name, and the prompt words with high weights will be matched and prompted first.

[0035] Example 1: DECLARE mAvail=E_HVAC_AVAILABLITY_NOT_ACTIVE Example 2: DECLARE aaa=1; Example 3: DECLARE bbb='ABCD'; Example 4: DECLARE ccc=3.141592; In the structural implementation of the DECLARE syntax tree, IAST is the base class of the abstract syntax tree, which encapsulates some common formatting interfaces. It has two members: index and errorCode. Index records the position of the corresponding lexical traverser when an error occurs during the syntax tree construction process, which is convenient for locating which vocabulary has a problem. ErrorCode records the error during the syntax tree construction process. ASTDeclareQuery is a DECLARE syntax tree instance class, which is derived from IAST and implements some common methods for DECLARE syntax parsing and formatting output C++ code. ASTDeclareQuery is a tree type in principle. It has a byte node ASTSetting, and ASTSetting has two members name and field. Name is the variable name, and field is the right value data. There are three major types of field types (basic numeric types, built-in enumeration types, and string types).

[0036] The second is the UPDATE-WHERE syntax: UPDATE variable assignment statement, variable assignment statement,…, variable assignment statement WHERE condition statement 1 [AND|OR] condition statement 2 [AND|OR] condition statement 3 [AND|OR]… condition statement N; First, the syntax rules of variable assignment statements are as follows: variable name = [numeric type data] or [enumeration type data] or [string type data]; Overall description: This syntax starts with UPDATE. UPDATE is a built-in syntax keyword of this system, which is used to identify that the syntax of the current statement complies with the UPDATE-WHERE syntax. The statement of this syntax structure is divided into two parts, the first half is the UPDATE variable assignment statement, and the second half is the WHERE conditional statement. The syntax of the UPDATE variable assignment statement is: UPDATE variable assignment statement, variable assignment statement, ..., variable assignment statement. An UPDATE statement can have n (n>0) variable assignment statements separated by commas. The syntax of a single variable assignment statement is: variable name = [numeric type data] or [enumeration type data] or [string type data], where the variable name is before the = (equal sign), and or represents one of the three numeric types. If the variable name has appeared in the previous DECLARE or UPDATE-WHERE statement, this coding system will perform real-time content matching and automatic prompts when the user is ready to enter the variable name again, helping the user to quickly complete the input of the variable name. The syntax format of the WHERE conditional statement is: WHERE conditional expression statement 1 [AND|OR] conditional expression statement 2 [AND|OR] conditional expression statement 3 [AND|OR] ... conditional expression statement N. The WHERE conditional statement ends with ; (semicolon) or / n (newline character). The conditional expression statement consists of two operands on the left and right plus a binary comparison operator. The left operand is a custom variable name (it may also be a structure object with a nested structure type. The introduction and implementation instructions of the internal structure table will be introduced separately in the following paragraphs). The right operand includes 4 types (basic numeric type, built-in enumeration type, string type, and numeric set type). The return value is a Boolean value (TRUE or FALSE). The comparison operators supported by this coding system include = (equal to), != (not equal to), > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to), IN (in the numeric set), and NOT IN (not in the numeric set). The WHERE conditional statement allows multiple conditional expression statements to be connected through AND (logical AND) and OR (logical OR) logical operators. When all conditional expression clauses of the WHERE conditional statement are established (the return value is TRUE), the system will determine the variable assignment statement to execute the UPDATE statement.

[0037] Example 1: UPDATE mStatus=E_ON_STATUS WHERE a>=1 AND b=2 AND c<=0 OR d!=5AND e IN(11,12,13) ​​OR f NOT IN(100,101); Example 2: UPDATE mAvail=E_HVAC_AVAILABLITY_ACTIVE, mStatus = E_OFF_STATUSWHERE mHvacSettings.CC8=100 AND mHvacSettings.CC22!=50 OR mHvacSettings.CC155IN(13,26); In the structural implementation of the UPDATE-WHERE syntax tree, IAST is the base class of the abstract syntax tree, which encapsulates some common formatting interfaces. It has two members, index and errorCode. Index records the position of the corresponding lexical traverser when an error occurs during the syntax tree construction process, which is convenient for locating which vocabulary has a problem. ErrorCode records the error during the syntax tree construction process. ASTUpdateWhereQuery is an UPDATE-WHERE syntax tree instance class, which is derived from IAST and implements some common methods for UPDATE-WHERE syntax parsing and formatting output C++ code. ASTUpdateWhereQuery is a tree type in principle. It has two child nodes, ASTSettings and ASTWhere. ASTSettings is a queue container for multiple ASTSettings. ASTWhere is a queue container for multiple ASTFunctions. ASTFunction has two child nodes, name and ASTExpressionList. Operators like AND, OR, >, <, !=, IN, and NOT IN are essentially function syntax trees, and they all have their own function names. Each operand function has its own specified number of operands. For example, a>0 has two operands a and 0, and the AND in a>0 AND b<0 has two operands (a>0) and (b<0).

[0038] In some embodiments, see Figure 2 , Figure 2 It is a flowchart of steps S201-S202 provided in an embodiment of the present application. The method also includes steps S201-S202, which will be described in combination with each step.

[0039] In step S201, in response to the assignment operation of assigning the enumeration name to the target variable, the target variable is marked as the enumeration type corresponding to the enumeration name based on a preset data table, and recorded in the recommendation engine; wherein the data table is an enumeration table.

[0040] In step S202, in response to detecting an assignment operation to the calibrated target variable, a drop-down list is displayed through the recommendation engine; wherein the drop-down list includes all enumeration names corresponding to the enumeration type.

[0041] In some embodiments, the enumeration table is used to automatically infer the variable type according to the enumeration table when referencing the enumeration value; the enumeration table is a CSV format table; the enumeration table includes at least four field columns: enumeration type, enumeration name, enumeration value, and semantics; The row data in the enumeration table is defined based on project requirements. All row data in the enumeration table are automatically loaded after the system is started, and a global enumeration table is constructed in memory.

[0042] For example, the table contains four columns, namely TYPE (enumeration type), ENUM (enumeration name), VALUE (enumeration value), and SEMANTICS (semantics). These four columns are necessary structure members to describe an enumeration type. Using the row data of these four columns, we can build a global enumeration type table in the system memory. When the encoding engine system detects that the user is assigning an enumeration name to a variable, the system will "mark" the variable name as the variable name of this enumeration type and record it in the recommendation engine. Later, if the key input framework detects that the user is assigning a value to a marked enumeration variable, it will notify the prompt word recommendation engine, which will recommend all enumeration names corresponding to the enumeration type through a drop-down list pop-up window, such as Figure 3 shown.

[0043] The enumeration table is a CSV format table used to define the right-hand enumeration type that may be referenced by the assignment statement in the coding system. It describes the structure and content required to define the enumeration.

[0044] In some embodiments, different enumeration types can be defined according to different C++ vehicle project frameworks. You only need to add the 4-column field row data of the required enumeration type to the enumeration table. After the system starts, it will automatically load all the row data of the full enumeration table and build a global enumeration table in memory. The structure of the global enumeration table is the same as the enumeration definition used in the C++ vehicle project in structure and expression. Only in this way can practical C++ code be generated.

[0045] The full enumeration table is a Map object, whose key is a string type, representing the name of the enumeration type; its value is an EnumDefine structure pointer. EnumDefine is an enumeration type definition, which contains a String type name and a Map<Int32,EnumType*> For example, E_ON_OFF_STATUS is an EnumDefine, which contains an enumeration value type table consisting of two enumeration value types (E_OFF_STATUS=0, E_ON_STATUS=1).

[0046] In some embodiments, the data table also includes an internal structure table, which includes at least five column fields: type name, type group name, actual member value type, type alias and description. The internal structure table is used for nested structure member prompts. The internal structure table is bound to the enumeration table through key values ​​to realize the use of custom enumeration types in the internal structure.

[0047] The concept of internal structure in this system corresponds to the concept of structure or class type in C++ language. The internal structure table is a .csv format table used to define the data structure of variables of structure type that may be referenced in the coding system. It describes the (nested) structure types that may be used by the coding system. The concept of structure type is very necessary for implementing multi-level prompt word feedback in the coding system. For example, if you want to realize the prompt word linkage of the first-level member and the second-level member variable of a variable, you need to define the nested structure with the first-level member and the second-level member in this table.

[0048] The internal structure table contains 5 columns, namely MemberTypeName (type name), MemberTypeGroup (type group name), MemberValueType (actual member value type), MemberTypeAlias ​​(type alias), and MemberTypeDesc (description). The following is an explanation of the functions of these 5 columns: MemberTypeName: The name of the internal structure type. Two hash tables are maintained in this system, one with the content of the MemberTypeName row as the key, and the other with the content of the MemberTypeAlias ​​row as the key. The key can be used to query the address of the corresponding internal structure in memory.

[0049] MemberTypeGroup: type family name. The type family can be considered as a group of data types with the same behavioral attributes. The system currently supports five major type families: E_UINT8 (8-bit unsigned integer), E_INT32 (signed 32-bit integer), E_FLOAT (signed 32-bit floating point), E_ENUM (enumeration type), and E_STRUCT (internal structure type). Each of the above type families encapsulates a general read and write interface suitable for data of this type. These five type families basically meet the application scenarios of the current encoding system for judging the enabling conditions of vehicle function configuration words. iii.MemberValueType: the value type of the actual member. Since the system described in the embodiment of the present application runs in a C++ compilation environment, it is necessary to implement the five major data type family concepts of this system through the basic data type concepts of C++. How to determine the actual type of an object: The system will first determine the type family name of the current object. If MemberTypeGroup is a basic data type family (E_UINT8, E_INT32, E_FLOAT, E_ENUM), then it has only one actual member; if MemberTypeGroup is a composite data type (E_STRUCT), then the value type of the corresponding actual member may be one or more combinations of the above five type families. For example, the system's E_UINT8 type family is actually implemented using C++'s UINT8. The E_INT32 type family is implemented using C++'s INT32, and the E_FLOAT type family is implemented using C++'s FLOAT32. The implementation of E_ENUM and E_STRUCT is the data type concept native to the system of the embodiment of this application. The E_ENUM type family uses the enumeration type data defined in the enumeration table. The E_STRUCT type family represents a composite structure type, which can be one or more combinations of the above five data type families. If an E_STRUCT contains another E_STRUCT, then we consider this E_STRUCT to be a nested structure type. No matter how many levels of nesting, it should ultimately be composed of basic data types (E_UINT8, E_INT32, E_FLOAT, E_ENUM), otherwise the definition of this type is incomplete. E_STRUCT can be used to implement multi-level data structures, which can help us deduce the prompt words of tree structure members through the keyword matching method of breadth-first traversal (depth exploration) on multi-level data structures. Bind the two tables (internal structure table and enumeration type table) with key values, so that the custom enumeration type can be flexibly used in the internal structure.

[0050] MemberTypeAlias: type alias, which has the same function as the type alias in C++ language and is intended to be compatible with the type alias in C++ language.

[0051] MemberTypeDesc: Description information, supplementary explanation of the current internal structure, used for help information, and can be used for grammar prompts.

[0052] In some embodiments, see Figure 4 , Figure 4 It is a flowchart of steps S401-S404 provided in an embodiment of the present application, and will be explained in combination with each step.

[0053] In step S401, in response to inputting characters in the editing area, the current cursor position of the editing area is obtained, and based on the current cursor position, the current statement of the line where the current cursor is located is obtained.

[0054] In step S402, the current sentence is traversed to obtain a string queue; wherein the string queue is a lexical traverser, the lexical traverser is a linear container, and the linear container is used to store all independent word contents and address indexes of the current sentence after lexical analysis.

[0055] In step S403, the string queue is parsed by a syntax parser. If the parsing is successful, a corresponding syntax tree object is generated; if the parsing is unsuccessful, an error code is marked during the parsing.

[0056] In step S404, an error code check is performed on the generated syntax tree object, and based on the value of the error code, it is determined whether to prompt a syntax error and / or derive the next input prompt word.

[0057] In some embodiments, see Figure 5 , Figure 5 It is a flowchart of steps S501-S503 provided in an embodiment of the present application, and will be explained in combination with each step.

[0058] In step S501, if any syntax leaf node does not exist or reports an error, a corresponding error code is marked on the current syntax tree node; wherein, a syntax leaf node corresponds to at least one sub-syntax tree.

[0059] In step S502, backtracking is performed until the outermost syntax tree object is returned.

[0060] In step S503, if the syntax tree object finally obtained is incomplete, the error code of the sub-syntax tree node is read by breadth-first traversal, and a syntax error prompt is given based on the error code.

[0061] In combination with steps S401-S404 and steps S501-S503, the embodiment of the present application also provides a real-time grammar detection function. The real-time grammar detection is when the user is writing a script. When the keyboard input characters are detected, the encoding system uses lexical analysis and grammar parser to detect whether the text on the line where the current cursor is located conforms to the grammar parsing rules (DECLARE or UPDATE-WHERE) introduced above. According to the grammar detection results, the correctness of the script code input by the user is fed back or the prompt words for the content that the user is going to enter are derived. The specific grammar detection steps are as follows: i. Monitor user keyboard input events: When the user enters characters, the cursor position of the current text area can be obtained. According to the cursor position, the text content of the current cursor line mLineStr can be obtained, and then step ii is executed.

[0062] ii. Perform lexical analysis on the text content: Use the lexical analyzer to perform lexical analysis on mLineStr. Lexical analysis refers to traversing all the character contents of the current sentence from beginning to end. If a separator is encountered (the separator is a space, semicolon or other special symbol), the separated string (the character sequence from the previous separator to the current separator) is recorded until the last character is traversed. Finally, we will get a string queue mTokenIterator, which is also called a lexical traverser. It is a linear container that saves all independent word contents and address indexes of the current sentence mLineStr after lexical analysis. Then execute step iii.

[0063] iii. Parse the lexical traverser: The parser performs grammatical parsing on mTokenIterator. Because the present invention currently supports the parsing of two grammatical structure statements (DECLARE and UPDATE-WHERE), it will first try to parse mTokenIterator using ParserDeclareQuery (DECLARE grammar parser), and then try to parse mTokenIterator using ParserUpdateWhereQuery (UPDATE-WHERE grammar parser) after the parsing fails. If both parsers fail, it means that the grammar of the current statement is wrong and does not conform to any of the above grammatical structures. If one parser parses successfully, a grammar tree object ASTxxx will be generated (AST is the abbreviation of Abstract syntax tree, xxx may be DeclareQuery or UpdateWhereQuery, and the combination of the two words is the corresponding grammar tree name). If the statement on the line where the current character input cursor is located belongs to an incomplete grammatical structure, for example, "DECLARE mAvail=;" is an incomplete DECLARE grammar statement because it lacks the data value on the right side of the assignment operator '='. For such grammatically incomplete statements, the parser will mark error codes during the process of parsing the syntax tree of the statement.

[0064] In some embodiments, the method further comprises: In response to inputting a part of the keywords in the editing area, all the child nodes of the internal structure are traversed, and if there is a member in the child node that includes the part of the keywords, a pop-up window of the keyword prompt is displayed through the recommender; wherein the keywords at least include the grammatical keywords of the script grammar and the comparison operator; Alternatively, in response to inputting a specific sentence for referencing a variable name in the editing area, if the variable name has been defined in the previous text, a prompt word pop-up window matching the specific sentence is displayed through the recommender; wherein the prompt word pop-up window includes at least one variable name to be referenced, and the order of the at least one variable name to be referenced is determined based on the frequency of occurrence in the previous text; Alternatively, in response to inputting a specific structure in the editing area, the recommender displays a prompt word pop-up window corresponding to the specific structure; wherein the prompt word pop-up window includes all structure members included in the specific structure.

[0065] This coding system supports three types of prompt words, namely system keywords, variable names, and right value structure types.

[0066] i. System keywords: DECLARE, UPDATE, WHERE, AND, OR, NOT, IN. These keywords are system prompts commonly used by users to write DECLARE statements and UPDATE-WHERE statements. Figure 6a shown.

[0067] ii. Figure 6a As shown in the figure, when the user enters the keyword WH, the system will traverse all the child nodes of the internal structure SQLInterpreter. If a member name in a child node contains "WH", it is considered that the member name of the child node is the prompt word that needs to be fed back to the user. If the internal structure table contains {INT32:DECLARE;INT32:UPDATE;INT32:WHERE}, the system will traverse the structure content and match "WH" to the third member name "WHERE", so it will notify the recommender to prompt the user with a WHERE prompt word pop-up window.

[0068] iii. Variable name: Both the DECLARE statement and the UPDATE-WHERE statement have syntax for variable assignment. The basic syntax structure for variable assignment is: [DECLARE|UPDATE] variable name = right value; The variable names that meet the above grammatical structure will be "annotated" by the encoding system and the number of occurrences will be recorded. The next time the user tries to enter the "annotated" variable name again, the encoding system will send the matching variable name to the recommender. Figure 6b As shown in the figure, the user enters a space in the 6th line, which is automatically matched to the known variable names "mC" and "mAvail". Because "mC" appears 3 times in the context and "mAvail" appears 2 times, the recommender will give priority to displaying the prompt word "mC" with a higher weight (more occurrences).

[0069] iv. List of right-value structure members: to be compatible with the structure objects used in the actual car C++ project. This system defines many structure types in the structure table. The structures and member names of these structure types are the same as those in the car C++ project. This allows this coding system to have a data basis for providing the same structure member prompt words. In this coding system, users can specify which structure types serve as the "data pool" for prompt words. The words entered by the user can be traversed in the list of these structure types. If nested structures are involved, a breadth-first traversal can be performed to match possible member names from shallow to deep. After the user-entered words match certain member names in these structures, these member names will be sent to the recommender for prompt word pop-up display. Figure 6c shown.

[0070] like Figure 6c As shown in the figure, the user inputs "mHvacSettings.", and the input system detects the character '.'. The system determines that the user is "exploring" the members of the current structure object at this time, and wants to know which members the object before the character '.' has. The system will first copy the content "mHvacSettings" before the '.', and then traverse the global internal structure list, and finally match the structure type ST_CommonStateMachineData with a member name of "mHvacSettings". ST_CommonStateMachineData has multiple sub-members, so the system finally determines that these sub-members are all structure members of "mHvacSettings". The input system notifies the recommender to display a list of prompt words containing these members "..., CC340, CC491, CC500..., ..., mbUsgAndCarType1".

[0071] In some embodiments, the keywords and the structure members are displayed through specific display effects.

[0072] This coding system supports two types of syntax keywords that can be highlighted: system keywords and internal structure members.

[0073] System keywords: DECLARE, UPDATE, WHERE, AND, OR, NOT, IN.

[0074] Internal structure members: The member names contained in the member lists of internal structures and the member lists of nested sub-members.

[0075] The above two types of keywords need to be highlighted in the coding system. The framework of highlighting rules can use the QSyntaxHighlighter class that comes with the Qt framework. We only need to sort out the queues of the above two types of keywords and set them to the QSyntaxHighlighter class object.

[0076] In some embodiments, the method further comprises: In response to the indicator hovering for a specific word in the script sentence in the editing area for a time greater than or equal to a preset time, a grammatical definition of the specific word in the script sentence is displayed in a pop-up window.

[0077] Regarding how to view the grammatical definition of a keyword, the embodiment of the present application realizes that when the mouse moves in the coding area and then hovers over a certain word in the script statement, a pop-up window can automatically display the grammatical definition of the current word in the current script statement after 500ms. The specific steps for implementation are as follows: i. The mouse does not move and hovers for 500ms: rewrite the mouseMoveEvent function. When the mouse moves to a word in the text area, the current mouse position pos can be obtained. When pos changes, the latest position mPos is memorized, and the current timestamp mTime is memorized. A 100ms timer is started in the encoding system. In the 100ms timer, if the time difference between the latest timestamp curTime and mTime is greater than or equal to 500ms, step ii is executed.

[0078] ii. Get the text content of the line where the cursor is located: According to the remembered mouse position mPos, the cursor position of the current text area can be obtained, and according to the cursor position, the text content of the line where the cursor is currently located mLineStr can be obtained, and the content of the word where the cursor is currently located mTokenStr can also be obtained. Then execute step iii.

[0079] iii. Perform lexical analysis on the text content: Use the lexical parser to perform lexical analysis on mLineStr. After lexical analysis, all segmented word queues mTokenIterator will be obtained. This word queue is called a lexical traverser, which stores all word contents and address indexes of the current sentence mLineStr. Then execute step iv.

[0080] iv. The lexical traverser performs grammatical parsing: The grammatical parser performs grammatical parsing on mTokenIterator. Because the present invention currently supports the parsing of two grammatical statements (DECLARE and UPDATE-WHERE), it will first try to parse mTokenIterator using ParserDeclareQuery (DECLARE parser), and then try to parse mTokenIterator using ParserUpdateWhereQuery (UPDATE-WHERE parser) after the parsing fails. If both parsers fail, it means that the grammar of the current statement is wrong and does not conform to any of the above grammatical structures, then the grammatical definition will not be displayed in a pop-up window. If one parser parses successfully, a grammatical tree object ASTxxx will be generated (AST is the abbreviation of Abstract syntax tree, xxx may be DeclareQuery or UpdateWhereQuery), then the parser will perform breadth-first backtracking traversal and matching on the grammatical tree object ASTxxx for the word mTokenStr at the cursor position. If the match fails, the grammatical definition will not be displayed in a pop-up window; if the match is successful, the grammatical definition statement of the keyword mTokenStr will be generated according to the position index of the keyword in the grammatical tree.

[0081] v. Finally, use a pop-up window to display the statement near the cursor position. If the user moves the mouse, the pop-up window will be hidden and the content will be cleared.

[0082] The final effect is as follows Figure 7 As shown in the figure: The current mouse cursor is at mAvail in line 2. If you hover the mouse here for 500ms, the system will pop up the syntax prompt box of mAvail. The format of the syntax prompt box is: keyword + data type + syntax position + data value.

[0083] The above embodiment describes how to generate a syntax tree (a DECLARE syntax tree or an UPDATE-WHERE syntax tree). Next, how to traverse the syntax tree and generate corresponding C++ logic code will be described.

[0084] (1) Get the overall text contentStr of the editing area.

[0085] (2) Split contenStr by line breaks to obtain SQL strings.

[0086] (3) Loop through the SQL string.

[0087] (4) Perform lexical analysis on an SQL string and generate a TokenIterator.

[0088] (5) Perform grammatical analysis on the TokenIterator to generate an AST syntax tree.

[0089] (6) Until all SQL strings are generated into AST syntax trees.

[0090] (7) Loop through the AST syntax tree queue.

[0091] (8) Parse an AST syntax tree into C++ statements until all AST syntax trees are parsed.

[0092] (9) Try to parse an AST syntax tree into a DECLARE syntax tree. If it fails, execute step 10. If it succeeds, read and process the name and field of ASTSetting of ASTDeclareQuery, and then convert them into the C++ assignment statement format of "variable name = value;".

[0093] (10) Try to parse an AST syntax tree into an UPDATE-WHERE syntax tree. If it fails, execute step 8. If it succeeds, first process it according to the C++ if else conditional statement format, first process the WHERE conditional expression syntax tree, and then process the variable assignment syntax tree. The final conversion result is as follows: Figure 8 shown.

[0094] In summary, the embodiments of the present application have the following beneficial effects: Compared with the traditional method of relying on the programmer's brain to analyze the configuration word enabling logic in the document, the embodiment of the present application can quickly and efficiently input the logic script that complies with the rules (judgment of the function configuration word and the power state enabling condition), and then the coding system interprets and generates the configuration word enabling logic code that complies with the C++ standard according to the grammatical rules of the logic script. The embodiment of the present application has the functions of clear and complete syntax tree rule (structure) checking, syntax error backtracking, automatic derivation of prompt words, and continuous learning and optimization of prompt word pop-up priority according to the context, which can generate more standard and unified C++ enabling judgment logic code.

[0095] Based on the same inventive concept, the embodiment of the present application also provides a code generation device based on script syntax corresponding to the code generation method based on script syntax in the first embodiment. Since the principle of solving the problem by the device in the embodiment of the present application is similar to the above-mentioned code generation method based on script syntax, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0096] like Fig. 9 As shown, Fig. 9 1 is a schematic diagram of a code generation device 900 based on script syntax provided in an embodiment of the present application. The code generation device 900 based on script syntax includes: The acquisition module 901 is used to acquire the target text in the editing area; wherein the syntax of the target text is script syntax; A generating module 902 is used to segment the target text to obtain at least one string, and generate a corresponding syntax tree for each string in the at least one string to obtain a syntax tree queue; The conversion module 903 is used to traverse the syntax tree queue and convert each syntax tree in the syntax tree queue based on preset syntax and code conversion rules to obtain target code.

[0097] Those skilled in the art should understand that Fig. 9 The implementation functions of each unit in the script grammar-based code generation device 900 shown can be understood by referring to the relevant description of the aforementioned script grammar-based code generation method. Fig. 9 The functions of the various units in the script grammar-based code generation device 900 shown may be implemented by a program running on a processor, or may be implemented by a specific logic circuit.

[0098] In a possible implementation, the script syntax includes at least a DECLARE syntax and an UPDATE-WHERE syntax; The DECLARE syntax is used to declare variables and assign values. The form of the DECLARE syntax is: DECLARE variable name = value data; wherein the value data includes basic numerical types, built-in enumeration types and string types; During parsing, the type of the variable name is automatically identified based on the data type of the value data; The UPDATE-WHERE syntax is used to update variable values. The form of the UPDATE-WHERE syntax is: UPDATE variable assignment statement, variable assignment statement…variable assignment statement WHERE=conditional statement 1 [comparison operator] conditional statement 2 [comparison operator]…conditional statement N; wherein N is a positive integer, and the syntax of the variable assignment statement is: variable name=[numeric type data] or [enumeration type data] or [string type data]; the comparison operator at least includes equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to, in the numerical set, and not in the numerical set; During parsing, the conditional statement is split into multiple sub-expressions to generate a logical judgment tree.

[0099] In a possible implementation, the generating module 902 further includes: In response to an assignment operation of assigning an enumeration name to a target variable, the target variable is marked as an enumeration type corresponding to the enumeration name based on a preset data table, and recorded in a recommendation engine; wherein the data table is an enumeration table; In response to detecting an assignment operation to the calibrated target variable, a drop-down list is displayed through the recommendation engine; wherein the drop-down list includes all enumeration names corresponding to the enumeration type.

[0100] In a possible implementation, the enumeration table is used to automatically infer the variable type according to the enumeration table when referencing the enumeration value; the enumeration table is a CSV format table; the enumeration table includes at least four field columns: enumeration type, enumeration name, enumeration value, and semantics; The row data in the enumeration table is defined based on project requirements. All row data in the enumeration table are automatically loaded after the system is started, and a global enumeration table is constructed in memory.

[0101] In a possible implementation, the data table also includes an internal structure table, which includes at least five column fields: type name, type group name, actual member value type, type alias and description. The internal structure table is used for nested structure member prompts. The internal structure table is bound to the enumeration table through key values ​​to implement the use of custom enumeration types in the internal structure.

[0102] In a possible implementation, the generating module 902 further includes: In response to inputting characters in the editing area, obtaining a current cursor position in the editing area, and obtaining a current statement in a row where the current cursor is located based on the current cursor position; Performing traversal processing on the current sentence to obtain a string queue; wherein the string queue is a lexical traverser, the lexical traverser is a linear container, and the linear container is used to store all independent word contents and address indexes of the current sentence after lexical analysis; The string queue is parsed by a syntax parser, and if the parsing is successful, a corresponding syntax tree object is generated; if the parsing is unsuccessful, an error code is marked during the parsing; An error code check is performed on the generated syntax tree object, and based on the value of the error code, it is determined whether to prompt a syntax error and / or derive the next input prompt word.

[0103] In a possible implementation, when parsing and generating a syntax tree, the generating module 902 further includes: If any syntax leaf node does not exist or reports an error, the corresponding error code is marked on the current syntax tree node; wherein a syntax leaf node corresponds to at least one sub-syntax tree; Backtrack and exit until the outermost syntax tree object is returned; If the syntax tree object finally obtained is incomplete, the error code of the sub-syntax tree node is read by breadth-first traversal, and a syntax error prompt is given based on the error code.

[0104] In a possible implementation, the generating module 902 further includes: In response to inputting a part of the keywords in the editing area, all the child nodes of the internal structure are traversed, and if there is a member in the child node that includes the part of the keywords, a pop-up window of the keyword prompt is displayed through the recommender; wherein the keywords at least include the grammatical keywords of the script grammar and the comparison operator; Alternatively, in response to inputting a specific sentence for referencing a variable name in the editing area, if the variable name has been defined in the previous text, a prompt word pop-up window matching the specific sentence is displayed through the recommender; wherein the prompt word pop-up window includes at least one variable name to be referenced, and the order of the at least one variable name to be referenced is determined based on the frequency of occurrence in the previous text; Alternatively, in response to inputting a specific structure in the editing area, the recommender displays a prompt word pop-up window corresponding to the specific structure; wherein the prompt word pop-up window includes all structure members included in the specific structure.

[0105] In a possible implementation, the keywords and the structure members are displayed through a specific display effect.

[0106] In a possible implementation, the generating module 902 further includes: In response to the indicator hovering for a specific word in the script sentence in the editing area for a time greater than or equal to a preset time, a grammatical definition of the specific word in the script sentence is displayed in a pop-up window.

[0107] The above-mentioned code generation device based on script grammar has the following beneficial effects: Compared with the traditional method of relying on the programmer's brain to analyze the configuration word enabling logic in the document, the embodiment of the present application can quickly and efficiently input the logic script that complies with the rules (judgment of the function configuration word and the power state enabling condition), and then the coding system interprets and generates the configuration word enabling logic code that complies with the C++ standard according to the grammatical rules of the logic script. The embodiment of the present application has the functions of clear and complete syntax tree rule (structure) checking, syntax error backtracking, automatic derivation of prompt words, and continuous learning and optimization of prompt word pop-up priority according to the context, which can generate more standard and unified C++ enabling judgment logic code.

[0108] like Fig.10 As shown, Fig.10 The present invention provides a schematic diagram of the structure of an electronic device 1000, wherein the electronic device 1000 includes: A processor 1001, a storage medium 1002 and a bus 1003, wherein the storage medium 1002 stores machine-readable instructions executable by the processor 1001. When the electronic device 1000 is running, the processor 1001 communicates with the storage medium 1002 via the bus 1003, and the processor 1001 executes the machine-readable instructions to perform the steps of the code generation method based on script syntax described in the embodiment of the present application.

[0109] In actual application, the components in the electronic device 1000 are coupled together via the bus 1003. It is understood that the bus 1003 is used to realize the connection and communication between these components. In addition to the data bus, the bus 1003 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Fig.10 Various buses are labeled as bus 1003.

[0110] The above electronic device has the following beneficial effects: Compared with the traditional method of relying on the programmer's brain to analyze the configuration word enabling logic in the document, the embodiment of the present application can quickly and efficiently input the logic script that complies with the rules (judgment of the function configuration word and the power state enabling condition), and then the coding system interprets and generates the configuration word enabling logic code that complies with the C++ standard according to the grammatical rules of the logic script. The embodiment of the present application has the functions of clear and complete syntax tree rule (structure) checking, syntax error backtracking, automatic derivation of prompt words, and continuous learning and optimization of prompt word pop-up priority according to the context, which can generate more standard and unified C++ enabling judgment logic code.

[0111] The embodiment of the present application further provides a computer-readable storage medium, which stores executable instructions. When the executable instructions are executed by at least one processor 1001, the code generation method based on script syntax described in the embodiment of the present application is implemented.

[0112] In some embodiments, the storage medium can be a magnetic random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface storage, an optical disk, or a compact disc read-only memory (CD-ROM); it can also be various devices including one or any combination of the above memories.

[0113] In some embodiments, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.

[0114] As an example, executable instructions may, but do not necessarily, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, for example, in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (for example, files storing one or more modules, subroutines, or code portions).

[0115] By way of example, executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or on multiple computing devices distributed across multiple sites and interconnected by a communication network.

[0116] The computer-readable storage medium has the following advantages: Compared with the traditional method of relying on the programmer's brain to analyze the configuration word enabling logic in the document, the embodiment of the present application can quickly and efficiently input the logic script that complies with the rules (judgment of the function configuration word and the power state enabling condition), and then the coding system interprets and generates the configuration word enabling logic code that complies with the C++ standard according to the grammatical rules of the logic script. The embodiment of the present application has the functions of clear and complete syntax tree rule (structure) checking, syntax error backtracking, automatic derivation of prompt words, and continuous learning and optimization of prompt word pop-up priority according to the context, which can generate more standard and unified C++ enabling judgment logic code.

[0117] In the several embodiments provided in the present application, it should be understood that the disclosed methods and electronic devices can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

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

[0119] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0120] 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, including several instructions for a computer device (which can be a personal computer, a platform server, or a network device, etc.) to perform 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 USB flash drives, mobile hard drives, ROM, RAM, magnetic disks, or optical disks.

[0121] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A code generation method based on script grammar, characterized in that: The method comprises: Acquire the target text in the editing area; wherein the syntax of the target text is script syntax; Segmenting the target text to obtain at least one character string, and generating a corresponding syntax tree for each character string in the at least one character string to obtain a syntax tree queue; The syntax tree queue is traversed, and each syntax tree in the syntax tree queue is converted based on preset syntax and code conversion rules to obtain target code.

2. The method according to claim 1, characterized in that The script syntax includes at least DECLARE syntax and UPDATE-WHERE syntax; The DECLARE syntax is used to declare variables and assign values. The form of the DECLARE syntax is: DECLARE variable name = value data; wherein the value data includes basic numerical types, built-in enumeration types and string types; During parsing, the type of the variable name is automatically identified based on the data type of the value data; The UPDATE-WHERE syntax is used to update variable values. The form of the UPDATE-WHERE syntax is: UPDATE variable assignment statement, variable assignment statement…variable assignment statement WHERE=conditional statement 1 [comparison operator] conditional statement 2 [comparison operator]…conditional statement N; wherein N is a positive integer, and the syntax of the variable assignment statement is: variable name=[numeric type data] or [enumeration type data] or [string type data]; the comparison operator at least includes equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to, in the numerical set, and not in the numerical set; During parsing, the conditional statement is split into multiple sub-expressions to generate a logical judgment tree.

3. The method according to claim 1, characterized in that The method further comprises: In response to an assignment operation of assigning an enumeration name to a target variable, the target variable is marked as an enumeration type corresponding to the enumeration name based on a preset data table, and recorded in a recommendation engine; wherein the data table is an enumeration table; In response to detecting an assignment operation to the calibrated target variable, a drop-down list is displayed through the recommendation engine; wherein the drop-down list includes all enumeration names corresponding to the enumeration type.

4. The method according to claim 3, characterized in that The enumeration table is used to automatically infer the variable type according to the enumeration table when referencing the enumeration value; the enumeration table is a CSV format table; the enumeration table includes at least four field columns: enumeration type, enumeration name, enumeration value, and semantics; The row data in the enumeration table is defined based on project requirements. All row data in the enumeration table are automatically loaded after the system is started, and a global enumeration table is constructed in memory.

5. The method according to claim 3, characterized in that: The data table also includes an internal structure table, which includes at least five column fields: type name, type group name, actual member value type, type alias and description. The internal structure table is used for nested structure member prompts. The internal structure table is bound to the enumeration table through key values ​​to realize the use of custom enumeration types in the internal structure.

6. The method according to claim 1, characterized in that The method further comprises: In response to inputting characters in the editing area, obtaining a current cursor position in the editing area, and obtaining a current statement in a row where the current cursor is located based on the current cursor position; Performing traversal processing on the current sentence to obtain a string queue; wherein the string queue is a lexical traverser, the lexical traverser is a linear container, and the linear container is used to store all independent word contents and address indexes of the current sentence after lexical analysis; The string queue is parsed by a syntax parser, and if the parsing is successful, a corresponding syntax tree object is generated; if the parsing is unsuccessful, an error code is marked during the parsing; An error code check is performed on the generated syntax tree object, and based on the value of the error code, it is determined whether to prompt a syntax error and / or derive the next input prompt word.

7. The method according to claim 6, characterized in that When parsing and generating a syntax tree, the method further includes: If any syntax leaf node does not exist or reports an error, the corresponding error code is marked on the current syntax tree node; wherein a syntax leaf node corresponds to at least one sub-syntax tree; Backtrack and exit until the outermost syntax tree object is returned; If the syntax tree object finally obtained is incomplete, the error code of the sub-syntax tree node is read by breadth-first traversal, and a syntax error prompt is given based on the error code.

8. The method according to claim 2, characterized in that: The method further comprises: In response to inputting a part of the keywords in the editing area, all the child nodes of the internal structure are traversed, and if there is a member in the child node that includes the part of the keywords, a pop-up window of the keyword prompt is displayed through the recommender; wherein the keywords at least include the grammatical keywords of the script grammar and the comparison operator; Alternatively, in response to inputting a specific sentence for referencing a variable name in the editing area, if the variable name has been defined in the previous text, a prompt word pop-up window matching the specific sentence is displayed through the recommender; wherein the prompt word pop-up window includes at least one variable name to be referenced, and the order of the at least one variable name to be referenced is determined based on the frequency of occurrence in the previous text; Alternatively, in response to inputting a specific structure in the editing area, the recommender displays a prompt word pop-up window corresponding to the specific structure; wherein the prompt word pop-up window includes all structure members included in the specific structure.

9. The method according to claim 8, characterized in that The keywords and the structure members are displayed through specific display effects.

10. The method according to claim 1, characterized in that The method further comprises: In response to the indicator hovering for a specific word in the script sentence in the editing area for a time greater than or equal to a preset time, a grammatical definition of the specific word in the script sentence is displayed in a pop-up window.

Citation Information

Patent Citations

  • Database access statement writing recommendation method and device and electronic equipment

    CN117493673A

  • SQL (Structured Query Language) code prompting method based on keyword backtracking and Token sorting

    CN118113264A

  • Code file conversion method and device, equipment, medium and product

    CN118860354A

Cited By

  • Method and device for generating programming language according to clinical DVP table

    CN120929062A