WO2019165706A1 - Expression processing method, apparatus, device, and computer readable storage medium - Google Patents
Expression processing method, apparatus, device, and computer readable storage medium Download PDFInfo
- Publication number
- WO2019165706A1 WO2019165706A1 PCT/CN2018/085277 CN2018085277W WO2019165706A1 WO 2019165706 A1 WO2019165706 A1 WO 2019165706A1 CN 2018085277 W CN2018085277 W CN 2018085277W WO 2019165706 A1 WO2019165706 A1 WO 2019165706A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- expression
- stack
- input parameter
- type
- priority level
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
Definitions
- the present application relates to the field of computer data processing, and in particular, to an expression processing method, apparatus, device, and computer readable storage medium.
- a computer program is a list of instructions that describe actions performed by a computer or processor-based device. When a computer program is loaded and executed on computer hardware, the computer will follow the instructions of the computer program to operate in a predetermined manner.
- a large number of expressions are used in computer programs. Expressions are sequences of operators and operands. For example, an expression can be "3+2".
- the computer cannot recognize the expression written according to the natural language, so the corresponding format conversion of the expression is required for the computer to read, but the format conversion of the expression in the prior art can only According to the operator of the expression and the operand, the conversion expression cannot call the function object, which causes the expression to fail to implement the logic operation with high complexity, and it is easy to cause the program code to be verbose and the execution efficiency to be low. .
- the present application provides an expression processing method, apparatus, device, and computer readable storage medium, which are directed to solving the problem that an expression cannot be called after a format conversion.
- the present application provides an expression processing method, including: parsing an expression to obtain an expression object in the expression; acquiring a type of the expression object; according to the expression The type of the object performs an inverse Polish transformation of the expression to generate an inverse Polish expression; the inverse Polish expression is executed to generate an execution result.
- an expression processing apparatus including:
- An object obtaining unit configured to parse the expression to obtain an expression object in the expression
- a type obtaining unit configured to acquire a type of the expression object
- a converting unit configured to inversely convert the expression according to a type of the expression object to generate an inverse Polish expression
- An execution unit for executing the inverse Polish expression to generate an execution result.
- the present application further provides a computer device comprising a memory, a processor, and a computer program stored on the memory and operable on the processor, wherein the processor executes the The above expression processing method is implemented when the program is executed.
- the present application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, the computer program comprising program instructions, when executed by a processor The processor executes the expression processing method described above.
- the implementation of the embodiment of the present application optimizes the conversion mode of the expression, solves the problem that the function object cannot be called after the format conversion, and improves the expansion of the expression and the execution efficiency.
- FIG. 1 is a schematic flowchart diagram of an expression processing method according to an embodiment of the present application.
- FIG. 2 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application.
- FIG. 3 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present disclosure
- FIG. 4 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present disclosure
- FIG. 5 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present disclosure
- FIG. 6 is a schematic block diagram of an expression processing apparatus according to an embodiment of the present application.
- FIG. 7 is a schematic block diagram of a first generating unit in an expression processing apparatus according to an embodiment of the present disclosure.
- FIG. 8 is a schematic block diagram of a type acquiring unit in an expression processing apparatus according to an embodiment of the present disclosure.
- FIG. 9 is a schematic block diagram of a conversion unit in an expression processing apparatus according to an embodiment of the present disclosure.
- FIG. 10 is a schematic block diagram of a second processing unit in an expression processing apparatus according to an embodiment of the present disclosure.
- FIG. 11 is a schematic block diagram of a computer device according to an embodiment of the present application.
- FIG. 1 is a schematic flowchart diagram of an expression processing method according to an embodiment of the present application.
- the expression processing method can be applied to terminals such as a server, a desktop computer, a laptop computer, a tablet computer, a personal digital assistant (PDA), a smart phone (such as an Android mobile phone, an IOS mobile phone, etc.).
- the method includes steps S100-S400.
- Expression is a sequence composed of an operator (Operator) and an operand (Operand).
- Expression objects include operator objects and operand objects.
- the parsing the expression may implement the combined parser by using a programming language such as Java and parse the expression by the combined parser to parse the expression into an expression object.
- An expression can include one or more types of expression objects, and different types of expression objects can be parsed by different parsers. For example, a string is parsed by a constant parser, and a constant in the string can be used to generate a corresponding expression object.
- FIG. 2 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application. Further, the acquiring the type of the expression object in step S200 includes steps S210-S220.
- the function identifier may be set according to a specific expression usage environment.
- the function identifier may be “$”, “ ⁇ ”, etc., and the embodiment of the present application does not limit the specific symbol of the function identifier.
- the function tag can be set before the first character of the expression object. If the function tag is included in the expression object, it is determined that the expression object contains a preset function tag.
- the representation form of the expression is greatly enriched, and the extension of the expression is improved.
- the function object directly references the function object to calculate the operand, which reduces the writing workload of the expression and improves the running efficiency of the code program.
- S300 Perform inverse raster transformation on the expression according to the type of the expression object to generate an inverse Polish expression.
- FIG. 3 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application. Further, the expression in step S300 is inversely converted according to the type of the expression object, including S310-S350.
- the preset first stack and the preset second stack are used to store an expression object in the inverse Polish conversion process.
- the data remaining in the stack memory is cleared to prevent data interference caused by the inverse Polish conversion.
- FIG. 4 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application.
- step S320 according to the type of the expression object, the expression object is pushed and popped, including steps S321-S326.
- the obtaining the input parameter corresponding to the function object and the input parameter quantity corresponding to the input parameter may include: acquiring a parameter start character, a parameter terminator, and a parameter separator corresponding to the function object; The input parameter, the parameter terminator, and the parameter separator divide the input parameter to obtain an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter.
- the parameter start character may be “(”, the parameter terminator may be “)”, and the parameter separator may be “,”.
- the embodiment of the present application does not limit the specific symbols of the parameter start character, the parameter terminator and the parameter separator.
- the function object is: $average(a,b,c).
- the function object is segmented according to the parameter start character, the parameter terminator and the parameter separator corresponding to the function object, and the obtained input parameters are “a”, “b”, “c”;
- the parameter is calculated to obtain the input parameter quantity corresponding to the input parameter, and the input parameter quantity corresponding to the function object $average(a, b, c) is three.
- marking the input parameter quantity may specifically set a quantity identifier for the input parameter quantity, and the identifier may be “[]”. Assuming that the input parameter quantity is "3”, the input parameter quantity obtained by marking the input parameter quantity is "[3]”. By marking the input parameter quantity, the amount of the input parameter is prevented from interfering with the execution of the expression after the function object is merged.
- the function object is: $average(a, b, c), and the inbound parameter quantity after the tag is [3]. Then, the marked function object generated by merging the marked input parameter quantity with the function object is $average[3].
- the markup function object is subjected to a push operation to push the markup function object into the first stack.
- parsing the input parameters in sequence specifically analyzes the input parameters from left to right.
- the input parameter corresponding to the function object can be an expression or an operand object. For example, if the function object is $average(a,b,c+d), the input parameters corresponding to the function object are "a", "b", and "c+d". Where “a” and “b” are operand objects and "c+d" is an expression.
- the type of the input parameter obtained is the operand object itself. If the input parameter is an expression, the expression is split into a plurality of expression objects and then parsed, and the type of the input parameter obtained may include an operand object or an operator object. For example, if the input parameter is "c+d”, after the input parameter is split, the resulting expression objects are "c", "+”, and “d”, and the pair "c", "+” And “d” for parsing, it can be concluded that the type of input parameter "c+d” includes operators and operands.
- the type of the input parameter includes an operand object and an operator object, and the step of extracting the stack parameter according to the type of the input parameter in step S326, including S3261-S3265.
- the input parameter is an operand object, such as "a”, "b”, etc., and the operand object is pushed into the second stack.
- S3262 If the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain a second priority level corresponding to the operator object located at the top of the stack in the first stack. .
- the operator objects can be set to a higher priority level by setting a priority level.
- the operator object "*" has a priority level of 3
- the operator object "+” has a priority level of 4, and the smaller the level number, the higher the priority level.
- the first priority level is 4 and the second priority level is 3, it may be determined that the first priority level is lower than the second priority level.
- the operator object located at the top of the stack in the first stack is popped from the first stack and pressed into the second Stack.
- the level of the first priority level and the second priority level are compared, and the stacking order of the operator object is controlled according to the level comparison result to ensure the operator priority of the inverse Polish expression after the conversion. Correctness.
- the parsing order of the expressions may be performed in a left-to-right order. If it is detected that the rightmost expression character is successfully parsed, it is determined that the expressions are all parsed successfully.
- the expression object stored in the first stack is pushed into the second stack, specifically, the expression objects in the first stack are sequentially popped one by one in the order of advanced output, and the first The expression objects popped up one by one in the stack are sequentially pushed into the second stack.
- the expression object in the second stack is popped in reverse order to generate the inverse Polish expression.
- the populating the expression object in the second stack in reverse order specifically pops up the expression object in the second stack in a first-in first-out order.
- the performing the inverse Polish expression to generate an execution result may specifically include:
- Step one initializing a preset third stack, and sequentially obtaining the expression object from the inverse Polish expression.
- the preset third stack is used to store an execution result of the inverse Polish expression.
- the expression object is obtained from the inverse Polish expression in turn, and the expression object is obtained by sequentially sending the inverse Polish expression according to the left-to-right flow.
- Step 2 Pushing the stack into the stack according to the type of the expression object.
- the expression object includes an operand object, an operator object, and a function object.
- the expression object is an operand object
- the operand object is pushed into the third stack.
- the expression object is an operator object, popping an operand object corresponding to the operator object from the third stack, and performing calculation according to the operand object and the operator object,
- the execution result is pushed into the third stack.
- the operand object corresponding to each operator object is a known value, for example, the operand object corresponding to the operator object "+" is two.
- the number of operand objects corresponding to the operator object it is determined that the number of operand objects corresponding to the operator object needs to be popped from the third stack. Calculating an operation result corresponding to the operator object by using an operand object popped from the third stack and the operator object, and then pressing the calculated operation result into the third stack .
- the in-parameter parameter corresponding to the input parameter in the function object has been obtained in the inverse Polish conversion process of the expression, and the input parameter quantity is marked and processed with the function. Objects are merged to generate a tag function object. Therefore, when the inverse Polish expression is executed, by acquiring the input parameter quantity corresponding to the mark function object, it can be determined that the number of operand objects corresponding to the function object needs to be popped from the third stack.
- the function object in the inverse Polish expression is $average[3]
- the input parameter quantity corresponding to the function object is three, thereby determining the need to go from the The number of operand objects corresponding to the function object popped up in the third stack is three.
- the function object is $average[3] for calculating the average value of the operand object. It is assumed that the three operand objects popped from the third stack are "a”, "b”, and “c", respectively. Based on the function object and the operand object, an average of the "a”, "b", and “c” may be calculated and pressed into the third stack.
- step three it is determined whether the expression objects of the inverse Polish expression are all acquired.
- Step four if the expression object of the inverse Polish expression has been all acquired, the execution result of the last push into the third stack is determined as the execution result of the inverse Polish expression.
- Embodiments of the present application are implemented by parsing the expression to obtain the expression corresponding to the expression and the type corresponding to the expression, and then performing inverse Polish transformation according to the type of the expression object, and executing the generated inverse Polish expression. To generate the execution result. It can simplify the record form of the expression, which is beneficial to improve the recognition speed of the expression by the computer system and improve the execution efficiency of the expression.
- FIG. 6 is a schematic block diagram of an expression processing apparatus according to an embodiment of the present application.
- the expression processing apparatus 10 includes an object acquisition unit 100, a type acquisition unit 200, a conversion unit 300, and an execution unit 400.
- the object obtaining unit 100 is configured to parse the expression to obtain an expression object in the expression.
- the type obtaining unit 200 is configured to acquire a type of the expression object.
- FIG. 7 is a schematic block diagram of a type obtaining unit 200 in an expression processing apparatus according to an embodiment of the present application. Further, the type obtaining unit 200 includes a first determining unit 210 and a first processing unit 220.
- the first determining unit 210 is configured to determine whether the expression object includes a preset function tag.
- the first processing unit 220 is configured to determine that the expression object is a function object if the expression object includes a preset function tag.
- the converting unit 300 is configured to perform inverse Polish conversion on the expression according to the type of the expression object to generate an inverse Polish expression.
- FIG. 8 is a schematic block diagram of a conversion unit 300 in an expression processing apparatus according to an embodiment of the present application.
- the conversion unit 300 includes an initialization unit 310, a second processing unit 320, a second determination unit 330, a third processing unit 340, and a first generation unit 350.
- the initialization unit 310 is configured to preset a first stack and a preset second stack.
- the second processing unit 320 is configured to perform a push stacking operation on the expression object according to the type of the expression object.
- FIG. 9 is a schematic block diagram of a second processing unit 320 in an expression processing apparatus according to an embodiment of the present application.
- the second processing unit 320 includes a first obtaining unit 321, a marking unit 322, a second generating unit 323, a fourth processing unit 324, a second obtaining unit 325, and a fifth processing unit 326.
- the first obtaining unit 321 is configured to acquire an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter, if the expression object is a function object.
- the marking unit 322 is configured to perform labeling processing on the input parameter quantity.
- the second generating unit 323 is configured to merge the marked input parameter quantity with the function object to generate a label function object.
- the fourth processing unit 324 is configured to press the mark function object into the first stack.
- the second obtaining unit 325 is configured to parse the input parameter to obtain the type of the input parameter.
- the fifth processing unit 326 is configured to perform a push stacking operation on the input parameter according to the type of the input parameter.
- FIG. 10 is a schematic block diagram of a fifth processing unit 326 in an expression processing apparatus according to an embodiment of the present application.
- the type of the input parameter includes an operand object and an operator object
- the fifth processing unit 326 includes a sixth processing unit 3261, a third obtaining unit 3262, a third determining unit 3263, a seventh processing unit 3264, and The eighth processing unit 3265.
- the sixth processing unit 3261 is configured to press the operand object into the second stack if the type of the input parameter is an operand object.
- the third obtaining unit 3262 is configured to: if the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain an operator object corresponding to a top of the stack in the first stack The second priority level.
- the third determining unit 3263 is configured to determine whether the first priority level is lower than the second priority level.
- the seventh processing unit 3264 is configured to: if the first priority level is lower than the second priority level, pop the operator object located at the top of the stack in the first stack from the first stack Pressing into the second stack.
- the eighth processing unit 3265 is configured to press the operator object into the first stack if the first priority level is higher than the second priority level.
- the second determining unit 330 is configured to determine whether the expression is all parsed successfully.
- the third processing unit 340 is configured to press the expression object stored in the first stack into the second stack if the expression has been completely parsed successfully.
- the first generating unit 350 is configured to pop the expression object in the second stack in reverse order to generate the inverse Polish expression.
- the execution unit 400 is configured to execute the inverse Polish expression to generate an execution result.
- the apparatus 10 described above can be implemented in the form of a computer program that can be run on a computer device as shown in FIG.
- FIG. 11 is a schematic block diagram of a computer device according to an embodiment of the present application.
- the computer device 500 device can be a terminal.
- the terminal can be a communication-enabled electronic device such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, and a wearable device.
- the computer device 500 includes a processor 520, a memory, and a network interface 550 that are coupled by a system bus 510, where the memory can include a non-volatile storage medium 530 and an internal memory 540.
- the non-volatile storage medium 530 can store an operating system 531 and a computer program 532.
- the processor 520 can be caused to perform an expression processing method.
- the processor 520 is used to provide computing and control capabilities to support the operation of the entire computer device 500.
- the internal memory 540 provides an environment for the operation of a computer program in a non-volatile storage medium that, when executed by the processor 520, causes the processor 520 to perform an expression processing method.
- the network interface 550 is used for network communication, such as sending assigned tasks and the like. It will be understood by those skilled in the art that the schematic block diagram of the computer device is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the computer device 500 to which the solution of the present application is applied.
- the specific computer device 500 More or fewer components than those shown in the figures may be included, or some components may be combined, or have different component arrangements.
- the processor 520 is configured to run the program code stored in the memory to implement the following method for the expression processing of the embodiment of the present application.
- the processor 520 may be a central processing unit (CPU), and the processor 520 may also be other general-purpose processors, a digital signal processor (DSP), Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc.
- the general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
- the schematic block diagram of the computer device 500 does not constitute a limitation to the computer device 500, and may include more or fewer components than those illustrated, or some components may be combined, or different component arrangements.
- a computer readable storage medium is stored, the computer readable storage medium storing a computer program, wherein the computer program comprises program instructions.
- the expression processing method of the embodiment of the present application is implemented when the program instruction is executed by a processor.
- the computer readable storage medium may be any medium that can store program code, such as a USB flash drive, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk.
- program code such as a USB flash drive, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk.
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- User Interface Of Digital Computer (AREA)
- Stored Programmes (AREA)
Abstract
The embodiments of the present application provide an expression processing method, an apparatus, a device, and a computer readable storage medium. The method comprises: parsing an expression, to acquire an expression object from the expression; acquiring the type of the expression object; performing a reverse Polish conversion on the expression according to the type of the expression object, to generate a reverse Polish expression; executing the reverse Polish expression to generate an execution result. The implementation of the present application can optimize the manner of converting an expression, solving the problem that a function object cannot be invoked after format conversion, and improving the extensibility and execution efficiency of expressions.
Description
本申请要求于2018年3月2日提交中国专利局、申请号为201810175368.X、发明名称为“表达式处理方法、装置、设备及计算机可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application No. 201 810 175 368.X filed on March 2, 2018, the disclosure of which is entitled "Expression Processing Method, Apparatus, Apparatus, and Computer Readable Storage Medium". The entire contents are incorporated herein by reference.
本申请涉及计算机数据处理领域,尤其涉及一种表达式处理方法、装置、设备及计算机可读存储介质。The present application relates to the field of computer data processing, and in particular, to an expression processing method, apparatus, device, and computer readable storage medium.
计算机程序是描述由计算机或基于处理器的设备执行的动作的指令列表。当计算机程序被加载并在计算机硬件上执行时,计算机将会跟随计算机程序的指令以预先确定的方式运转。在计算机程序中会使用大量的表达式,表达式(Expression)是运算符(Operator)和操作数(Operand)所构成的序列,例如表达式可以“3+2”。在计算机执行表达式的过程中,计算机无法识别根据自然语言书写的表达式,因此需要对表达式进行相对应的格式转换以供计算机读取,但现有技术中对表达式的格式转换只能根据表达式的运算符以及操作数进行转换,从而导致转换后的表达式无法调用函数对象,导致了表达式无法实现复杂度较高的逻辑运算,且容易造成程序代码冗长、执行效率低下等问题。A computer program is a list of instructions that describe actions performed by a computer or processor-based device. When a computer program is loaded and executed on computer hardware, the computer will follow the instructions of the computer program to operate in a predetermined manner. A large number of expressions are used in computer programs. Expressions are sequences of operators and operands. For example, an expression can be "3+2". During the execution of an expression by a computer, the computer cannot recognize the expression written according to the natural language, so the corresponding format conversion of the expression is required for the computer to read, but the format conversion of the expression in the prior art can only According to the operator of the expression and the operand, the conversion expression cannot call the function object, which causes the expression to fail to implement the logic operation with high complexity, and it is easy to cause the program code to be verbose and the execution efficiency to be low. .
发明内容Summary of the invention
本申请提供了一种表达式处理方法、装置、设备及计算机可读存储介质,旨在解决表达式在格式转换后无法调用函数对象的问题。The present application provides an expression processing method, apparatus, device, and computer readable storage medium, which are directed to solving the problem that an expression cannot be called after a format conversion.
第一方面,本申请提供了一种表达式处理方法,其包括:对表达式进行解析,以获取所述表达式中的表达式对象;获取所述表达式对象的类型;根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式;执行所述逆波兰表达式以生成执行结果。In a first aspect, the present application provides an expression processing method, including: parsing an expression to obtain an expression object in the expression; acquiring a type of the expression object; according to the expression The type of the object performs an inverse Polish transformation of the expression to generate an inverse Polish expression; the inverse Polish expression is executed to generate an execution result.
第二方面,本申请提供了一种表达式处理装置,其包括:In a second aspect, the present application provides an expression processing apparatus, including:
对象获取单元,用于对表达式进行解析,以获取所述表达式中的表达式对象;An object obtaining unit, configured to parse the expression to obtain an expression object in the expression;
类型获取单元,用于获取所述表达式对象的类型;a type obtaining unit, configured to acquire a type of the expression object;
转换单元,用于根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式;a converting unit, configured to inversely convert the expression according to a type of the expression object to generate an inverse Polish expression;
执行单元,用于执行所述逆波兰表达式以生成执行结果。An execution unit for executing the inverse Polish expression to generate an execution result.
第三方面,本申请又提供了一种计算机设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,其特征在于,所述处理器执行所述程序时实现上述的表达式处理方法。In a third aspect, the present application further provides a computer device comprising a memory, a processor, and a computer program stored on the memory and operable on the processor, wherein the processor executes the The above expression processing method is implemented when the program is executed.
第四方面,本申请还提供了一种计算机可读存储介质,其中所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时使所述处理器执行上述的表达式处理方法。In a fourth aspect, the present application also provides a computer readable storage medium, wherein the computer readable storage medium stores a computer program, the computer program comprising program instructions, when executed by a processor The processor executes the expression processing method described above.
实施本申请实施例,优化了表达式的转换方式,解决了格式转换后无法调用函数对象的问题,提升了表达式的拓展性以及执行效率。The implementation of the embodiment of the present application optimizes the conversion mode of the expression, solves the problem that the function object cannot be called after the format conversion, and improves the expansion of the expression and the execution efficiency.
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings used in the description of the embodiments will be briefly described below. Obviously, the drawings in the following description are some embodiments of the present application, For the ordinary technicians, other drawings can be obtained based on these drawings without any creative work.
图1为本申请一实施例提供的一种表达式处理方法的流程示意图;FIG. 1 is a schematic flowchart diagram of an expression processing method according to an embodiment of the present application;
图2为本申请一实施例提供的一种表达式处理方法的子流程示意图;2 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application;
图3为本申请一实施例提供的一种表达式处理方法的子流程示意图;FIG. 3 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present disclosure;
图4为本申请一实施例提供的一种表达式处理方法的子流程示意图;FIG. 4 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present disclosure;
图5为本申请一实施例提供的一种表达式处理方法的子流程示意图;FIG. 5 is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present disclosure;
图6为本申请一实施例提供的一种表达式处理装置的示意性框图;FIG. 6 is a schematic block diagram of an expression processing apparatus according to an embodiment of the present application;
图7为本申请一实施例提供的一种表达式处理装置中第一生成单元的示意性框图;FIG. 7 is a schematic block diagram of a first generating unit in an expression processing apparatus according to an embodiment of the present disclosure;
图8为本申请一实施例提供的一种表达式处理装置中类型获取单元的示意性框图;FIG. 8 is a schematic block diagram of a type acquiring unit in an expression processing apparatus according to an embodiment of the present disclosure;
图9为本申请一实施例提供的一种表达式处理装置中转换单元的示意性框图;FIG. 9 is a schematic block diagram of a conversion unit in an expression processing apparatus according to an embodiment of the present disclosure;
图10为本申请一实施例提供的一种表达式处理装置中第二处理单元的示意性框图;FIG. 10 is a schematic block diagram of a second processing unit in an expression processing apparatus according to an embodiment of the present disclosure;
图11为本申请一实施例提供的一种计算机设备的示意性框图。FIG. 11 is a schematic block diagram of a computer device according to an embodiment of the present application.
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application are clearly and completely described in the following with reference to the drawings in the embodiments of the present application. It is obvious that the described embodiments are a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present application without departing from the inventive scope are the scope of the present application.
请参照图1,其为本申请一实施例提供的一种表达式处理方法的流程示意图。该表达式处理方法可应用于服务器、台式电脑、手提电脑、平板电脑、个人数字助理(PDA)、智能手机(如Android手机、IOS手机等)等终端中。具体地,该方法包括步骤S100-S400。Please refer to FIG. 1 , which is a schematic flowchart diagram of an expression processing method according to an embodiment of the present application. The expression processing method can be applied to terminals such as a server, a desktop computer, a laptop computer, a tablet computer, a personal digital assistant (PDA), a smart phone (such as an Android mobile phone, an IOS mobile phone, etc.). Specifically, the method includes steps S100-S400.
S100,对表达式进行解析,以获取所述表达式中的表达式对象。S100: Parse the expression to obtain an expression object in the expression.
具体地,所述表达式(Expression)是运算符(Operator)和操作数(Operand)所构成的序列。表达式对象包括运算符对象、操作数对象。常见的运算符对象例如有算术运算符(例如+、-、×、÷等),关系运算符(例如<、<=、>、>=、==、!=等),以及逻辑运算符(例如&&、()、||、!等);常见的操作数对象例如有数字(1、23等)、变量(var、a等)。Specifically, the expression (Expression) is a sequence composed of an operator (Operator) and an operand (Operand). Expression objects include operator objects and operand objects. Common operator objects are, for example, arithmetic operators (such as +, -, ×, ÷, etc.), relational operators (such as <, <=, >, >=, ==, !=, etc.), and logical operators ( For example, &&, (), ||, !, etc.); common operand objects are, for example, numbers (1, 23, etc.), variables (var, a, etc.).
所述对所述表达式进行解析可通过利用Java等编程语言实现组合式解析器并通过该组合式解析器对表达式进行解析,以将所述表达式解析成为表达式对象。一个表达式可以包括一个或者多个类型的表达式对象,不同类型的表达式对象可通过不同的解析器进行解析得出。例如,通过常数解析器对字符串进行解析,可将该字符串中的常数生成相对应的表达式对象。The parsing the expression may implement the combined parser by using a programming language such as Java and parse the expression by the combined parser to parse the expression into an expression object. An expression can include one or more types of expression objects, and different types of expression objects can be parsed by different parsers. For example, a string is parsed by a constant parser, and a constant in the string can be used to generate a corresponding expression object.
S200,获取所述表达式对象的类型。S200: Acquire a type of the expression object.
具体请参照图2,其为本申请一实施例提供的一种表达式处理方法的子流程示意图。进一步地,步骤S200中的所述获取所述表达式对象的类型,包括步骤S210-S220。For details, please refer to FIG. 2 , which is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application. Further, the acquiring the type of the expression object in step S200 includes steps S210-S220.
S210,判断所述表达式对象是否包含预设的函数标记符。S210. Determine whether the expression object includes a preset function tag.
具体地,所述函数标记符可以根据具体的表达式使用环境进行设置,例如该函数标记符可以为“$”、“¥”等等,本申请实施例并不对函数标记符的具体符号作出限制。所述函数标记符可设置于表达式对象的首字符前面。若表达式对象中包含该函数标记符,则判定所述表达式对象包含预设的函数标记符。Specifically, the function identifier may be set according to a specific expression usage environment. For example, the function identifier may be “$”, “¥”, etc., and the embodiment of the present application does not limit the specific symbol of the function identifier. . The function tag can be set before the first character of the expression object. If the function tag is included in the expression object, it is determined that the expression object contains a preset function tag.
S220,若所述表达式对象包含预设的函数标记符,确定所述表达式对象为函数对象。S220. If the expression object includes a preset function tag, determine that the expression object is a function object.
具体地,假设所述函数标记符为“$”,若所述表达式对象为“$startswith”,通过检测,可判定表达式对象“$startswith”中包含有预设的函数标记符“$”,则确定表达式对象“$startswith”为函数对象。Specifically, assuming that the function tag is "$", if the expression object is "$startswith", by detecting, it can be determined that the expression object "$startswith" contains the preset function tag "$" , then determine the expression object "$startswith" as a function object.
实施本申请实施例,通过在表达式中引入函数对象,并在函数对象中设置预设的函数标识符,极大地丰富了表达式的表现形式,提升了表达式的拓展性。通过函数对象直接引用该函数对象对操作数进行计算,减少了表达式的编写工作量,同时也提升了代码程序的运行效率。By implementing the embodiment of the present application, by introducing a function object in an expression and setting a preset function identifier in the function object, the representation form of the expression is greatly enriched, and the extension of the expression is improved. The function object directly references the function object to calculate the operand, which reduces the writing workload of the expression and improves the running efficiency of the code program.
S300,根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式。S300: Perform inverse raster transformation on the expression according to the type of the expression object to generate an inverse Polish expression.
具体请参照图3,其为本申请一实施例提供的一种表达式处理方法的子流程示意图。进一步地,步骤S300中的所述根据所述表达式对象的类型将所述表达式进行逆波兰转换,包括S310-S350。For details, please refer to FIG. 3 , which is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application. Further, the expression in step S300 is inversely converted according to the type of the expression object, including S310-S350.
S310,初始化预设的第一堆栈以及预设的第二堆栈。S310. Initialize a preset first stack and a preset second stack.
具体地,所述预设的第一堆栈以及预设的第二堆栈用于存储逆波兰转换过程中的表达式对象。通过初始化该预设的第一堆栈以及预设的第二堆栈,以对栈内存留的数据进行清零,防止对逆波兰转换造成数据干扰。Specifically, the preset first stack and the preset second stack are used to store an expression object in the inverse Polish conversion process. By initializing the preset first stack and the preset second stack, the data remaining in the stack memory is cleared to prevent data interference caused by the inverse Polish conversion.
S320,根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作。S320. Perform a push stacking operation on the expression object according to the type of the expression object.
具体请参照图4,其为本申请一实施例提供的一种表达式处理方法的子流程示意图。进一步地,步骤S320中的根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作,包括步骤S321-S326。For details, please refer to FIG. 4 , which is a schematic diagram of a sub-flow of an expression processing method according to an embodiment of the present application. Further, in step S320, according to the type of the expression object, the expression object is pushed and popped, including steps S321-S326.
S321,若所述表达式对象为函数对象,获取所述函数对象对应的输入参数以及所述输入参数对应的入参数量。S321. If the expression object is a function object, obtain an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter.
具体地,所述获取所述函数对象对应的输入参数以及所述输入参数对应的 入参数量可以包括:获取所述函数对象对应的参数起始符、参数结束符以及参数分隔符;根据参数起始符、参数结束符以及参数分隔符对所述输入参数进行分割,以得出所述函数对象对应的输入参数以及所述输入参数对应的入参数量。其中所述参数起始符可以为“(”,所述参数结束符可以为“)”,所述参数分割符可以为“,”。本申请实施例并不对所述参数起始符、参数结束符以及参数分隔符的具体符号作出限制。Specifically, the obtaining the input parameter corresponding to the function object and the input parameter quantity corresponding to the input parameter may include: acquiring a parameter start character, a parameter terminator, and a parameter separator corresponding to the function object; The input parameter, the parameter terminator, and the parameter separator divide the input parameter to obtain an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter. The parameter start character may be “(”, the parameter terminator may be “)”, and the parameter separator may be “,”. The embodiment of the present application does not limit the specific symbols of the parameter start character, the parameter terminator and the parameter separator.
假设该函数对象为:$average(a,b,c)。根据所述函数对象对应的参数起始符、参数结束符以及参数分隔符对该函数对象进行分割,所得出的输入参数为“a”、“b”、“c”;通过对所得出的输入参数进行计算,可得出所述输入参数对应的入参数量,函数对象$average(a,b,c)对应的入参数量为3个。Suppose the function object is: $average(a,b,c). The function object is segmented according to the parameter start character, the parameter terminator and the parameter separator corresponding to the function object, and the obtained input parameters are “a”, “b”, “c”; The parameter is calculated to obtain the input parameter quantity corresponding to the input parameter, and the input parameter quantity corresponding to the function object $average(a, b, c) is three.
S322,对所述入参数量进行标记处理。S322, performing marking processing on the input parameter quantity.
具体地,对所述入参数量进行标记处理具体可以为对该入参数量设置数量标识符,该标识符可以为“[]”。假设该入参数量为“3”,通过对所述入参数量进行标记处理后得出的入参数量为“[3]”。通过对入参数量进行标记处理,以防止所述入参数量在于所述函数对象合并后,对表达式的执行造成干扰。Specifically, marking the input parameter quantity may specifically set a quantity identifier for the input parameter quantity, and the identifier may be “[]”. Assuming that the input parameter quantity is "3", the input parameter quantity obtained by marking the input parameter quantity is "[3]". By marking the input parameter quantity, the amount of the input parameter is prevented from interfering with the execution of the expression after the function object is merged.
S323,将标记后的入参数量与所述函数对象合并,以生成标记函数对象。S323. Combine the marked input parameter quantity with the function object to generate a tag function object.
具体地,假设该函数对象为:$average(a,b,c),标记后的入参数量为[3]。则将标记后的入参数量与所述函数对象合并所生成标记函数对象为$average[3]。Specifically, assume that the function object is: $average(a, b, c), and the inbound parameter quantity after the tag is [3]. Then, the marked function object generated by merging the marked input parameter quantity with the function object is $average[3].
S324,将所述标记函数对象压入所述第一堆栈。S324, pressing the markup function object into the first stack.
具体地,对所述标记函数对象进行压栈操作,以将述标记函数对象压入所述第一堆栈。Specifically, the markup function object is subjected to a push operation to push the markup function object into the first stack.
S325,依次对所述输入参数进行解析,以获取所述输入参数的类型。S325. Parse the input parameter in sequence to obtain a type of the input parameter.
具体地,依次对所述输入参数进行解析具体为从左至右对所述输入参数进行解析。函数对象对应的输入参数可以是表达式或者操作数对象。例如假设该函数对象为$average(a,b,c+d),该函数对象对应的输入参数为“a”、“b”以及“c+d”。其中“a”以及“b”为操作数对象,“c+d”为表达式。Specifically, parsing the input parameters in sequence specifically analyzes the input parameters from left to right. The input parameter corresponding to the function object can be an expression or an operand object. For example, if the function object is $average(a,b,c+d), the input parameters corresponding to the function object are "a", "b", and "c+d". Where "a" and "b" are operand objects and "c+d" is an expression.
若所述输入参数为操作数对象,则获取到所述输入参数的类型为操作数对象本身。若所述输入参数为表达式,则将该表达式拆分为若干个的表达式对象后再进行解析,所获取到所述输入参数的类型为可以包括操作数对象或者运算符对象。例如,若该输入参数为“c+d”,对该输入参数进行拆分后,得出的表 达式对象为“c”、“+”以及“d”,通过对“c”、“+”以及“d”进行解析,可得出输入参数“c+d”的类型包括运算符以及操作数。If the input parameter is an operand object, the type of the input parameter obtained is the operand object itself. If the input parameter is an expression, the expression is split into a plurality of expression objects and then parsed, and the type of the input parameter obtained may include an operand object or an operator object. For example, if the input parameter is "c+d", after the input parameter is split, the resulting expression objects are "c", "+", and "d", and the pair "c", "+" And "d" for parsing, it can be concluded that the type of input parameter "c+d" includes operators and operands.
S326,根据所述输入参数的类型对所述输入参数进行压栈出栈操作。S326. Perform a push stacking operation on the input parameter according to the type of the input parameter.
具体请参照图5,其为本申请一实施例提供的一种表达式处理方法的子流程示意图。进一步地,所述输入参数的类型包括操作数对象以及运算符对象,步骤S326中的所述根据所述输入参数的类型对所述输入参数进行压栈出栈操作,包括S3261-S3265。For details, refer to FIG. 5 , which is a sub-flow diagram of an expression processing method according to an embodiment of the present application. Further, the type of the input parameter includes an operand object and an operator object, and the step of extracting the stack parameter according to the type of the input parameter in step S326, including S3261-S3265.
S3261,若所述输入参数的类型为操作数对象,将所述操作数对象压入所述第二堆栈。S3261: If the type of the input parameter is an operand object, press the operand object into the second stack.
具体地,例如所述输入参数为操作数对象,例如为“a”、“b”等,则将所述操作数对象压入所述第二堆栈。Specifically, for example, the input parameter is an operand object, such as "a", "b", etc., and the operand object is pushed into the second stack.
S3262,若所述输入参数的类型为运算符对象,获取所述运算符对象对应的第一优先级等级,以及获取位于所述第一堆栈中栈顶的运算符对象对应的第二优先级等级。S3262: If the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain a second priority level corresponding to the operator object located at the top of the stack in the first stack. .
具体地,运算符对象之间可通过设定优先级等级,以进行复杂性较强的运算。例如运算符对象“*”的优先等级为3级,运算符对象“+”的优先等级为4级,级别数字越小,优先等级越高。Specifically, the operator objects can be set to a higher priority level by setting a priority level. For example, the operator object "*" has a priority level of 3, and the operator object "+" has a priority level of 4, and the smaller the level number, the higher the priority level.
S3263,判断所述第一优先等级是否低于所述第二优先级等级。S3263. Determine whether the first priority level is lower than the second priority level.
具体地,假设第一优先等级为4级,所述第二优先级等级为3级,则可判定判断所述第一优先等级低于所述第二优先级等级。Specifically, if the first priority level is 4 and the second priority level is 3, it may be determined that the first priority level is lower than the second priority level.
S3264,若所述第一优先等级低于所述第二优先级等级,将所述位于所述第一堆栈中栈顶的运算符对象从所述第一堆栈中弹出并压入所述第二堆栈。S3264. If the first priority level is lower than the second priority level, the operator object located at the top of the stack in the first stack is popped from the first stack and pressed into the second Stack.
S3265,若所述第一优先等级高于所述第二优先级等级,将所述运算符对象压入所述第一堆栈。S3265: If the first priority level is higher than the second priority level, pressing the operator object into the first stack.
具体的,通过对第一优先等级以及所述第二优先级等级的进行等级比较,并根据等级比较结果控制运算符对象的压栈顺序,以保证转换后逆波兰表达式的运算符优先级的正确性。Specifically, the level of the first priority level and the second priority level are compared, and the stacking order of the operator object is controlled according to the level comparison result to ensure the operator priority of the inverse Polish expression after the conversion. Correctness.
S330,判断所述表达式是否全部解析成功。S330. Determine whether the expression is all parsed successfully.
具体地,所述表达式的解析顺序可按照从左至右的顺序进行,若检测到最右端的表达式字符被解析成功,则判定所述表达式全部解析成功。Specifically, the parsing order of the expressions may be performed in a left-to-right order. If it is detected that the rightmost expression character is successfully parsed, it is determined that the expressions are all parsed successfully.
S340,若所述表达式已全部解析成功,将存储于所述第一堆栈的表达式对象压入所述第二堆栈。S340. If the expression has been fully parsed successfully, the expression object stored in the first stack is pushed into the second stack.
具体地,将存储于所述第一堆栈的表达式对象压入所述第二堆栈具体为按照先进后出的顺序依次将第一堆栈中的表达式对象逐个弹出,并将从所述第一堆栈中逐个弹出的表达式对象依次压入所述第二堆栈。Specifically, the expression object stored in the first stack is pushed into the second stack, specifically, the expression objects in the first stack are sequentially popped one by one in the order of advanced output, and the first The expression objects popped up one by one in the stack are sequentially pushed into the second stack.
S350,逆序弹出所述第二堆栈中的表达式对象,以生成所述逆波兰表达式。S350. The expression object in the second stack is popped in reverse order to generate the inverse Polish expression.
具体地,所述逆序弹出所述第二堆栈中的表达式对象具体为按照先进先出的顺序依次弹出所述第二堆栈中的表达式对象。Specifically, the populating the expression object in the second stack in reverse order specifically pops up the expression object in the second stack in a first-in first-out order.
S400,执行所述逆波兰表达式以生成执行结果。S400. Perform the inverse Polish expression to generate an execution result.
具体地,所述执行所述逆波兰表达式以生成执行结果具体可以包括:Specifically, the performing the inverse Polish expression to generate an execution result may specifically include:
步骤一,初始化预设的第三堆栈,并依次从所述逆波兰表达式中获取所述表达式对象。Step one, initializing a preset third stack, and sequentially obtaining the expression object from the inverse Polish expression.
具体地,所述预设的第三堆栈用于存储逆波兰表达式的执行结果。依次从所述逆波兰表达式中获取所述表达式对象具体为根据从左至右的顺便依次送所述逆波兰表达式中获取所述表达式对象。Specifically, the preset third stack is used to store an execution result of the inverse Polish expression. The expression object is obtained from the inverse Polish expression in turn, and the expression object is obtained by sequentially sending the inverse Polish expression according to the left-to-right flow.
步骤二,根据所述表达式对象的类型进行压栈入栈操作。Step 2: Pushing the stack into the stack according to the type of the expression object.
具体地,所述表达式对象包括操作数对象、运算符对象以及函数对象。Specifically, the expression object includes an operand object, an operator object, and a function object.
(1)若所述表达式对象为操作数对象,将所述操作数对象压入所述第三堆栈。(1) If the expression object is an operand object, the operand object is pushed into the third stack.
(2)若所述表达式对象为运算符对象,从所述第三堆栈中弹出与所述运算符对象对应的操作数对象,根据所述操作数对象以及运算符对象进行计算,将所述执行结果压入所述第三堆栈。具体地,每一个运算符对象所对应的操作数对象为已知值,例如运算符对象“+”对应的操作数对象为2个。通过获取所述运算符对象对应的操作数对象的个数,从而确定需要从所述第三堆栈中弹出与所述运算符对象对应的操作数对象的个数。通过从所述第三堆栈中弹出的操作数对象以及所述运算符对象即可计算得出所述运算符对象对应的运算结果,然后将所计算得出的运算结果压入所述第三堆栈。(2) if the expression object is an operator object, popping an operand object corresponding to the operator object from the third stack, and performing calculation according to the operand object and the operator object, The execution result is pushed into the third stack. Specifically, the operand object corresponding to each operator object is a known value, for example, the operand object corresponding to the operator object "+" is two. By obtaining the number of operand objects corresponding to the operator object, it is determined that the number of operand objects corresponding to the operator object needs to be popped from the third stack. Calculating an operation result corresponding to the operator object by using an operand object popped from the third stack and the operator object, and then pressing the calculated operation result into the third stack .
(3)若所述表达式对象为函数对象,从所述第三堆栈中弹出与所述函数对象对应的操作数对象,根据所述操作数对象以及函数对象进行计算,将所述执行结果压入所述第三堆栈。(3) if the expression object is a function object, popping an operand object corresponding to the function object from the third stack, performing calculation according to the operand object and the function object, and pressing the execution result Into the third stack.
具体地,由前述实施例可知,在所述表达式的逆波兰转换过程中已获取到所述函数对象中输入参数对应的入参数量,并将该入参数量进行标记处理后与所述函数对象合并,以生成标记函数对象。因此在执行所述逆波兰表达式时,通过获取所述标记函数对象对应的入参数量,即可确定需要从所述第三堆栈中弹出与所述函数对象对应的操作数对象的个数。Specifically, it can be seen from the foregoing embodiment that the in-parameter parameter corresponding to the input parameter in the function object has been obtained in the inverse Polish conversion process of the expression, and the input parameter quantity is marked and processed with the function. Objects are merged to generate a tag function object. Therefore, when the inverse Polish expression is executed, by acquiring the input parameter quantity corresponding to the mark function object, it can be determined that the number of operand objects corresponding to the function object needs to be popped from the third stack.
例如,假设该逆波兰表达式中的函数对象为$average[3],通过获取该函数对象对应的入参数量,可得出该函数对象对应的入参数量为3个,进而确定需要从所述第三堆栈中弹出与所述函数对象对应的操作数对象的个数为3个。For example, if the function object in the inverse Polish expression is $average[3], by obtaining the input parameter quantity corresponding to the function object, it can be concluded that the input parameter quantity corresponding to the function object is three, thereby determining the need to go from the The number of operand objects corresponding to the function object popped up in the third stack is three.
本申请实施例中,函数对象为$average[3]用于计算操作数对象的平均值。假设从所述第三堆栈中弹出的三个操作数对象分别为“a”、“b”以及“c”。根据所述函数对象的以及所述操作数对象,则可计算出所述“a”、“b”以及“c”的平均值,并将该平均值压入所述第三堆栈。In the embodiment of the present application, the function object is $average[3] for calculating the average value of the operand object. It is assumed that the three operand objects popped from the third stack are "a", "b", and "c", respectively. Based on the function object and the operand object, an average of the "a", "b", and "c" may be calculated and pressed into the third stack.
步骤三,判断所述逆波兰表达式的表达式对象是否全部被获取。In step three, it is determined whether the expression objects of the inverse Polish expression are all acquired.
步骤四,若所述逆波兰表达式的表达式对象已全部被获取,则将最后一个压入所述第三堆栈的执行结果确定为所述逆波兰表达式的执行结果。Step four, if the expression object of the inverse Polish expression has been all acquired, the execution result of the last push into the third stack is determined as the execution result of the inverse Polish expression.
实施本申请实施例,通过对所述表达式进行解析以获取所述表达式对应以及表达式对应的类型,进而根据所述表达式对象的类型进行逆波兰转换,并执行所生成的逆波兰表达式以生成所述执行结果。可简化表达式的记录形式,有利于提高计算机***对表达式的识别速度,提升了表达式的执行效率。Embodiments of the present application are implemented by parsing the expression to obtain the expression corresponding to the expression and the type corresponding to the expression, and then performing inverse Polish transformation according to the type of the expression object, and executing the generated inverse Polish expression. To generate the execution result. It can simplify the record form of the expression, which is beneficial to improve the recognition speed of the expression by the computer system and improve the execution efficiency of the expression.
请参照图6,其为本申请一实施例提供的一种表达式处理装置的示意性框图。该表达式处理装置10包括对象获取单元100、类型获取单元200、转换单元300以及执行单元400。Please refer to FIG. 6 , which is a schematic block diagram of an expression processing apparatus according to an embodiment of the present application. The expression processing apparatus 10 includes an object acquisition unit 100, a type acquisition unit 200, a conversion unit 300, and an execution unit 400.
对象获取单元100,用于对表达式进行解析,以获取所述表达式中的表达式对象。The object obtaining unit 100 is configured to parse the expression to obtain an expression object in the expression.
类型获取单元200,用于获取所述表达式对象的类型。The type obtaining unit 200 is configured to acquire a type of the expression object.
具体请参照图7,其为本申请一实施例提供的一种表达式处理装置中类型获取单元200的示意性框图。进一步地,所述类型获取单元200包括第一判断单元210以及第一处理单元220。For details, please refer to FIG. 7 , which is a schematic block diagram of a type obtaining unit 200 in an expression processing apparatus according to an embodiment of the present application. Further, the type obtaining unit 200 includes a first determining unit 210 and a first processing unit 220.
第一判断单元210,用于判断所述表达式对象是否包含预设的函数标记符。The first determining unit 210 is configured to determine whether the expression object includes a preset function tag.
第一处理单元220,用于若所述表达式对象包含预设的函数标记符,确定所 述表达式对象为函数对象。The first processing unit 220 is configured to determine that the expression object is a function object if the expression object includes a preset function tag.
转换单元300,用于根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式。The converting unit 300 is configured to perform inverse Polish conversion on the expression according to the type of the expression object to generate an inverse Polish expression.
具体请参照图8,其为本申请一实施例提供的一种表达式处理装置中转换单元300的示意性框图。进一步地,所述转换单元300包括初始化单元310、第二处理单元320、第二判断单元330、第三处理单元340以及第一生成单元350。For details, please refer to FIG. 8 , which is a schematic block diagram of a conversion unit 300 in an expression processing apparatus according to an embodiment of the present application. Further, the conversion unit 300 includes an initialization unit 310, a second processing unit 320, a second determination unit 330, a third processing unit 340, and a first generation unit 350.
初始化单元310,用于预设的第一堆栈以及预设的第二堆栈。The initialization unit 310 is configured to preset a first stack and a preset second stack.
第二处理单元320,用于根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作。The second processing unit 320 is configured to perform a push stacking operation on the expression object according to the type of the expression object.
具体请参照图9,其为本申请一实施例提供的一种表达式处理装置中第二处理单元320的示意性框图。进一步地,所述第二处理单元320包括第一获取单元321、标记单元322、第二生成单元323、第四处理单元324、第二获取单元325以及第五处理单元326。For details, refer to FIG. 9 , which is a schematic block diagram of a second processing unit 320 in an expression processing apparatus according to an embodiment of the present application. Further, the second processing unit 320 includes a first obtaining unit 321, a marking unit 322, a second generating unit 323, a fourth processing unit 324, a second obtaining unit 325, and a fifth processing unit 326.
第一获取单元321,用于若所述表达式对象为函数对象,获取所述函数对象对应的输入参数以及所述输入参数对应的入参数量。The first obtaining unit 321 is configured to acquire an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter, if the expression object is a function object.
标记单元322,用于对所述入参数量进行标记处理。The marking unit 322 is configured to perform labeling processing on the input parameter quantity.
第二生成单元323,用于将标记后的入参数量与所述函数对象合并,以生成标记函数对象。The second generating unit 323 is configured to merge the marked input parameter quantity with the function object to generate a label function object.
第四处理单元324,用于将所述标记函数对象压入所述第一堆栈。The fourth processing unit 324 is configured to press the mark function object into the first stack.
第二获取单元325,用于次对所述输入参数进行解析,以获取所述输入参数的类型。The second obtaining unit 325 is configured to parse the input parameter to obtain the type of the input parameter.
第五处理单元326,用于根据所述输入参数的类型对所述输入参数进行压栈出栈操作。The fifth processing unit 326 is configured to perform a push stacking operation on the input parameter according to the type of the input parameter.
具体请参照图10,其为本申请一实施例提供的一种表达式处理装置中第五处理单元326的示意性框图。进一步地,所述输入参数的类型包括操作数对象以及运算符对象,所述第五处理单元326包括第六处理单元3261、第三获取单元3262、第三判断单元3263、第七处理单元3264以及第八处理单元3265。For details, please refer to FIG. 10 , which is a schematic block diagram of a fifth processing unit 326 in an expression processing apparatus according to an embodiment of the present application. Further, the type of the input parameter includes an operand object and an operator object, and the fifth processing unit 326 includes a sixth processing unit 3261, a third obtaining unit 3262, a third determining unit 3263, a seventh processing unit 3264, and The eighth processing unit 3265.
第六处理单元3261,用于若所述输入参数的类型为操作数对象,将所述操作数对象压入所述第二堆栈。The sixth processing unit 3261 is configured to press the operand object into the second stack if the type of the input parameter is an operand object.
第三获取单元3262,用于若所述输入参数的类型为运算符对象,获取所述 运算符对象对应的第一优先级等级,以及获取位于所述第一堆栈中栈顶的运算符对象对应的第二优先级等级。The third obtaining unit 3262 is configured to: if the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain an operator object corresponding to a top of the stack in the first stack The second priority level.
第三判断单元3263,用于判断所述第一优先等级是否低于所述第二优先级等级。The third determining unit 3263 is configured to determine whether the first priority level is lower than the second priority level.
第七处理单元3264,用于若所述第一优先等级低于所述第二优先级等级,将所述位于所述第一堆栈中栈顶的运算符对象从所述第一堆栈中弹出并压入所述第二堆栈。The seventh processing unit 3264 is configured to: if the first priority level is lower than the second priority level, pop the operator object located at the top of the stack in the first stack from the first stack Pressing into the second stack.
第八处理单元3265,用于若所述第一优先等级高于所述第二优先级等级,将所述运算符对象压入所述第一堆栈。The eighth processing unit 3265 is configured to press the operator object into the first stack if the first priority level is higher than the second priority level.
第二判断单元330,用于判断所述表达式是否全部解析成功。The second determining unit 330 is configured to determine whether the expression is all parsed successfully.
第三处理单元340,用于若所述表达式已全部解析成功,将存储于所述第一堆栈的表达式对象压入所述第二堆栈。The third processing unit 340 is configured to press the expression object stored in the first stack into the second stack if the expression has been completely parsed successfully.
第一生成单元350,用于逆序弹出所述第二堆栈中的表达式对象,以生成所述逆波兰表达式。The first generating unit 350 is configured to pop the expression object in the second stack in reverse order to generate the inverse Polish expression.
执行单元400,用于执行所述逆波兰表达式以生成执行结果。The execution unit 400 is configured to execute the inverse Polish expression to generate an execution result.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
上述装置10可以实现为一种计算机程序的形式,计算机程序可以在如图11所示的计算机设备上运行。The apparatus 10 described above can be implemented in the form of a computer program that can be run on a computer device as shown in FIG.
请参阅图11,图11是本申请实施例提供的一种计算机设备的示意性框图。该计算机设备500设备可以是终端。该终端可以是智能手机、平板电脑、笔记本电脑、台式电脑、个人数字助理和穿戴式设备等具有通信功能的电子设备。Referring to FIG. 11, FIG. 11 is a schematic block diagram of a computer device according to an embodiment of the present application. The computer device 500 device can be a terminal. The terminal can be a communication-enabled electronic device such as a smart phone, a tablet computer, a notebook computer, a desktop computer, a personal digital assistant, and a wearable device.
该计算机设备500包括通过***总线510连接的处理器520、存储器和网络接口550,其中,存储器可以包括非易失性存储介质530和内存储器540。The computer device 500 includes a processor 520, a memory, and a network interface 550 that are coupled by a system bus 510, where the memory can include a non-volatile storage medium 530 and an internal memory 540.
该非易失性存储介质530可存储操作***531和计算机程序532。该计算机程序532被执行时,可使得处理器520执行一种表达式处理方法。The non-volatile storage medium 530 can store an operating system 531 and a computer program 532. When the computer program 532 is executed, the processor 520 can be caused to perform an expression processing method.
该处理器520用于提供计算和控制能力,支撑整个计算机设备500的运行。The processor 520 is used to provide computing and control capabilities to support the operation of the entire computer device 500.
该内存储器540为非易失性存储介质中的计算机程序的运行提供环境,该计算机程序被处理器520执行时,可使得处理器520执行一种表达式处理方法。The internal memory 540 provides an environment for the operation of a computer program in a non-volatile storage medium that, when executed by the processor 520, causes the processor 520 to perform an expression processing method.
该网络接口550用于进行网络通信,如发送分配的任务等。本领域技术人员可以理解,该计算机设备的示意性框图仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备500的限定,具体的计算机设备500可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。The network interface 550 is used for network communication, such as sending assigned tasks and the like. It will be understood by those skilled in the art that the schematic block diagram of the computer device is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the computer device 500 to which the solution of the present application is applied. The specific computer device 500 More or fewer components than those shown in the figures may be included, or some components may be combined, or have different component arrangements.
其中,所述处理器520用于运行存储在存储器中的程序代码,以实现如下功能本申请实施例的表达式处理方法。The processor 520 is configured to run the program code stored in the memory to implement the following method for the expression processing of the embodiment of the present application.
应当理解,在本申请实施例中,处理器520可以是中央处理单元(Central Processing Unit,CPU),该处理器520还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。It should be understood that, in the embodiment of the present application, the processor 520 may be a central processing unit (CPU), and the processor 520 may also be other general-purpose processors, a digital signal processor (DSP), Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware component, etc. The general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
本领域技术人员可以理解,该计算机设备500的示意性框图并不构成对计算机设备500的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art will appreciate that the schematic block diagram of the computer device 500 does not constitute a limitation to the computer device 500, and may include more or fewer components than those illustrated, or some components may be combined, or different component arrangements.
在本申请的另一实施例中提供一种计算机可读存储介质,该计算机可读存储介质存储有计算机程序,其中计算机程序包括程序指令。所述程序指令被处理器执行时实现本申请实施例的表达式处理方法。In another embodiment of the present application, a computer readable storage medium is stored, the computer readable storage medium storing a computer program, wherein the computer program comprises program instructions. The expression processing method of the embodiment of the present application is implemented when the program instruction is executed by a processor.
该计算机可读存储介质可以是U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、磁碟或者光盘等各种可以存储程序代码的介质。The computer readable storage medium may be any medium that can store program code, such as a USB flash drive, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working process of the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。The foregoing is only a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto, and any equivalents can be easily conceived by those skilled in the art within the technical scope disclosed in the present application. Modifications or substitutions are intended to be included within the scope of the present application. Therefore, the scope of protection of this application should be determined by the scope of protection of the claims.
Claims (20)
- 一种表达式处理方法,其特征在于,包括:An expression processing method, comprising:对表达式进行解析,以获取所述表达式中的表达式对象;Parsing an expression to obtain an expression object in the expression;获取所述表达式对象的类型;Get the type of the expression object;根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式;Performing an inverse Polish transformation on the expression according to the type of the expression object to generate an inverse Polish expression;执行所述逆波兰表达式以生成执行结果。The inverse Polish expression is executed to generate an execution result.
- 如权利要求1所述的方法,其特征在于,所述获取所述表达式对象的类型,包括:The method of claim 1, wherein the obtaining the type of the expression object comprises:判断所述表达式对象是否包含预设的函数标记符;Determining whether the expression object includes a preset function tag;若所述表达式对象包含预设的函数标记符,确定所述表达式对象为函数对象。If the expression object contains a preset function tag, it is determined that the expression object is a function object.
- 如权利要求1所述的方法,其特征在于,所述根据所述表达式对象的类型将所述表达式进行逆波兰转换,包括:The method of claim 1, wherein said inversely converting said expression according to a type of said expression object comprises:初始化预设的第一堆栈以及预设的第二堆栈;Initializing a preset first stack and a preset second stack;根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作;And stacking the expression object according to the type of the expression object;判断所述表达式是否全部解析成功;Determining whether the expression is all parsed successfully;若所述表达式已全部解析成功,将存储于所述第一堆栈的表达式对象压入所述第二堆栈;If the expression has been fully parsed successfully, the expression object stored in the first stack is pushed into the second stack;逆序弹出所述第二堆栈中的表达式对象,以生成所述逆波兰表达式。The expression object in the second stack is popped in reverse order to generate the inverse Polish expression.
- 如权利要求3所述的方法,其特征在于,所述根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作,包括:The method of claim 3, wherein the step of popping the stack object according to the type of the expression object comprises:若所述表达式对象为函数对象,获取所述函数对象对应的输入参数以及所述输入参数对应的入参数量;If the expression object is a function object, obtain an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter;对所述入参数量进行标记处理;Marking the input parameter quantity;将标记后的入参数量与所述函数对象合并,以生成标记函数对象;Combining the marked in-argument parameter with the function object to generate a tag function object;将所述标记函数对象压入所述第一堆栈;Pressing the markup function object into the first stack;依次对所述输入参数进行解析,以获取所述输入参数的类型;And parsing the input parameter in sequence to obtain a type of the input parameter;根据所述输入参数的类型对所述输入参数进行压栈出栈操作。The input parameter is popped and popped according to the type of the input parameter.
- 如权利要求4所述的方法,其特征在于,所述输入参数的类型包括操作数对象以及运算符对象,所述根据所述输入参数的类型对所述输入参数进行压栈出栈操作,包括:The method of claim 4, wherein the type of the input parameter comprises an operand object and an operator object, and wherein the input parameter is popped and popped according to a type of the input parameter, including :若所述输入参数的类型为操作数对象,将所述操作数对象压入所述第二堆栈;If the type of the input parameter is an operand object, pressing the operand object into the second stack;若所述输入参数的类型为运算符对象,获取所述运算符对象对应的第一优先级等级,以及获取位于所述第一堆栈中栈顶的运算符对象对应的第二优先级等级;If the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain a second priority level corresponding to the operator object located at the top of the stack in the first stack;判断所述第一优先等级是否低于所述第二优先级等级;Determining whether the first priority level is lower than the second priority level;若所述第一优先等级低于所述第二优先级等级,将所述位于所述第一堆栈中栈顶的运算符对象从所述第一堆栈中弹出并压入所述第二堆栈;If the first priority level is lower than the second priority level, the operator object located at the top of the stack in the first stack is popped from the first stack and pushed into the second stack;若所述第一优先等级高于所述第二优先级等级,将所述运算符对象压入所述第一堆栈。If the first priority level is higher than the second priority level, the operator object is pushed into the first stack.
- 一种表达式处理装置,其特征在于,所述装置包括:An expression processing device, characterized in that the device comprises:对象获取单元,用于对表达式进行解析,以获取所述表达式中的表达式对象;An object obtaining unit, configured to parse the expression to obtain an expression object in the expression;类型获取单元,用于获取所述表达式对象的类型;a type obtaining unit, configured to acquire a type of the expression object;转换单元,用于根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式;a converting unit, configured to inversely convert the expression according to a type of the expression object to generate an inverse Polish expression;执行单元,用于执行所述逆波兰表达式以生成执行结果。An execution unit for executing the inverse Polish expression to generate an execution result.
- 如权利要求6所述的装置,其特征在于,所述类型获取单元包括:The device according to claim 6, wherein the type obtaining unit comprises:第一判断单元,用于判断所述表达式对象是否包含预设的函数标记符;a first determining unit, configured to determine whether the expression object includes a preset function tag;第一处理单元,用于若所述表达式对象包含预设的函数标记符,确定所述表达式对象为函数对象。The first processing unit is configured to determine that the expression object is a function object if the expression object includes a preset function tag.
- 如权利要求6所述的装置,其特征在于,所述转换单元包括:The apparatus of claim 6 wherein said converting unit comprises:初始化单元,用于预设的第一堆栈以及预设的第二堆栈;An initializing unit, configured to preset a first stack and a preset second stack;第二处理单元,用于根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作;a second processing unit, configured to perform a push stacking operation on the expression object according to the type of the expression object;第二判断单元,用于判断所述表达式是否全部解析成功;a second determining unit, configured to determine whether the expression is all parsed successfully;第三处理单元,用于若所述表达式已全部解析成功,将存储于所述第一堆 栈的表达式对象压入所述第二堆栈;a third processing unit, configured to: if the expression has been completely parsed successfully, push an expression object stored in the first stack into the second stack;第一生成单元,用于逆序弹出所述第二堆栈中的表达式对象,以生成所述逆波兰表达式。a first generating unit, configured to pop the expression object in the second stack in reverse order to generate the inverse Polish expression.
- 如权利要求8所述的装置,其特征在于,所述第二处理单元包括:The apparatus of claim 8 wherein said second processing unit comprises:第一获取单元,用于若所述表达式对象为函数对象,获取所述函数对象对应的输入参数以及所述输入参数对应的入参数量;a first acquiring unit, configured to acquire an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter, if the expression object is a function object;标记单元,用于对所述入参数量进行标记处理;a marking unit, configured to perform marking processing on the input parameter quantity;第二生成单元,用于将标记后的入参数量与所述函数对象合并,以生成标记函数对象;a second generating unit, configured to merge the marked input parameter quantity with the function object to generate a label function object;第四处理单元,用于将所述标记函数对象压入所述第一堆栈;a fourth processing unit, configured to press the mark function object into the first stack;第二获取单元,用于依次对所述输入参数进行解析,以获取所述输入参数的类型;a second acquiring unit, configured to sequentially parse the input parameter to obtain a type of the input parameter;第五处理单元,用于根据所述输入参数的类型对所述输入参数进行压栈出栈操作。And a fifth processing unit, configured to perform a push stacking operation on the input parameter according to the type of the input parameter.
- 如权利要求9所述的装置,其特征在于,所述输入参数的类型包括操作数对象以及运算符对象,所述第五处理单元包括:The apparatus of claim 9, wherein the type of the input parameter comprises an operand object and an operator object, and the fifth processing unit comprises:第六处理单元,用于若所述输入参数的类型为操作数对象,将所述操作数对象压入所述第二堆栈;a sixth processing unit, configured to: press the operand object into the second stack if the type of the input parameter is an operand object;第三获取单元,用于若所述输入参数的类型为运算符对象,获取所述运算符对象对应的第一优先级等级,以及获取位于所述第一堆栈中栈顶的运算符对象对应的第二优先级等级;a third acquiring unit, configured to: if the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain an operator object corresponding to the top of the stack in the first stack Second priority level;第三判断单元,用于判断所述第一优先等级是否低于所述第二优先级等级;a third determining unit, configured to determine whether the first priority level is lower than the second priority level;第七处理单元,用于若所述第一优先等级低于所述第二优先级等级,将所述位于所述第一堆栈中栈顶的运算符对象从所述第一堆栈中弹出并压入所述第二堆栈;a seventh processing unit, configured to: when the first priority level is lower than the second priority level, eject and press the operator object located at the top of the stack in the first stack from the first stack Into the second stack;第八处理单元,用于若所述第一优先等级高于所述第二优先级等级,将所述运算符对象压入所述第一堆栈。And an eighth processing unit, configured to: press the operator object into the first stack if the first priority level is higher than the second priority level.
- 一种计算机设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,其特征在于,所述处理器执行所述程序时实现以下步骤:A computer apparatus comprising a memory, a processor, and a computer program stored on the memory and operative on the processor, wherein the processor, when executing the program, implements the following steps:对表达式进行解析,以获取所述表达式中的表达式对象;Parsing an expression to obtain an expression object in the expression;获取所述表达式对象的类型;Get the type of the expression object;根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式;Performing an inverse Polish transformation on the expression according to the type of the expression object to generate an inverse Polish expression;执行所述逆波兰表达式以生成执行结果。The inverse Polish expression is executed to generate an execution result.
- 如权利要求11所述的计算机设备,其特征在于,所述获取所述表达式对象的类型,包括:The computer device according to claim 11, wherein the obtaining the type of the expression object comprises:判断所述表达式对象是否包含预设的函数标记符;Determining whether the expression object includes a preset function tag;若所述表达式对象包含预设的函数标记符,确定所述表达式对象为函数对象。If the expression object contains a preset function tag, it is determined that the expression object is a function object.
- 如权利要求11所述的计算机设备,其特征在于,所述根据所述表达式对象的类型将所述表达式进行逆波兰转换,包括:The computer apparatus according to claim 11, wherein said inversely converting said expression according to a type of said expression object comprises:初始化预设的第一堆栈以及预设的第二堆栈;Initializing a preset first stack and a preset second stack;根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作;And stacking the expression object according to the type of the expression object;判断所述表达式是否全部解析成功;Determining whether the expression is all parsed successfully;若所述表达式已全部解析成功,将存储于所述第一堆栈的表达式对象压入所述第二堆栈;If the expression has been fully parsed successfully, the expression object stored in the first stack is pushed into the second stack;逆序弹出所述第二堆栈中的表达式对象,以生成所述逆波兰表达式。The expression object in the second stack is popped in reverse order to generate the inverse Polish expression.
- 如权利要求13所述的计算机设备,其特征在于,所述根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作,包括:The computer device according to claim 13, wherein the step of pushing the stacking operation on the expression object according to the type of the expression object comprises:若所述表达式对象为函数对象,获取所述函数对象对应的输入参数以及所述输入参数对应的入参数量;If the expression object is a function object, obtain an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter;对所述入参数量进行标记处理;Marking the input parameter quantity;将标记后的入参数量与所述函数对象合并,以生成标记函数对象;Combining the marked in-argument parameter with the function object to generate a tag function object;将所述标记函数对象压入所述第一堆栈;Pressing the markup function object into the first stack;依次对所述输入参数进行解析,以获取所述输入参数的类型;And parsing the input parameter in sequence to obtain a type of the input parameter;根据所述输入参数的类型对所述输入参数进行压栈出栈操作。The input parameter is popped and popped according to the type of the input parameter.
- 如权利要求14所述的计算机设备,其特征在于,所述输入参数的类型包括操作数对象以及运算符对象,所述根据所述输入参数的类型对所述输入参数进行压栈出栈操作,包括:The computer device according to claim 14, wherein the type of the input parameter comprises an operand object and an operator object, and the input parameter is popped and popped according to a type of the input parameter, include:若所述输入参数的类型为操作数对象,将所述操作数对象压入所述第二堆栈;If the type of the input parameter is an operand object, pressing the operand object into the second stack;若所述输入参数的类型为运算符对象,获取所述运算符对象对应的第一优先级等级,以及获取位于所述第一堆栈中栈顶的运算符对象对应的第二优先级等级;If the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain a second priority level corresponding to the operator object located at the top of the stack in the first stack;判断所述第一优先等级是否低于所述第二优先级等级;Determining whether the first priority level is lower than the second priority level;若所述第一优先等级低于所述第二优先级等级,将所述位于所述第一堆栈中栈顶的运算符对象从所述第一堆栈中弹出并压入所述第二堆栈;If the first priority level is lower than the second priority level, the operator object located at the top of the stack in the first stack is popped from the first stack and pushed into the second stack;若所述第一优先等级高于所述第二优先级等级,将所述运算符对象压入所述第一堆栈。If the first priority level is higher than the second priority level, the operator object is pushed into the first stack.
- 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时使所述处理器执行以下操作:A computer readable storage medium, characterized in that the computer readable storage medium stores a computer program, the computer program comprising program instructions that, when executed by a processor, cause the processor to perform the following operations :对表达式进行解析,以获取所述表达式中的表达式对象;Parsing an expression to obtain an expression object in the expression;获取所述表达式对象的类型;Get the type of the expression object;根据所述表达式对象的类型将所述表达式进行逆波兰转换,以生成逆波兰表达式;Performing an inverse Polish transformation on the expression according to the type of the expression object to generate an inverse Polish expression;执行所述逆波兰表达式以生成执行结果。The inverse Polish expression is executed to generate an execution result.
- 如权利要求16所述的计算机可读存储介质,其特征在于,所述获取所述表达式对象的类型,包括:The computer readable storage medium of claim 16, wherein the obtaining the type of the expression object comprises:判断所述表达式对象是否包含预设的函数标记符;Determining whether the expression object includes a preset function tag;若所述表达式对象包含预设的函数标记符,确定所述表达式对象为函数对象。If the expression object contains a preset function tag, it is determined that the expression object is a function object.
- 如权利要求16所述的计算机可读存储介质,其特征在于,所述根据所述表达式对象的类型将所述表达式进行逆波兰转换,包括:The computer readable storage medium of claim 16, wherein said performing an inverse Polish conversion of said expression according to a type of said expression object comprises:初始化预设的第一堆栈以及预设的第二堆栈;Initializing a preset first stack and a preset second stack;根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作;And stacking the expression object according to the type of the expression object;判断所述表达式是否全部解析成功;Determining whether the expression is all parsed successfully;若所述表达式已全部解析成功,将存储于所述第一堆栈的表达式对象压入所述第二堆栈;If the expression has been fully parsed successfully, the expression object stored in the first stack is pushed into the second stack;逆序弹出所述第二堆栈中的表达式对象,以生成所述逆波兰表达式。The expression object in the second stack is popped in reverse order to generate the inverse Polish expression.
- 如权利要求18所述的计算机可读存储介质,其特征在于,所述根据所述表达式对象的类型,对所述表达式对象进行压栈出栈操作,包括:The computer readable storage medium according to claim 18, wherein said performing a push stacking operation on said expression object according to a type of said expression object comprises:若所述表达式对象为函数对象,获取所述函数对象对应的输入参数以及所述输入参数对应的入参数量;If the expression object is a function object, obtain an input parameter corresponding to the function object and an input parameter quantity corresponding to the input parameter;对所述入参数量进行标记处理;Marking the input parameter quantity;将标记后的入参数量与所述函数对象合并,以生成标记函数对象;Combining the marked in-argument parameter with the function object to generate a tag function object;将所述标记函数对象压入所述第一堆栈;Pressing the markup function object into the first stack;依次对所述输入参数进行解析,以获取所述输入参数的类型;And parsing the input parameter in sequence to obtain a type of the input parameter;根据所述输入参数的类型对所述输入参数进行压栈出栈操作。The input parameter is popped and popped according to the type of the input parameter.
- 如权利要求19所述的计算机可读存储介质,其特征在于,所述输入参数的类型包括操作数对象以及运算符对象,所述根据所述输入参数的类型对所述输入参数进行压栈出栈操作,包括:The computer readable storage medium of claim 19, wherein the type of the input parameter comprises an operand object and an operator object, and the input parameter is pushed out according to a type of the input parameter Stack operations, including:若所述输入参数的类型为操作数对象,将所述操作数对象压入所述第二堆栈;If the type of the input parameter is an operand object, pressing the operand object into the second stack;若所述输入参数的类型为运算符对象,获取所述运算符对象对应的第一优先级等级,以及获取位于所述第一堆栈中栈顶的运算符对象对应的第二优先级等级;If the type of the input parameter is an operator object, obtain a first priority level corresponding to the operator object, and obtain a second priority level corresponding to the operator object located at the top of the stack in the first stack;判断所述第一优先等级是否低于所述第二优先级等级;Determining whether the first priority level is lower than the second priority level;若所述第一优先等级低于所述第二优先级等级,将所述位于所述第一堆栈中栈顶的运算符对象从所述第一堆栈中弹出并压入所述第二堆栈;If the first priority level is lower than the second priority level, the operator object located at the top of the stack in the first stack is popped from the first stack and pushed into the second stack;若所述第一优先等级高于所述第二优先级等级,将所述运算符对象压入所述第一堆栈。If the first priority level is higher than the second priority level, the operator object is pushed into the first stack.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810175368.X | 2018-03-02 | ||
CN201810175368.XA CN108491207B (en) | 2018-03-02 | 2018-03-02 | Expression processing method, device, equipment and computer readable storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2019165706A1 true WO2019165706A1 (en) | 2019-09-06 |
Family
ID=63341365
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2018/085277 WO2019165706A1 (en) | 2018-03-02 | 2018-05-02 | Expression processing method, apparatus, device, and computer readable storage medium |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN108491207B (en) |
WO (1) | WO2019165706A1 (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111767004A (en) * | 2020-06-30 | 2020-10-13 | 电子科技大学 | Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110333844B (en) * | 2019-05-06 | 2023-08-29 | 北京创鑫旅程网络技术有限公司 | Calculation formula processing method and device |
CN110532260B (en) * | 2019-07-23 | 2021-05-25 | 北京三快在线科技有限公司 | Logic expression storage and reading method and device, electronic equipment and medium |
CN111008020B (en) * | 2019-12-24 | 2023-04-07 | 四川新网银行股份有限公司 | Method for analyzing logic expression into general query statement |
CN111191106B (en) * | 2019-12-30 | 2023-05-12 | 上海携程商务有限公司 | DSL construction method, system, electronic device and medium |
CN111708540B (en) * | 2020-04-30 | 2023-11-28 | 北京配天技术有限公司 | Variable parameter function analysis method, analyzer and storage device |
CN111784148A (en) * | 2020-06-28 | 2020-10-16 | 京东数字科技控股有限公司 | Data processing method and device, electronic equipment and storage medium |
CN113947334A (en) * | 2021-11-11 | 2022-01-18 | 昆明电力交易中心有限责任公司 | Configurable power transaction risk monitoring method and device and computer equipment |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1832419A (en) * | 2005-03-08 | 2006-09-13 | 华为技术有限公司 | Analytic method of expression type |
CN101000615A (en) * | 2006-12-31 | 2007-07-18 | 华为技术有限公司 | Service processing method and device based on data base |
CN102779044A (en) * | 2012-06-28 | 2012-11-14 | 用友软件股份有限公司 | Analysis processing system and analysis processing method of expression |
CN103023766A (en) * | 2012-11-23 | 2013-04-03 | 山东电力集团公司 | Dynamic routing method based on expression judgment |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS6073731A (en) * | 1983-09-29 | 1985-04-25 | Fujitsu Ltd | Processing system of logical operator |
CN103440331B (en) * | 2013-09-05 | 2017-02-08 | 五八同城信息技术有限公司 | Reverse Polish and multi-way tree-based search engine query statement analyzing method |
CN106649212A (en) * | 2016-09-12 | 2017-05-10 | 济南浪潮高新科技投资发展有限公司 | Business data processing method and device |
CN106648753A (en) * | 2016-11-23 | 2017-05-10 | 北京航天自动控制研究所 | Automatic criterion analysis method based on reverse Polish notation algorithm |
CN107092656B (en) * | 2017-03-23 | 2019-12-03 | 中国科学院计算技术研究所 | A kind of tree data processing method and system |
-
2018
- 2018-03-02 CN CN201810175368.XA patent/CN108491207B/en active Active
- 2018-05-02 WO PCT/CN2018/085277 patent/WO2019165706A1/en active Application Filing
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1832419A (en) * | 2005-03-08 | 2006-09-13 | 华为技术有限公司 | Analytic method of expression type |
CN101000615A (en) * | 2006-12-31 | 2007-07-18 | 华为技术有限公司 | Service processing method and device based on data base |
CN102779044A (en) * | 2012-06-28 | 2012-11-14 | 用友软件股份有限公司 | Analysis processing system and analysis processing method of expression |
CN103023766A (en) * | 2012-11-23 | 2013-04-03 | 山东电力集团公司 | Dynamic routing method based on expression judgment |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111767004A (en) * | 2020-06-30 | 2020-10-13 | 电子科技大学 | Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm |
CN111767004B (en) * | 2020-06-30 | 2022-02-11 | 电子科技大学 | Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm |
Also Published As
Publication number | Publication date |
---|---|
CN108491207A (en) | 2018-09-04 |
CN108491207B (en) | 2020-11-17 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2019165706A1 (en) | Expression processing method, apparatus, device, and computer readable storage medium | |
US11106437B2 (en) | Lookup table optimization for programming languages that target synchronous digital circuits | |
CN108845839B (en) | Application page loading method and device and computer readable storage medium | |
CN111460815B (en) | Rule processing method, apparatus, medium, and electronic device | |
WO2021175053A1 (en) | Method and apparatus for executing functional module in virtual machine | |
US20230315416A1 (en) | Code translation method and apparatus, and device | |
CN111177113A (en) | Data migration method and device, computer equipment and storage medium | |
CN112416331A (en) | Page adaptation method and device, electronic equipment and computer readable storage medium | |
CN112506569A (en) | Bytecode execution method, bytecode execution device and terminal equipment | |
CN113468534B (en) | Vulnerability detection method and related device for android application program | |
US9274755B2 (en) | Infrastructure for generating code using annotation and template generators | |
CN111190750A (en) | Data processing method and system | |
CN112667225A (en) | Method, system, equipment and readable storage medium for prototype graph code conversion | |
CN111026604B (en) | Log file analysis method and device | |
CN114911541B (en) | Processing method and device of configuration information, electronic equipment and storage medium | |
CN115629795A (en) | Configuration method and device of executable file and electronic equipment | |
CN115291839A (en) | Localization method of virtual method type API of JAVA card, electronic equipment and medium | |
CN114385868B (en) | Regular expression generation method, device, medium and equipment | |
CN105868113B (en) | String searching method and device | |
CN112540755A (en) | Front-end-based component processing method, device, equipment and storage medium | |
CN109783134B (en) | Front-end page configuration method and device and electronic equipment | |
CN113296827A (en) | Method and device for converting different languages and terminal equipment | |
CN111273913A (en) | Method and device for outputting application program interface data represented by specifications | |
CN113031952A (en) | Method and device for determining execution code of deep learning model and storage medium | |
CN117075912B (en) | Method for program language conversion, compiling method and related equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 18907909 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
32PN | Ep: public notification in the ep bulletin as address of the adressee cannot be established |
Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 01.12.2020) |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 18907909 Country of ref document: EP Kind code of ref document: A1 |