Expression editing method, device, equipment and product
By lexical and syntax analysis of expressions in the editing box of the simulation software, detecting errors in real time and providing exception prompts, the problem of independent code writing of each editing box in the existing technology is solved, which improves work efficiency and user experience, and reduces development and maintenance costs.
Patent Information
- Application Number
- CN202411842431.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-03-21
AI Technical Summary
In existing simulation software, each editing box writes code independently, which has a huge workload and high error rate, lacks flexibility and versatility, resulting in increased development and maintenance costs.
By obtaining the expressions entered in the edit box, performing lexical and syntax analysis, detecting errors in real time and providing exception prompts, supporting automatic completion prompts, reducing duplicate code and improving code maintainability.
It realizes real-time detection of errors during user input, reduces input expressions that do not comply with specifications, improves work efficiency and user experience, and reduces development and maintenance costs.
Smart Images

Figure CN119668581A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an expression editing method, device, equipment and product. Background Art
[0002] In modern Computer-Aided Engineering (CAE) simulation software, expressions are widely used. These expressions can not only perform mathematical operations, but also dynamically adjust the position, direction and other properties of elements in the model by referencing functions or parameters, establish complex cascade relationships, achieve real-time feedback and visual debugging, and define input and output interfaces to exchange data with other modules or software.
[0003] Since almost every attribute in the model can be expressed by an expression, there are a large number of edit boxes in the user interface of the simulation software that need to support the editing function of such expressions. However, traditional edit box designs are usually customized for specific purposes and lack flexibility and versatility, resulting in a large amount of duplicate code and increasing development and maintenance costs. In addition, there are a large number of edit boxes in the simulation software that need to use expressions, and writing code for each edit box independently is a huge workload and has a high error rate.
[0004] Therefore, it is necessary to propose a new expression editing method. Summary of the invention
[0005] In view of this, an embodiment of the present invention is dedicated to providing an expression editing method to solve the problem of huge workload and high error rate in independently writing codes for each editing box in the prior art simulation software.
[0006] According to a first aspect of an embodiment of the present application, a method for editing an expression is provided, the method comprising:
[0007] Get the expression entered in the edit box;
[0008] Parsing the expression to obtain a parsing result;
[0009] When the parsing result is normal, a calculation result is obtained according to the expression; the parsing result is normal means that the parsing result conforms to the lexical and grammatical structure of the expression editing; or,
[0010] When there is an abnormality in the analysis result, an abnormality prompt is given.
[0011] In a possible design of the first aspect, parsing the expression to obtain a parsing result includes:
[0012] The expression is lexically parsed by comparing it with a pre-built dictionary tree to obtain parsed words; the dictionary tree is constructed by parsing the pre-collected function names and supported operators;
[0013] Performing grammatical analysis on the parsed word to obtain an operator and a value;
[0014] The operator and the value are determined as the parsing result.
[0015] In a possible design of the first aspect, when the parsing result is normal, obtaining the calculation result according to the expression includes:
[0016] When there is no abnormality in the operator or the value, adding the operator and the value as symbol objects to a reverse Polish notation queue;
[0017] Calculate the reverse Polish sequence and output the calculation result.
[0018] In a possible design of the first aspect, when there is an abnormality in the analysis result, providing an abnormality prompt includes:
[0019] When there is an abnormality in the arrangement of the analyzed words, an abnormality prompt is given.
[0020] In a possible design of the first aspect, when there is an abnormality in the analysis result, providing an abnormality prompt includes:
[0021] When there is an abnormality in the operator or the value, an abnormality prompt is given.
[0022] In a possible design of the first aspect, before obtaining a calculation result by calculating according to the expression, the method further includes:
[0023] Display auto-completion hints related to the parsed result.
[0024] In a possible design of the first aspect, before obtaining the expression input in the edit box, the method further includes:
[0025] When an editing event in the editing box is monitored, a parsing timer is started;
[0026] The expression input in the acquisition edit box includes:
[0027] When the parsing timer reaches a set time point, the expression input in the edit box is obtained.
[0028] According to a second aspect of an embodiment of the present application, there is provided an expression editing device, the device comprising:
[0029] The acquisition module is used to obtain the expression entered in the edit box;
[0030] A parsing module, used for parsing the expression to obtain a parsing result;
[0031] A calculation module, used for obtaining a calculation result according to the expression when the parsing result is normal; the parsing result is normal means that the parsing result conforms to the lexical and grammatical structure of the expression editing;
[0032] The prompt module is used to give an abnormal prompt when there is an abnormality in the analysis result.
[0033] According to a third aspect of an embodiment of the present application, there is provided an electronic device, including a memory and a processor;
[0034] The memory is connected to the processor and is used for storing programs;
[0035] The processor is used to implement an expression editing method as described in any one of the first aspects of the embodiments of the present application by running a program in a memory.
[0036] According to a fourth aspect of an embodiment of the present application, a computer program product is provided, comprising computer program instructions. When the computer program instructions are executed by a processor, the processor executes an expression editing method as described in any one of the first aspects of the embodiment of the present application.
[0037] According to the fifth aspect of the embodiments of the present application, a chip is provided, including a processor and a data interface, and the processor reads and runs the program stored in the memory through the data interface to execute the expression editing method as any one of the first aspects of the embodiments of the present application.
[0038] According to the sixth aspect of the embodiments of the present application, a storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, an expression editing method as described in any one of the first aspects of the embodiments of the present application is implemented.
[0039] According to the technical solution of the embodiment of the present application, by
[0040] Get the expression entered in the edit box; parse the expression to obtain the parsing result; when there is no abnormality in the parsing result, calculate the result according to the expression; the parsing result is no abnormality means that the parsing result conforms to the lexical and grammatical structure of the expression edit; or, when there is an abnormality in the parsing result, give an abnormal prompt. According to the present application, by parsing the expression lexical and grammatical structure, errors can be detected in real time during the user input process, and the user can be prompted when there is an abnormality in the parsing, so as to prevent the user from entering an expression that does not conform to the specification. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0042] Figure 1 A flowchart of an expression editing method provided in an embodiment of the present application;
[0043] Figure 2 A flowchart of another expression editing method provided in an embodiment of the present application;
[0044] Figure 3 A schematic diagram of an automatic completion prompt in the expression editing method provided in an embodiment of the present application;
[0045] Figure 4 A flowchart of another expression editing method provided in an embodiment of the present application;
[0046] Figure 5 A schematic diagram of the structure of an expression editing device provided in an embodiment of the present application;
[0047] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0049] In modern computer-aided engineering (CAE) simulation software, expressions are widely used, almost penetrating every design and analysis link. These expressions can not only perform complex mathematical operations, but also dynamically adjust the position, direction, size, material properties, etc. of elements in the model by referencing functions or parameters, establish complex cascade relationships, achieve real-time feedback and visual debugging, and define input and output interfaces to exchange data with other modules or software. This flexibility enables users to create highly customized models to meet the needs of various complex engineering problems.
[0050] Specifically, expressions can include basic arithmetic operations (such as addition, subtraction, multiplication, and division), advanced mathematical functions (such as trigonometric functions, logarithmic functions, power functions, etc.), as well as logical operations and conditional judgments. This allows users to accurately describe various relationships in physical phenomena and engineering calculations.
[0051] Through expressions, users can define various attributes in the model as variables or functions to achieve dynamic adjustment. For example, the length of a part can be associated with the height H of another part through the expression L=H+50. When the latter changes, the former will also be automatically updated. The establishment of this dependency makes the model more flexible and intelligent.
[0052] Expressions can be used to build complex dependencies between model elements. For example, the position of one component may depend on the size or position of another component, or the magnitude of a force may depend on changes in temperature. With expressions, these dependencies can be clearly defined, forming a complex cascading system. When any upstream element changes, all downstream elements that depend on it are automatically recalculated and updated, ensuring consistency and accuracy throughout the model.
[0053] Modern CAE simulation software usually provides real-time feedback function, users can immediately see the result value or model changes when entering expressions. This is very helpful for quickly verifying the correctness of expressions and adjusting model parameters. In addition, some advanced expression editing boxes also support visual debugging tools, such as charts or animations, to display the calculation process and results of expressions, so that users can more intuitively understand the impact of expressions and make necessary optimizations.
[0054] In some application scenarios, expressions can not only be used to define the internal properties of the model, but also as an interface to exchange data with other modules or software. For example, expressions can be used to define input and output parameters and connect the model with external data sources or control systems. This helps to achieve multidisciplinary collaborative simulation and optimized design, and improve overall work efficiency.
[0055] Although expressions play such an important role in CAE simulation software, the traditional edit box design still has many limitations and is difficult to meet the needs of users. Specifically, traditional edit boxes are usually customized for specific purposes and lack flexibility and versatility. Each edit box is implemented independently, resulting in a large amount of duplicate code and increasing development and maintenance costs. This design approach is not only inefficient, but also prone to errors, especially when dealing with a large number of different types of expressions.
[0056] Secondly, traditional editing boxes are often simple in processing expressions and fail to provide sufficient user interaction support, such as real-time function association, automatic completion, instant error checking and prompts, etc. This makes it difficult and requires a high learning curve for users to write complex expressions, affecting their productivity and satisfaction.
[0057] Based on this, this application proposes a new expression editing method that can reduce duplicate code and improve code maintainability and reusability by componentizing the expression editing box. The componentized design allows developers to more easily manage and optimize the expression processing flow, ensuring the stability and consistency of the entire system.
[0058] Secondly, the expression editing method proposed in this application can provide rich user interaction functions, such as function association, automatic completion, instant error checking and prompting, result value display, etc., to help users write and debug expressions more efficiently. Through intelligent interactive design, users can get timely help and feedback during the input process, reduce the learning curve, and improve work efficiency. At the same time, in the scheme of this application, by adopting a unified parsing and calculation logic, it is ensured that the processing process of the expression is consistent and reliable. Through strict lexical and grammatical parsing, input errors can be detected and corrected regularly to prevent calculation failures or abnormal results caused by grammatical or logical errors.
[0059] The following specific embodiments are used to describe in detail the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0060] For example, Figure 1 A flowchart of an expression editing method provided in an embodiment of the present application. Figure 1 In an exemplary embodiment, the provided expression editing method may include the following steps 1100 to 1400:
[0061] 1100. Get the expression entered in the edit box.
[0062] 1200. Parse the expression to obtain a parsing result.
[0063] 1300. When there is no abnormality in the parsing result, the calculation result is obtained according to the expression calculation; the parsing result having no abnormality means that the parsing result conforms to the lexical and grammatical structure of the expression editing.
[0064] 1400. When there is an abnormality in the parsing result, an abnormal prompt is given.
[0065] Usually, in addition to data calculation functions, user-entered expressions also include simulation software-defined functions and references to other objects. Customized functions have function names and function parameters. Function parameters have type restrictions and number restrictions. Parameter types can be integer, floating point, 3D vector, or the name of a certain type of modeling element, or a parameter reference. Parameters can be optional or indefinite, so the number of parameters is an interval. Referencing other objects means using the name of another object to use its value.
[0066] When the user enters an expression in the edit box, the expression in the edit box is obtained in real time and parsed. The parsing of the expression is divided into lexical parsing and syntactic parsing. Among them, lexical parsing is the first step in the parsing process. Its main task is to split the input expression into a series of meaningful unit symbols, which are called tokens. It should be noted that a token is the smallest semantic unit in an expression, usually including keywords, identifiers, constants, operators, separators, etc. Lexical parsing is to identify and classify different tokens according to predefined lexical rules. The main task of syntactic parsing is to verify whether the token stream meets the structural requirements of the language according to predefined grammatical rules. Syntactic rules define the structure of legal expressions, statements, function calls, etc.
[0067] Specifically, in step 1200, the expression is lexically parsed by comparing with the pre-built dictionary tree to obtain parsed words, and the parsed words are grammatically parsed to obtain operators and values, where the operators and values are the parsing results.
[0068] The dictionary tree is constructed by parsing the pre-collected function names and supported operators. In this embodiment, the pre-collected function names include custom function names and general function names. The supported operators refer to the operators supported by the custom function names and the parameters supported by the general function names. At the same time, the parameter number range, parameter type, return value type, etc. are also collected. In addition, when the user imports a model or creates a new modeling element, the modeling element type and name are also collected in real time. The above-collected function names and operators are parsed as keywords to construct the dictionary tree.
[0069] In the above parsing process, if the parsing result is normal, that is, the operator and the value conform to the lexical and grammatical requirements of the expression editor, indicating that the operator and the value are normal, then the operator and the value are added to the Reverse Polish Notation queue as symbol objects; the Reverse Polish Notation queue is calculated, and the calculation result is output. During the parsing process, if a function name is encountered, a function symbol is created, and then function parsing, parameter verification, and parameter parsing are performed. After the function parsing is completed, it is added to the Reverse Polish Notation queue. Among them, Reverse Polish Notation is a method of expressing mathematical expressions, in which the operator is located after the operand. For example, the expression 1+2*3 is expressed as 123*+ in Reverse Polish Notation.
[0070] It should be noted that when parsing an expression, when an operator is encountered, the operator can be followed by two different contents, namely a function call or a parameter object name. At this time, it is necessary to identify these two cases and collect the string following the operator for further parsing and processing. In other words, if the operator is followed by a function call, the function name and its parameters need to be identified. If the operator is followed by a parameter object name, the identifier needs to be identified and processed as an operand.
[0071] In some cases, the function parameter may be a certain element type name rather than a specific value or variable. For example, in CAE simulation software, the user may define a function to operate on specific elements in the model, such as parts, materials, boundary conditions, etc. These elements usually have a unique identifier or name, and the function needs to find the corresponding object based on this name.
[0072] When this type of parameter is encountered during expression parsing, it is necessary to be able to identify that this is an element type name, not an ordinary value or variable. If the element corresponding to the name cannot be found, or the name does not conform to the expected format, the operation string, that is, the original text entered by the user, is collected, and an exception is fed back to prompt the user that the input is wrong or provide correction suggestions.
[0073] In addition, in an expression, a function parameter may itself be a function call. In this case, it is necessary to be able to identify and handle nested functions, that is, a function call as a parameter of another function. The parsing process of nested functions is relatively complex because it involves a nested structure of multiple layers of function calls.
[0074] In order to correctly handle nested functions, a symbol is usually created for each nested function and used as an independent parsing unit. Specifically, a temporary symbol is created for each nested function to represent the call of the function. This symbol can be the function name plus its parameter list, or other unique identifiers. When a function call is parsed, the parsing of the current function is paused, and the nested function call is parsed first until the nested function is completely parsed, then the parent function is returned to continue parsing the remaining parameters. This ensures that all nested functions are parsed correctly. Finally, the parsed functions and their parameters are stored in the queue in reverse Polish order.
[0075] For example, when encountering a function call, check if the function's argument is also a function call. If so, enter the parsing process for the nested function. Create a symbol for the nested function to represent the call of the function. This symbol can be the function name plus its argument list, or some other unique identifier. Pause parsing of the current function and recursively parse the nested functions. Repeat the above steps until all nested functions have been parsed, return to the parent function, and continue parsing the remaining arguments. Resume parsing step by step according to the nested hierarchy to ensure that all functions are processed correctly. Store the parsed functions and their arguments in a queue in reverse Polish notation order. Reverse Polish notation ensures that the expression is evaluated in the correct order and avoids the complexity caused by parentheses. After parsing is completed, the elements in the reverse Polish notation queue can be used for subsequent calculations or execution.
[0076] This mechanism enables the solution of this embodiment to correctly handle complex expression structures and supports users to write flexible and diverse mathematical formulas and function calls.
[0077] The above describes the case where the parsing result is normal. In this embodiment, an abnormality prompt is given when the parsing result is abnormal. Specifically, an abnormality prompt is given when the arrangement of the parsed words is abnormal. Similarly, an abnormality prompt is given when an operator or a value is abnormal.
[0078] According to the technical solution of this embodiment, the expression entered in the edit box is obtained; the expression is parsed to obtain the parsing result; when there is no abnormality in the parsing result, the calculation result is obtained according to the expression calculation; the parsing result is normal means that the parsing result conforms to the lexical and grammatical structure of the expression edit; or, when there is an abnormality in the parsing result, an abnormality prompt is given. According to the present application, by parsing the expression lexical and grammatical structure, errors can be detected in real time during the user input process, and the user can be prompted when there is an abnormality in the parsing, so as to prevent the user from entering an expression that does not conform to the specification.
[0079] Figure 2A flowchart of another expression editing method provided in an embodiment of the present application. Figure 2 In an exemplary embodiment, the provided expression editing method may include the following steps 2100 to 2400:
[0080] 2100. Get the expression entered in the edit box.
[0081] 2200. Parse the expression to obtain a parsing result.
[0082] 2300. When there is no abnormality in the parsing result, the auto-completion prompt related to the parsing result is displayed.
[0083] 2400. The calculation result is obtained according to the expression calculation; the parsing result is normal, which means that the parsing result conforms to the lexical and grammatical structure of the expression editing.
[0084] 2500. When there is an exception in the parsing result, an exception prompt will be given.
[0085] When the user enters an expression in the edit box, the expression entered in the edit box is obtained, and the obtained expression is lexically parsed and parsed to generate a parsing result. For example, the expression string is split into a series of meaningful tokens, such as numbers, operators, function names, variables, etc. Then, according to the predefined grammar rules, it is checked whether these tokens form a legal expression structure.
[0086] If the parsed result of the expression has no syntax errors, intelligent auto-completion tips are provided based on the parsed result to help users complete the expression writing more efficiently. For example, based on the contextual information in the parsed result, the functions, variables, constants, units, etc. that the user may need are inferred, and corresponding completion suggestions are generated. For example, if the user enters part of the function name, a matching function list can be provided; if the user enters part of the variable name, a matching variable list can be provided.
[0087] Specifically, a drop-down menu can be displayed below or next to the edit box to list all possible completion options. Users can select the appropriate option using the keyboard or mouse to quickly complete the input, such as Figure 3 As the user continues to type, the auto-complete suggestions are updated in real time to ensure that the suggestions are always relevant to the current input context.
[0088] If there is no syntax error in the parsed expression, the system will perform calculations based on the parsed expression and display the calculation results.
[0089] According to the technical solution of this embodiment, the expression entered in the edit box is obtained. The expression is parsed to obtain the parsing result. When there is no abnormality in the parsing result, the automatic completion prompt related to the parsing result is displayed. The calculation result is obtained according to the expression calculation; no abnormality in the parsing result means that the parsing result conforms to the lexical and grammatical structure of the expression editing. When there is an abnormality in the parsing result, an abnormality prompt is given. By performing lexical and grammatical parsing on the expression, errors can be detected in real time during the user input process, and the user can be prompted when there is an abnormality in the parsing, so as to prevent the user from entering an expression that does not conform to the specification. At the same time, when there is no abnormality in the parsing, the automatic completion prompt related to the parsing result is displayed to assist the user in writing and debugging expressions more efficiently and improve work efficiency.
[0090] Figure 4 A flowchart of another expression editing method provided in an embodiment of the present application. Figure 4 In an exemplary embodiment, the provided expression editing method may include the following steps 4100 to 4400:
[0091] 4100. When an editing event in the edit box is monitored, a parsing timer is started.
[0092] 4200. When the parsing timer reaches the set time point, obtain the expression entered in the edit box.
[0093] 4300. Parse the expression to obtain a parsing result.
[0094] 4400. When there is no abnormality in the parsing result, the auto-completion prompt related to the parsing result is displayed.
[0095] 4500. The calculation result is obtained according to the expression calculation; the parsing result is normal, which means that the parsing result conforms to the lexical and grammatical structure of the expression editing.
[0096] 4600. When there is an exception in the parsing result, an exception prompt will be given.
[0097] In this embodiment, in order to reduce unnecessary consumption of computing resources, a delayed parsing strategy is adopted when the user enters an expression. Specifically, when an editing event in the edit box is monitored, the parsing operation is not started immediately, but a parsing timer is started. When the parsing timer reaches the set time point, the expression entered in the edit box is obtained for parsing. This can avoid frequent triggering of parsing operations when the user frequently inputs, thereby improving performance and response speed. Among them, the editing event can refer to any input operation performed by the user in the edit box, such as pressing a key, deleting, pasting, etc.
[0098] The implementation of step 4300 to step 4600 may refer to the relevant description in the above embodiment and will not be repeated here.
[0099] According to the technical solution of this embodiment, when the editing event in the edit box is monitored, the parsing timer is started. When the parsing timer reaches the set time point, the expression entered in the edit box is obtained. The expression is parsed to obtain the parsing result. When there is no abnormality in the parsing result, the automatic completion prompt related to the parsing result is displayed. The calculation result is obtained according to the expression calculation; the parsing result is normal means that the parsing result conforms to the lexical and grammatical editing of the expression. When there is an abnormality in the parsing result, an abnormal prompt is given. According to this embodiment, by starting the parsing expression when the editing event is started, the expression can be parsed regularly, reducing the problem of high performance overhead caused by the existing fast and multiple parsing expressions. In addition, by parsing the expression lexical and grammatical, errors can be detected in real time during the user input process, and the user can be prompted when there is an abnormality in the parsing to avoid the user inputting an expression that does not conform to the specification. At the same time, when there is no abnormality in the parsing, the automatic completion prompt related to the parsing result is displayed to assist the user in writing and debugging expressions more efficiently and improve work efficiency.
[0100] Exemplary Devices
[0101] Accordingly, the present application also provides a device, such as Figure 5 As shown, the expression editing device 500 provided in this embodiment may include: an acquisition module 510 , a parsing module 520 , a calculation module 530 and a prompt module 540 .
[0102] The acquisition module 510 is used to acquire the expression input in the edit box.
[0103] The parsing module 520 is used to parse the expression and obtain a parsing result.
[0104] The calculation module 530 is used to obtain a calculation result according to the expression calculation when the parsing result is normal; the parsing result is normal means that the parsing result conforms to the lexical and grammatical structure of the expression editing.
[0105] The prompt module 540 is used to give an abnormal prompt when there is an abnormality in the parsing result.
[0106] In a feasible implementation, the parsing module 520 can be specifically used to perform lexical analysis on the expression against a pre-constructed dictionary tree to obtain parsed words; the dictionary tree is constructed after parsing the pre-collected function names and supported operators; the parsed words are syntactically parsed to obtain operators and values; the operators and values are determined as parsing results.
[0107] In a feasible implementation, the calculation module 530 may be specifically configured to add the operator and the value as symbol objects to the reverse Polish notation queue when there is no abnormality in the operator or the value; calculate the reverse Polish notation queue, and output the calculation result.
[0108] In a feasible implementation, the prompt module 540 may be specifically configured to provide an abnormality prompt when there is an abnormality in the arrangement of the parsed words.
[0109] In a feasible implementation, the prompt module 540 may be specifically configured to provide an exception prompt when an operator or a value is abnormal.
[0110] In a feasible implementation, the prompt module 540 may also be used to display automatic completion prompts related to the parsing results.
[0111] In a feasible implementation, the expression editing device 500 may further include a start module for starting a parsing timer when an editing event in the edit box is monitored. Correspondingly, the acquisition module 510 may be used to acquire the expression input in the edit box when the parsing timer reaches a set time point.
[0112] The expression editing device provided in this embodiment belongs to the same application concept as the expression editing method provided in the above embodiments of this application, can execute the expression editing method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of executing the expression editing method. For the technical details not described in detail in this embodiment, please refer to the specific processing content of the expression editing method provided in the above embodiments of this application, which will not be repeated here.
[0113] It should be understood that the modules in the above devices can be implemented in the form of a processor calling software. For example, the device includes a processor, the processor is connected to a memory, and instructions are stored in the memory. The processor calls the instructions stored in the memory to implement any of the above methods or realize the functions of each unit of the device, wherein the processor can be a general-purpose processor, such as a CPU or a microprocessor, etc., and the memory can be a memory in the device or a memory outside the device. Alternatively, the unit in the device can be implemented in the form of a hardware circuit, and the functions of some or all units can be realized by designing the hardware circuit. The hardware circuit can be understood as one or more processors; for example, in one implementation, the hardware circuit is an ASIC, and the functions of some or all of the above units are realized by designing the logical relationship of the components in the circuit; for another example, in another implementation, the hardware circuit can be implemented by PLD, taking FPGA as an example, which can include a large number of logic gate circuits, and the connection relationship between the logic gate circuits is configured by a configuration file, so as to realize the functions of some or all of the above units. All units of the above devices can be implemented in the form of a processor calling software, or in the form of a hardware circuit, or in part by a processor calling software, and the remaining part is implemented in the form of a hardware circuit.
[0114] In an embodiment of the present application, a processor is a circuit with the ability to process signals. In one implementation, the processor may be a circuit with the ability to read and run instructions, such as a CPU, a microprocessor, a GPU, or a DSP; in another implementation, the processor may implement certain functions through the logical relationship of a hardware circuit, and the logical relationship of the hardware circuit is fixed or reconfigurable, such as a hardware circuit implemented by an ASIC or PLD, such as an FPGA. In a reconfigurable hardware circuit, the process of the processor loading a configuration document to implement the hardware circuit configuration can be understood as the process of the processor loading instructions to implement the functions of some or all of the above units. In addition, it can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as an NPU, TPU, DPU, etc.
[0115] It can be seen that each unit in the above device can be one or more processors (or processing circuits) configured to implement the above method, such as: CPU, GPU, NPU, TPU, DPU, microprocessor, DSP, ASIC, FPGA, or a combination of at least two of these processor forms.
[0116] In addition, all or part of the units in the above device can be integrated together, or can be implemented independently. In one implementation, these units are integrated together and implemented in the form of a SOC. The SOC may include at least one processor for implementing any of the above methods or implementing the functions of each unit of the device. The type of the at least one processor may be different, for example, including a CPU and an FPGA, a CPU and an artificial intelligence processor, a CPU and a GPU, etc.
[0117] Exemplary Electronic Devices
[0118] The present application embodiment provides an electronic device, see Figure 6 As shown, the electronic device includes a memory 600 and a processor 610 connected to the memory 600 .
[0119] The memory 600 is used to store programs.
[0120] Processor 610 is used to execute any expression editing method of any of the above embodiments, by obtaining the expression input in the edit box; parsing the expression to obtain the parsing result; when there is no abnormality in the parsing result, the calculation result is obtained according to the expression calculation; the parsing result is normal means that the parsing result conforms to the lexical and grammatical of the expression editing; or, when there is an abnormality in the parsing result, an abnormal prompt is given. According to the present application, by parsing the expression lexical and grammatical, errors can be detected in real time during the user input process, and the user can be prompted when there is an abnormality in the parsing, so as to prevent the user from entering an expression that does not conform to the specification.
[0121] The specific processing process of the processor 610 can refer to the introduction of the above method embodiment, and the specific implementation of the processor 610 can also refer to the introduction of the above embodiment.
[0122] Specifically, the electronic device may further include: a bus, a communication interface 620 , an input device 630 and an output device 640 .
[0123] The processor 610, the memory 600, the communication interface 620, the input device 630 and the output device 640 are connected to each other via a bus.
[0124] A bus may include a pathway that transfers information between components of a computer system.
[0125] The processor 610 may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. 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, discrete hardware components.
[0126] The processor 610 may include a main processor, and may also include a baseband chip, a modem, and the like.
[0127] The memory 600 stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes a computer operation instruction. More specifically, the memory 600 may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.
[0128] The input device 630 may include a device for receiving data and information input by a user, such as an error microphone, a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.
[0129] Output device 640 may include devices that allow information to be output to a user, such as a speaker, display screen, printer, speakers, etc.
[0130] The communication interface 620 may include any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, a radio access network (RAN), a wireless local area network (WLAN), etc.
[0131] The processor 610 executes the program stored in the memory 600 and calls other devices, which can be used to implement the various steps of any expression editing method provided in the above embodiments of the present application.
[0132] An embodiment of the present application also proposes a chip, which includes a processor and a data interface. The processor reads and runs the program stored in the memory through the data interface to execute the expression editing method introduced in any of the above embodiments. The specific processing process and its beneficial effects can be found in the introduction to the embodiment of the above expression editing method.
[0133] Exemplary computer program products and storage media
[0134] In addition to the above-mentioned methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps of the expression editing method according to various embodiments of the present application described in any of the above embodiments of this specification.
[0135] The computer program product may be written in any combination of one or more programming languages to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0136] In addition, the embodiment of the present application may also be a storage medium on which a computer program is stored. The computer program is executed by a processor to execute the steps of the expression editing method according to various embodiments of the present application described in any of the above embodiments of this specification, and specifically the following steps may be implemented:
[0137] 1100. Get the expression entered in the edit box.
[0138] 1200. Parse the expression to obtain a parsing result.
[0139] 1300. When there is no abnormality in the parsing result, the calculation result is obtained according to the expression calculation; the parsing result having no abnormality means that the parsing result conforms to the lexical and grammatical structure of the expression editing.
[0140] 1400. When there is an abnormality in the parsing result, an abnormal prompt is given.
[0141] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0142] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0143] The steps in the methods of each embodiment of the present application can be adjusted in order, combined and deleted according to actual needs, and the technical features recorded in each embodiment can be replaced or combined.
[0144] The modules and sub-modules in the devices and terminals of the various embodiments of the present application can be combined, divided and deleted according to actual needs.
[0145] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0146] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0147] In addition, each functional module or submodule in each embodiment of the present application may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.
[0148] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0149] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0150] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0151] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for editing an expression, characterized in that: The method comprises: Get the expression entered in the edit box; Parsing the expression to obtain a parsing result; When the parsing result is normal, a calculation result is obtained according to the expression; the parsing result is normal means that the parsing result conforms to the lexical and grammatical structure of the expression editing; or, When there is an abnormality in the analysis result, an abnormality prompt is given.
2. The method according to claim 1, characterized in that The step of parsing the expression to obtain a parsing result includes: The expression is lexically parsed by comparing it with a pre-built dictionary tree to obtain parsed words; the dictionary tree is constructed by parsing the pre-collected function names and supported operators; Performing grammatical analysis on the parsed word to obtain an operator and a value; The operator and the value are determined as the parsing result.
3. The method according to claim 2, characterized in that When the parsing result is normal, the calculation result is obtained according to the expression, including: When there is no abnormality in the operator or the value, adding the operator and the value as symbol objects to a reverse Polish notation queue; Calculate the reverse Polish sequence and output the calculation result.
4. The method according to claim 2, characterized in that: When the analysis result is abnormal, an abnormal prompt is given, including: When there is an abnormality in the arrangement of the analyzed words, an abnormality prompt is given.
5. The method according to claim 2, characterized in that: When the analysis result is abnormal, an abnormal prompt is given, including: When there is an abnormality in the operator or the value, an abnormality prompt is given.
6. The method according to claim 1, characterized in that Before obtaining the calculation result according to the expression, the method further includes: Display auto-completion hints related to the parsed result.
7. The method according to claim 1, characterized in that Before obtaining the expression input in the edit box, the method further includes: When an editing event in the editing box is monitored, a parsing timer is started; The expression input in the acquisition edit box includes: When the parsing timer reaches a set time point, the expression input in the edit box is obtained.
8. An expression editing device, characterized in that: The device comprises: The acquisition module is used to obtain the expression entered in the edit box; A parsing module, used for parsing the expression to obtain a parsing result; A calculation module, used for obtaining a calculation result according to the expression when the parsing result is normal; the parsing result is normal means that the parsing result conforms to the lexical and grammatical structure of the expression editing; The prompt module is used to give an abnormal prompt when there is an abnormality in the analysis result.
9. An electronic device, characterized in that: including memory and processor; The memory is connected to the processor and is used to store programs; The processor is used to implement the expression editing method as described in any one of claims 1 to 7 by running the program in the memory.
10. A computer program product, characterized in that It comprises computer program instructions, which, when executed by a processor, enable the processor to execute the expression editing method as described in any one of claims 1 to 7.