CN108491207B - Expression processing method, device, equipment and computer readable storage medium - Google Patents

Expression processing method, device, equipment and computer readable storage medium Download PDF

Info

Publication number
CN108491207B
CN108491207B CN201810175368.XA CN201810175368A CN108491207B CN 108491207 B CN108491207 B CN 108491207B CN 201810175368 A CN201810175368 A CN 201810175368A CN 108491207 B CN108491207 B CN 108491207B
Authority
CN
China
Prior art keywords
expression
stack
type
function
unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810175368.XA
Other languages
Chinese (zh)
Other versions
CN108491207A (en
Inventor
彭明强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN201810175368.XA priority Critical patent/CN108491207B/en
Priority to PCT/CN2018/085277 priority patent/WO2019165706A1/en
Publication of CN108491207A publication Critical patent/CN108491207A/en
Application granted granted Critical
Publication of CN108491207B publication Critical patent/CN108491207B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Abstract

The embodiment of the invention provides an expression processing method, an expression processing device, expression processing equipment and a computer readable storage medium. Analyzing an expression to obtain an expression object in the expression; acquiring the type of the expression object; according to the type of the expression object, performing inverse Polish conversion on the expression to generate an inverse Polish expression; executing the inverse Polish expression to generate an execution result. By implementing the invention, the conversion mode of the expression can be optimized, the problem that the function object can not be called after format conversion is solved, and the expansibility and the execution efficiency of the expression are improved.

Description

Expression processing method, device, equipment and computer readable storage medium
Technical Field
The present invention relates to the field of computer data processing, and in particular, to a method, an apparatus, a device, and a computer-readable storage medium for processing an expression.
Background
A computer program is a list of instructions that describe actions to be performed by a computer or processor-based device. When the computer program is loaded and executed on computer hardware, the computer will behave in a predetermined manner following the instructions of the computer program. A large number of expressions are used in a computer program, an Expression (Expression) being a sequence of operators (Operator) and operands (Operator nd), for example an Expression may be "3 + 2". In the process of executing the expression by the computer, the computer cannot identify the expression written according to the natural language, so that corresponding format conversion needs to be performed on the expression for the computer to read, but in the prior art, format conversion on the expression can only be performed according to an operator and an operand of the expression, so that the converted expression cannot call a function object, the expression cannot realize logic operation with higher complexity, and problems of long program code, low execution efficiency and the like are easily caused.
Disclosure of Invention
The invention provides an expression processing method, an expression processing device, expression processing equipment and a computer readable storage medium, and aims to solve the problem that an expression cannot call a function object after format conversion.
In a first aspect, the present invention provides an expression processing method, including:
analyzing the expression to obtain an expression object in the expression;
acquiring the type of the expression object;
according to the type of the expression object, performing inverse Polish conversion on the expression to generate an inverse Polish expression;
executing the inverse Polish expression to generate an execution result.
In a second aspect, the present invention provides an expression processing apparatus comprising:
the object acquisition unit is used for analyzing the expression to acquire an expression object in the expression;
the type acquisition unit is used for acquiring the type of the expression object;
the conversion unit is used for carrying out inverse Polish conversion on the expression according to the type of the expression object so as to generate an inverse Polish expression;
and the execution unit is used for executing the inverse Polish expression to generate an execution result.
In a third aspect, the present invention provides a computer device, including a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the expression processing method according to any one of the invention when executing the program.
In a fourth aspect, the present invention also provides a computer-readable storage medium, wherein 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 execute any one of the expression processing methods provided by the invention.
The invention provides an expression processing method, an expression processing device, computer equipment and a computer readable storage medium. By implementing the embodiment of the invention, the expression is analyzed to obtain the expression correspondence and the type corresponding to the expression, then inverse Polish conversion is carried out according to the type of the expression object, and the generated inverse Polish expression is executed to generate the execution result. The conversion mode of the expression is optimized, the problem that the function object cannot be called after format conversion is solved, and the expansibility and the execution efficiency of the expression are improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flow chart of an expression processing method according to an embodiment of the present invention;
FIG. 2 is a sub-flow diagram of an expression processing method according to an embodiment of the present invention;
FIG. 3 is a sub-flow diagram of an expression processing method according to an embodiment of the present invention;
FIG. 4 is a sub-flow diagram of an expression processing method according to an embodiment of the present invention;
FIG. 5 is a sub-flow diagram of an expression processing method according to an embodiment of the present invention;
FIG. 6 is a schematic block diagram of an expression processing apparatus according to an embodiment of the present invention;
fig. 7 is a schematic block diagram of a first generation unit in an expression processing apparatus according to an embodiment of the present invention;
fig. 8 is a schematic block diagram of a type obtaining unit in an expression processing apparatus according to an embodiment of the present invention;
fig. 9 is a schematic block diagram of a conversion unit in an expression processing apparatus according to an embodiment of the present invention;
fig. 10 is a schematic block diagram of a second processing unit in an expression processing apparatus according to an embodiment of the present invention;
fig. 11 is a schematic block diagram of a computer device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
Fig. 1 is a flowchart illustrating an expression processing method according to an embodiment of the present invention. The expression processing method can be applied to terminals such as servers, desktop computers, laptop computers, tablet computers, Personal Digital Assistants (PDAs), smart phones (such as Android phones and IOS phones). In particular, the method comprises steps S100-S400.
S100, analyzing the expression to obtain an expression object in the expression.
Specifically, the Expression (Expression) is a sequence of an Operator (Operator) and an Operand (Operator nd). The expression object comprises an operator object and an operand object. Common operator objects are, for example, arithmetic operators (e.g. +, -, ×, ÷ etc.), relational operators (e.g. <, >, etc.), and logical operators (e.g. &, (), | | etc.); common operand objects are, for example, numbers (1, 23, etc.), variables (var, a, etc.).
The analysis of the expression can be realized by using a programming language such as Java and the like to realize a combined parser and analyze the expression by using the combined parser, so as to analyze the expression into an expression object. An expression may include one or more types of expression objects, and different types of expression objects may be parsed by different parsers. For example, a string is parsed by a constant parser, and constants in the string can be generated into corresponding expression objects.
S200, acquiring the type of the expression object.
Referring to fig. 2, a sub-flow diagram of an expression processing method according to an embodiment of the present invention is shown. Further, the obtaining of the type of the expression object in step S200 includes steps S210-S220.
S210, judging whether the expression object contains a preset function marker.
Specifically, the function flag may be set according to a specific expression use environment, for example, the function flag may be "$", "rah", and the like, and the specific symbol of the function flag is not limited in the embodiment of the present invention. The function marker may be placed before the first character of the expression object. And if the expression object comprises the function marker, judging that the expression object comprises a preset function marker.
S220, if the expression object contains a preset function marker, determining the expression object as a function object.
Specifically, assuming that the function marker is "$", if the expression object is "$ startswitch", it may be determined through detection that the expression object "$ startswitch" includes a preset function marker "$", and then the expression object "$ startswitch" is determined as the function object.
By implementing the embodiment of the invention, the function object is introduced into the expression and the preset function identifier is set in the function object, so that the expression form of the expression is greatly enriched and the expansibility of the expression is improved. The function object is directly referred to calculate the operand, so that the writing workload of the expression is reduced, and the running efficiency of the code program is improved.
S300, performing inverse Polish conversion on the expression according to the type of the expression object to generate an inverse Polish expression.
Specifically, referring to fig. 3, a sub-flow diagram of an expression processing method according to an embodiment of the present invention is shown. Further, the inverse-wave conversion of the expression according to the type of the expression object in step S300 includes S310-S350.
S310, initialize a first stack and a second stack.
Specifically, the preset first stack and the preset second stack are used for storing an expression object in the reverse-wave-blue conversion process. The data reserved in the stack is cleared by initializing the preset first stack and the preset second stack, so that data interference caused by reverse wave-blue conversion is prevented.
S320, according to the type of the expression object, performing a push operation on the expression object.
Specifically, referring to fig. 4, a sub-flow diagram of an expression processing method according to an embodiment of the present invention is shown. Further, in step S320, according to the type of the expression object, a push operation is performed on the expression object, including steps S321-S326.
S321, if the expression object is a function object, obtaining an input parameter corresponding to the function object and an input parameter number corresponding to the input parameter.
Specifically, the obtaining the input parameter corresponding to the function object and the input parameter amount corresponding to the input parameter may include: acquiring a parameter start character, a parameter end character and a parameter separator corresponding to the function object; and segmenting the input parameters according to the parameter start character, the parameter end character and the parameter separator to obtain the input parameters corresponding to the function object and the input parameter quantity corresponding to the input parameters. Wherein the parameter start symbol may be "(", the parameter end symbol may be ")", and the parameter divider may be ",". The embodiments of the present invention do not limit the specific signs of the parameter start symbol, the parameter end symbol, and the parameter delimiter.
Assume that the function object is: $ average (a, b, c). Dividing the function object according to the parameter start symbol, the parameter end symbol and the parameter separator corresponding to the function object, wherein the obtained input parameters are 'a', 'b', 'c'; by calculating the obtained input parameters, the parameter number corresponding to the input parameters can be obtained, and the parameter number corresponding to the function object $ average (a, b, c) is 3.
And S322, marking the input parameter quantity.
Specifically, the marking process on the input parameter amount may specifically be to set a quantity identifier, which may be "[ ]", on the input parameter amount. Assuming that the number of entries is "3", the number of entries obtained by labeling the number of entries is "[ 3 ]. And marking the input parameter quantity to prevent the input parameter quantity from interfering the execution of the expression after being combined with the function object.
And S323, merging the marked input parameter number with the function object to generate a marked function object.
Specifically, assume that the function object is: average (a, b, c), the number of enrolled parameters after labeling is [3 ]. The tagged argument number is merged with the function object to generate a tagged function object of $ average [3 ].
S324, the mark function object is pushed to the first stack.
Specifically, a push operation is performed on the tagged function object to push the tagged function object onto the first stack.
And S325, analyzing the input parameters in sequence to acquire the types of the input parameters.
Specifically, the analyzing the input parameters in sequence is to analyze the input parameters from left to right. The input parameter corresponding to the function object may be an expression or an operand object. For example, assume that the function object is $ average (a, b, c + d), and 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.
And if the input parameter is an operand object, acquiring that the type of the input parameter is the operand object. If the input parameter is an expression, the expression is divided into a plurality of expression objects and then analyzed, and the type of the acquired input parameter can comprise an operand object or an operator object. For example, if the input parameter is "c + d", after the input parameter is split, the obtained expression objects are "c", "+" and "d", and the type of the input parameter "c + d" including an operator and an operand can be obtained by analyzing the "c", "+" and "d".
S326, performing a push operation on the input parameter according to the type of the input parameter.
Specifically, referring to fig. 5, a sub-flow diagram of an expression processing method according to an embodiment of the present invention is shown. Further, the type of the input parameter includes an operand object and an operator object, and the pushing operation performed on the input parameter according to the type of the input parameter in step S326 includes S3261-S3265.
S3261, if the type of the input parameter is an operand object, pushing the operand object to the second stack.
In particular, for example, if the input parameter is an operand object, e.g., "a", "b", etc., the operand object is pushed onto the second stack.
S3262, if the type of the input parameter is an operator object, acquiring a first priority level corresponding to the operator object, and acquiring a second priority level corresponding to the operator object located at the top of the first stack.
In particular, the operator objects can be operated by setting priority levels to perform operations with higher complexity. For example, the operator object "+" has a priority level of 3, the operator object "+" has a priority level of 4, and the lower the number of levels, the higher the priority level.
S3263, judging whether the first priority level is lower than the second priority level.
Specifically, assuming that the first priority level is 4-level and the second priority level is 3-level, it may be determined that the first priority level is lower than the second priority level.
S3264, if the first priority level is lower than the second priority level, popping the operator object at the top of the first stack from the first stack and pushing the operator object to the second stack.
S3265, if the first priority level is higher than the second priority level, pushing the operator object onto the first stack.
Specifically, the correctness of the operator priority of the converted inverse wave-blue expression is ensured by performing level comparison on the first priority level and the second priority level and controlling the stacking sequence of the operator object according to the level comparison result.
S330, judging whether all the expressions are successfully analyzed.
Specifically, the analysis sequence of the expressions may be performed in a sequence from left to right, and if it is detected that the expression character at the rightmost end is successfully analyzed, it is determined that all the expressions are successfully analyzed.
S340, if the expressions are all successfully analyzed, pushing the expression objects stored in the first stack to the second stack.
Specifically, pushing the expression objects stored in the first stack to the second stack is to sequentially pop the expression objects in the first stack one by one according to a first-in-last-out sequence, and sequentially push the expression objects popped out from the first stack one by one to the second stack.
S350, popping up the expression objects in the second stack in the reverse order to generate the reverse Polish expression.
Specifically, the popping the expression objects in the second stack in the reverse order is to sequentially pop the expression objects in the second stack according to a first-in first-out order.
S400, executing the inverse Polish expression to generate an execution result.
Specifically, the executing the inverse polish expression to generate an execution result may specifically include:
s410, initializing a preset third stack, and sequentially obtaining the expression object from the inverse Polish expression.
Specifically, the preset third stack is used for storing an execution result of the inverse polish expression. The sequentially obtaining the expression objects from the inverse Polish expression specifically comprises sequentially sending the expression objects from left to right to the inverse Polish expression to obtain the expression objects.
And S420, performing a push operation according to the type of the expression object.
Specifically, the expression object includes an operand object, an operator object, and a function object.
(1) And if the expression object is an operand object, pushing the operand object to the third stack.
(2) And if the expression object is an operator object, popping an operand object corresponding to the operator object from the third stack, calculating according to the operand object and the operator object, and pressing the execution result into the third stack. Specifically, each operator object corresponds to a known operand object, for example, 2 operand objects are associated with the operator object "+". And determining the number of operand objects corresponding to the operator object to be popped from the third stack by acquiring the number of the operand objects corresponding to the operator object. And calculating an operation result corresponding to the operator object through the operand object popped from the third stack and the operator object, and then pressing the calculated operation result into the third stack.
(3) If the expression object is a function object, popping an operand object corresponding to the function object from the third stack, calculating according to the operand object and the function object, and pressing the execution result into the third stack.
Specifically, as can be seen from the foregoing embodiment, in the inverse wave-to-blue conversion process of the expression, the input parameter quantity corresponding to the input parameter in the function object is obtained, and the input parameter quantity is combined with the function object after being subjected to the labeling processing, so as to generate a labeled function object. Therefore, when the inverse Polish expression is executed, the number of operand objects corresponding to the function object which needs to be popped from the third stack can be determined by acquiring the number of entries corresponding to the marked function object.
For example, assuming that the function object in the inverse wave-blue expression is $ average [3], by obtaining the number of arguments corresponding to the function object, it can be obtained that the number of arguments corresponding to the function object is 3, and it is further determined that the number of operand objects corresponding to the function object needs to be popped from the third stack is 3.
In an embodiment of the present invention, the function object is $ average [3] for calculating the average of the operand objects. Assume that the three operand objects popped from the third stack are "a", "b", and "c", respectively. From the function objects and the operand objects, the average values of "a", "b" and "c" may be calculated and pushed onto the third stack.
S430, judging whether all expression objects of the inverse Polish expression are acquired.
S440, if all the expression objects of the inverse polish expression are obtained, determining the last execution result pushed to the third stack as the execution result of the inverse polish expression.
By implementing the embodiment of the invention, the expression is analyzed to obtain the expression correspondence and the type corresponding to the expression, then inverse Polish conversion is carried out according to the type of the expression object, and the generated inverse Polish expression is executed to generate the execution result. The recording form of the expression can be simplified, the recognition speed of the computer system to the expression is favorably improved, and the execution efficiency of the expression is improved.
Fig. 6 is a schematic block diagram of an expression processing apparatus according to an embodiment of the present invention. 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.
An object obtaining unit 100, configured to parse the expression to obtain an expression object in the expression.
Specifically, the Expression (Expression) is a sequence of an Operator (Operator) and an Operand (Operator nd). The expression object comprises an operator object and an operand object. Common operator objects are, for example, arithmetic operators (e.g. +, -, ×, ÷ etc.), relational operators (e.g. <, >, etc.), and logical operators (e.g. &, (), | | etc.); common operand objects are, for example, numbers (1, 23, etc.), variables (var, a, etc.).
The analysis of the expression can be realized by using a programming language such as Java and the like to realize a combined parser and analyze the expression by using the combined parser, so as to analyze the expression into an expression object. An expression may include one or more types of expression objects, and different types of expression objects may be parsed by different parsers. For example, a string is parsed by a constant parser, and constants in the string can be generated into corresponding expression objects.
A type obtaining unit 200, configured to obtain a type of the expression object.
Referring to fig. 7, a schematic block diagram of a type obtaining unit 200 in an expression processing apparatus according to an embodiment of the present invention is shown. Further, the type obtaining unit 200 includes a first judging unit 210 and a first processing unit 220.
The first judging unit 210 is configured to judge whether the expression object includes a preset function marker.
Specifically, the function flag may be set according to a specific expression use environment, for example, the function flag may be "$", "rah", and the like, and the specific symbol of the function flag is not limited in the embodiment of the present invention. The function marker may be placed before the first character of the expression object. And if the expression object comprises the function marker, judging that the expression object comprises a preset function marker.
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 marker.
Specifically, assuming that the function marker is "$", if the expression object is "$ startswitch", it may be determined through detection that the expression object "$ startswitch" includes a preset function marker "$", and then the expression object "$ startswitch" is determined as the function object.
By implementing the embodiment of the invention, the function object is introduced into the expression and the preset function identifier is set in the function object, so that the expression form of the expression is greatly enriched and the expansibility of the expression is improved. The function object is directly referred to calculate the operand, so that the writing workload of the expression is reduced, and the running efficiency of the code program is improved.
A conversion unit 300, configured to perform inverse-portland conversion on the expression according to the type of the expression object to generate an inverse-portland expression.
Referring to fig. 8, a schematic block diagram of a conversion unit 300 in an expression processing apparatus according to an embodiment of the present invention is shown. Further, the conversion unit 300 includes an initialization unit 310, a second processing unit 320, a second judgment unit 330, a third processing unit 340, and a first generation unit 350.
The initialization unit 310 is used for a preset first stack and a preset second stack.
Specifically, the preset first stack and the preset second stack are used for storing an expression object in the reverse-wave-blue conversion process. The data reserved in the stack is cleared by initializing the preset first stack and the preset second stack, so that data interference caused by reverse wave-blue conversion is prevented.
The second processing unit 320 is configured to perform a push operation on the expression object according to the type of the expression object.
Referring to fig. 9, a schematic block diagram of a second processing unit 320 in an expression processing apparatus according to an embodiment of the present invention is shown. 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.
A first obtaining unit 321, configured to obtain an input parameter corresponding to the function object and an input parameter number corresponding to the input parameter if the expression object is the function object.
Specifically, the obtaining the input parameter corresponding to the function object and the input parameter amount corresponding to the input parameter may include: acquiring a parameter start character, a parameter end character and a parameter separator corresponding to the function object; and segmenting the input parameters according to the parameter start character, the parameter end character and the parameter separator to obtain the input parameters corresponding to the function object and the input parameter quantity corresponding to the input parameters. Wherein the parameter start symbol may be "(", the parameter end symbol may be ")", and the parameter divider may be ",". The embodiments of the present invention do not limit the specific signs of the parameter start symbol, the parameter end symbol, and the parameter delimiter.
Assume that the function object is: $ average (a, b, c). Dividing the function object according to the parameter start symbol, the parameter end symbol and the parameter separator corresponding to the function object, wherein the obtained input parameters are 'a', 'b', 'c'; by calculating the obtained input parameters, the parameter number corresponding to the input parameters can be obtained, and the parameter number corresponding to the function object $ average (a, b, c) is 3.
A marking unit 322, configured to perform marking processing on the input parameter quantity.
Specifically, the marking process on the input parameter amount may specifically be to set a quantity identifier, which may be "[ ]", on the input parameter amount. Assuming that the number of entries is "3", the number of entries obtained by labeling the number of entries is "[ 3 ]. And marking the input parameter quantity to prevent the input parameter quantity from interfering the execution of the expression after being combined with the function object.
A second generating unit 323, configured to merge the marked parameter number with the function object to generate a marked function object.
Specifically, assume that the function object is: average (a, b, c), the number of enrolled parameters after labeling is [3 ]. The tagged argument number is merged with the function object to generate a tagged function object of $ average [3 ].
A fourth processing unit 324 for pushing the marker function object onto the first stack.
Specifically, a push operation is performed on the tagged function object to push the tagged function object onto the first stack.
A second obtaining unit 325, configured to parse the input parameter again to obtain the type of the input parameter.
Specifically, the analyzing the input parameters in sequence is to analyze the input parameters from left to right. The input parameter corresponding to the function object may be an expression or an operand object. For example, assume that the function object is $ average (a, b, c + d), and 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.
And if the input parameter is an operand object, acquiring that the type of the input parameter is the operand object. If the input parameter is an expression, the expression is divided into a plurality of expression objects and then analyzed, and the type of the acquired input parameter can comprise an operand object or an operator object. For example, if the input parameter is "c + d", after the input parameter is split, the obtained expression objects are "c", "+" and "d", and the type of the input parameter "c + d" including an operator and an operand can be obtained by analyzing the "c", "+" and "d".
The fifth processing unit 326 is configured to perform a push operation on the input parameter according to the type of the input parameter.
Referring to fig. 10, a schematic block diagram of a fifth processing unit 326 in an expression processing apparatus according to an embodiment of the present invention is shown. Further, the types of the input parameters include 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 judging unit 3263, a seventh processing unit 3264, and an eighth processing unit 3265.
A sixth processing unit 3261, configured to push the operand object to the second stack if the type of the input parameter is an operand object.
In particular, for example, if the input parameter is an operand object, e.g., "a", "b", etc., the operand object is pushed onto the second stack.
A third obtaining unit 3262, 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 a second priority level corresponding to an operator object located at a top of the first stack.
In particular, the operator objects can be operated by setting priority levels to perform operations with higher complexity. For example, the operator object "+" has a priority level of 3, the operator object "+" has a priority level of 4, and the lower the number of levels, the higher the priority level.
A third judging unit 3263, configured to judge whether the first priority level is lower than the second priority level.
Specifically, assuming that the first priority level is 4-level and the second priority level is 3-level, it may be determined that the first priority level is lower than the second priority level.
A seventh processing unit 3264, configured to pop the operator object at the top of the first stack from the first stack and push the operator object to the second stack if the first priority level is lower than the second priority level.
An eighth processing unit 3265, configured to push the operator object onto the first stack if the first priority level is higher than the second priority level.
Specifically, the correctness of the operator priority of the converted inverse wave-blue expression is ensured by performing level comparison on the first priority level and the second priority level and controlling the stacking sequence of the operator object according to the level comparison result.
The second judging unit 330 is configured to judge whether all the expressions are successfully parsed.
Specifically, the analysis sequence of the expressions may be performed in a sequence from left to right, and if it is detected that the expression character at the rightmost end is successfully analyzed, it is determined that all the expressions are successfully analyzed.
The third processing unit 340 is configured to, if all the expressions are successfully parsed, push the expression object stored in the first stack to the second stack.
Specifically, pushing the expression objects stored in the first stack to the second stack is to sequentially pop the expression objects in the first stack one by one according to a first-in-last-out sequence, and sequentially push the expression objects popped out from the first stack one by one to the second stack.
A first generating unit 350, configured to pop up the expression objects in the second stack in a reverse order to generate the inverse portland expression.
Specifically, the popping the expression objects in the second stack in the reverse order is to sequentially pop the expression objects in the second stack according to a first-in first-out order.
An execution unit 400, configured to execute the inverse polish expression to generate an execution result.
Specifically, the generating unit includes a stack initializing unit 310, a push operating unit, an expression judging unit, and a result determining unit.
The stack initialization unit 310 is configured to initialize a preset third stack, and sequentially obtain the expression object from the inverse polish expression.
Specifically, the preset third stack is used for storing an execution result of the inverse polish expression. The sequentially obtaining the expression objects from the inverse Polish expression specifically comprises sequentially sending the expression objects from left to right to the inverse Polish expression to obtain the expression objects.
And the push operation unit is used for performing push operation according to the type of the expression object.
Specifically, the expression object includes an operand object, an operator object, and a function object.
(1) And if the expression object is an operand object, pushing the operand object to the third stack.
(2) And if the expression object is an operator object, popping an operand object corresponding to the operator object from the third stack, calculating according to the operand object and the operator object, and pressing the execution result into the third stack. Specifically, each operator object corresponds to a known operand object, for example, 2 operand objects are associated with the operator object "+". And determining the number of operand objects corresponding to the operator object to be popped from the third stack by acquiring the number of the operand objects corresponding to the operator object. And calculating an operation result corresponding to the operator object through the operand object popped from the third stack and the operator object, and then pressing the calculated operation result into the third stack.
(3) If the expression object is a function object, popping an operand object corresponding to the function object from the third stack, calculating according to the operand object and the function object, and pressing the execution result into the third stack.
Specifically, as can be seen from the foregoing embodiment, in the inverse wave-to-blue conversion process of the expression, the input parameter quantity corresponding to the input parameter in the function object is obtained, and the input parameter quantity is combined with the function object after being subjected to the labeling processing, so as to generate a labeled function object. Therefore, when the inverse Polish expression is executed, the number of operand objects corresponding to the function object which needs to be popped from the third stack can be determined by acquiring the number of entries corresponding to the marked function object.
For example, assuming that the function object in the inverse wave-blue expression is $ average [3], by obtaining the number of arguments corresponding to the function object, it can be obtained that the number of arguments corresponding to the function object is 3, and it is further determined that the number of operand objects corresponding to the function object needs to be popped from the third stack is 3.
In an embodiment of the present invention, the function object is $ average [3] for calculating the average of the operand objects. Assume that the three operand objects popped from the third stack are "a", "b", and "c", respectively. From the function objects and the operand objects, the average values of "a", "b" and "c" may be calculated and pushed onto the third stack.
And the expression judging unit is used for judging whether all expression objects of the inverse Polish expression are acquired.
And the result determining unit is used for determining the last execution result pressed into the third stack as the execution result of the inverse Polish expression if all the expression objects of the inverse Polish expression are obtained.
By implementing the embodiment of the invention, the expression is analyzed to obtain the expression correspondence and the type corresponding to the expression, then inverse Polish conversion is carried out according to the type of the expression object, and the generated inverse Polish expression is executed to generate the execution result. The recording form of the expression can be simplified, the recognition speed of the computer system to the expression is favorably improved, and the execution efficiency of the expression is improved.
The apparatus 10 described above may be implemented in the form of a computer program which may be run on a computer device as shown in fig. 11.
Referring to fig. 11, fig. 11 is a schematic block diagram of a computer device according to an embodiment of the present invention. The computer device 500 device may be a terminal. The terminal can be an electronic device with a communication function, 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, memory, and a network interface 550 coupled by a system bus 510, where the memory may include a non-volatile storage medium 530 and an internal memory 540.
The non-volatile storage medium 530 may store an operating system 531 and computer programs 532. The computer program 532, when executed, may cause the processor 520 to perform a method for automated testing of an interface.
The processor 520 is used to provide computing and control capabilities that support the operation of the overall computer device 500.
The internal memory 540 provides an environment for running a computer program in a non-volatile storage medium, which when executed by the processor 520, causes the processor 520 to perform a method for automated testing of an interface.
The network interface 550 is used for network communication such as sending assigned tasks and the like. It will be appreciated by those skilled in the art that the schematic block diagram of the computer device is only a partial block diagram of the structure associated with the inventive arrangements and does not constitute a limitation of the computer device 500 to which the inventive arrangements are applied, and that a particular computer device 500 may include more or less components than those shown, or combine certain components, or have a different arrangement of components.
Wherein the processor 520 is configured to run the program code stored in the memory to implement the following functions:
analyzing the expression to obtain an expression object in the expression;
acquiring the type of the expression object;
according to the type of the expression object, performing inverse Polish conversion on the expression to generate an inverse Polish expression;
executing the inverse Polish expression to generate an execution result.
In an embodiment, when the processor 520 performs the step of obtaining the type of the expression object, the following steps are specifically performed:
judging whether the expression object contains a preset function marker or not;
and if the expression object contains a preset function marker, determining the expression object as a function object.
In an embodiment, when the step of performing inverse-to-blue conversion on the expression according to the type of the expression object is executed, the processor 520 specifically executes the following steps:
initializing a preset first stack and a preset second stack;
performing stack pushing operation on the expression object according to the type of the expression object;
judging whether all the expressions are successfully analyzed;
if the expressions are all successfully analyzed, pressing the expression objects stored in the first stack into the second stack;
and popping the expression objects in the second stack in a reverse order to generate the reverse Polish expression.
In an embodiment, when the processor 520 executes the step of pushing and popping the expression object according to the type of the expression object, the following steps are specifically executed:
if the expression object is a function object, acquiring input parameters corresponding to the function object and input parameter quantity corresponding to the input parameters;
marking the input parameter quantity;
merging the marked input parameter number with the function object to generate a marked function object;
pushing the marker function object onto the first stack;
analyzing the input parameters in sequence to obtain the types of the input parameters;
and performing stack pushing operation on the input parameters according to the types of the input parameters.
In an embodiment, the types of the input parameters include an operand object and an operator object, and when the processor 520 performs the step of performing the push-pull operation on the input parameters according to the types of the input parameters, the following steps are specifically performed:
if the type of the input parameter is an operand object, pushing the operand object to the second stack;
if the type of the input parameter is an operator object, acquiring a first priority level corresponding to the operator object, and acquiring a second priority level corresponding to the operator object positioned at the top of the stack in the first stack;
judging whether the first priority level is lower than the second priority level;
popping the operator object at the top of the first stack from the first stack and pushing the operator object to the second stack if the first priority level is lower than the second priority level;
pushing the operator object onto the first stack if the first priority level is higher than the second priority level.
It should be understood that, in the embodiment of the present invention, the Processor 520 may be a Central Processing Unit (CPU), and the Processor 520 may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components, and the like. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Those skilled in the art will appreciate that the schematic block diagram of the computer device 500 does not constitute a limitation of the computer device 500 and may include more or less components than those shown, or some components in combination, or a different arrangement of components.
In another embodiment of the present invention, a computer-readable storage medium is provided that stores a computer program, wherein the computer program comprises program instructions. The program instructions when executed by a processor implement the steps of:
analyzing the expression to obtain an expression object in the expression;
acquiring the type of the expression object;
according to the type of the expression object, performing inverse Polish conversion on the expression to generate an inverse Polish expression;
executing the inverse Polish expression to generate an execution result.
In an embodiment, when the program instructions are executed by a processor to implement the step of obtaining the type of the expression object, the following steps are specifically implemented:
judging whether the expression object contains a preset function marker or not;
and if the expression object contains a preset function marker, determining the expression object as a function object.
In an embodiment, when the program instructions are executed by a processor to implement the step of performing inverse-to-blue conversion on the expression according to the type of the expression object, the following steps are specifically implemented:
initializing a preset first stack and a preset second stack;
performing stack pushing operation on the expression object according to the type of the expression object;
judging whether all the expressions are successfully analyzed;
if the expressions are all successfully analyzed, pressing the expression objects stored in the first stack into the second stack;
and popping the expression objects in the second stack in a reverse order to generate the reverse Polish expression.
In an embodiment, when the program instruction is executed by a processor to implement the step of performing the push-pull operation on the expression object according to the type of the expression object, the following steps are specifically implemented:
if the expression object is a function object, acquiring input parameters corresponding to the function object and input parameter quantity corresponding to the input parameters;
marking the input parameter quantity;
merging the marked input parameter number with the function object to generate a marked function object;
pushing the marker function object onto the first stack;
analyzing the input parameters in sequence to obtain the types of the input parameters;
and performing stack pushing operation on the input parameters according to the types of the input parameters.
In an embodiment, the type of the input parameter includes an operand object and an operator object, and when the program instruction is executed by the processor to implement the step of pushing and popping the input parameter according to the type of the input parameter, the following steps are specifically implemented:
if the type of the input parameter is an operand object, pushing the operand object to the second stack;
if the type of the input parameter is an operator object, acquiring a first priority level corresponding to the operator object, and acquiring a second priority level corresponding to the operator object positioned at the top of the stack in the first stack;
judging whether the first priority level is lower than the second priority level;
popping the operator object at the top of the first stack from the first stack and pushing the operator object to the second stack if the first priority level is lower than the second priority level;
pushing the operator object onto the first stack if the first priority level is higher than the second priority level.
The computer readable storage medium may be various media that can store program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk, or an optical disk.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative. For example, the division of each unit is only one logic function division, and there may be another division manner in actual implementation. For example, more than one unit or component may be combined or may be integrated into another system, or some features may be omitted, or not implemented.
The steps in the method of the embodiment of the invention can be sequentially adjusted, combined and deleted according to actual needs. The units in the device of the embodiment of the invention can be merged, divided and deleted according to actual needs.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention essentially or partially contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a terminal, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (8)

1. An expression processing method, comprising:
analyzing the expression to obtain an expression object in the expression;
acquiring the type of the expression object;
according to the type of the expression object, performing inverse Polish conversion on the expression to generate an inverse Polish expression;
executing the inverse Polish expression to generate an execution result;
the inverse Polish converting the expression according to the type of the expression object includes:
initializing a preset first stack and a preset second stack;
performing stack pushing operation on the expression object according to the type of the expression object;
judging whether all the expressions are successfully analyzed;
if the expressions are all successfully analyzed, pressing the expression objects stored in the first stack into the second stack;
and popping the expression objects in the second stack in a reverse order to generate the reverse Polish expression.
2. The method of claim 1, wherein said obtaining the type of the expression object comprises:
judging whether the expression object contains a preset function marker or not;
and if the expression object contains a preset function marker, determining the expression object as a function object.
3. The method of claim 1, wherein said pushing the expression object according to the type of the expression object comprises:
if the expression object is a function object, acquiring input parameters corresponding to the function object and input parameter quantity corresponding to the input parameters;
marking the input parameter quantity;
merging the marked input parameter number with the function object to generate a marked function object;
pushing the marker function object onto the first stack;
analyzing the input parameters in sequence to obtain the types of the input parameters;
and performing stack pushing operation on the input parameters according to the types of the input parameters.
4. The method of claim 3, wherein the types of input parameters include an operand object and an operator object, and wherein the pushing the input parameters according to the types of input parameters comprises:
if the type of the input parameter is an operand object, pushing the operand object to the second stack;
if the type of the input parameter is an operator object, acquiring a first priority level corresponding to the operator object, and acquiring a second priority level corresponding to the operator object positioned at the top of the stack in the first stack;
judging whether the first priority level is lower than the second priority level;
popping the operator object at the top of the first stack from the first stack and pushing the operator object to the second stack if the first priority level is lower than the second priority level;
pushing the operator object onto the first stack if the first priority level is higher than the second priority level.
5. An expression processing apparatus, comprising:
the object acquisition unit is used for analyzing the expression to acquire an expression object in the expression;
the type acquisition unit is used for acquiring the type of the expression object;
the conversion unit is used for carrying out inverse Polish conversion on the expression according to the type of the expression object so as to generate an inverse Polish expression;
an execution unit for executing the inverse Polish expression to generate an execution result;
the conversion unit includes:
the device comprises an initialization unit, a first stacking unit and a second stacking unit, wherein the initialization unit is used for a preset first stack and a preset second stack;
the second processing unit is used for performing stack pushing operation on the expression object according to the type of the expression object;
the second judgment unit is used for judging whether all the expressions are successfully analyzed;
the third processing unit is used for pressing the expression object stored in the first stack into the second stack if the expressions are all successfully analyzed;
and the first generation unit is used for popping up the expression objects in the second stack in a reverse order so as to generate the inverse Polish expression.
6. The apparatus of claim 5, wherein the type obtaining unit comprises:
the first judgment unit is used for judging whether the expression object contains a preset function marker;
the first processing unit is used for determining the expression object as a function object if the expression object contains a preset function marker.
7. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the expression processing method according to any one of claims 1 to 4 when executing the program.
8. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program comprising program instructions that, when executed by a processor, cause the processor to execute the expression processing method according to any one of claims 1 to 4.
CN201810175368.XA 2018-03-02 2018-03-02 Expression processing method, device, equipment and computer readable storage medium Active CN108491207B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201810175368.XA CN108491207B (en) 2018-03-02 2018-03-02 Expression processing method, device, equipment and computer readable storage medium
PCT/CN2018/085277 WO2019165706A1 (en) 2018-03-02 2018-05-02 Expression processing method, apparatus, device, and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810175368.XA CN108491207B (en) 2018-03-02 2018-03-02 Expression processing method, device, equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN108491207A CN108491207A (en) 2018-09-04
CN108491207B true CN108491207B (en) 2020-11-17

Family

ID=63341365

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810175368.XA Active CN108491207B (en) 2018-03-02 2018-03-02 Expression processing method, device, equipment and computer readable storage medium

Country Status (2)

Country Link
CN (1) CN108491207B (en)
WO (1) WO2019165706A1 (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
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
CN111767004B (en) * 2020-06-30 2022-02-11 电子科技大学 Digital oscilloscope mathematical operation processing method based on inverse Polish algorithm

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103440331A (en) * 2013-09-05 2013-12-11 五八同城信息技术有限公司 Reverse Polish and multi-way tree-based search engine query statement analyzing method
CN106648753A (en) * 2016-11-23 2017-05-10 北京航天自动控制研究所 Automatic criterion analysis method based on reverse Polish notation algorithm

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPS6073731A (en) * 1983-09-29 1985-04-25 Fujitsu Ltd Processing system of logical operator
CN100389565C (en) * 2005-03-08 2008-05-21 华为技术有限公司 Analytic method of expression type
CN100437587C (en) * 2006-12-31 2008-11-26 华为技术有限公司 Service processing method and device based on data base
CN102779044B (en) * 2012-06-28 2016-01-20 用友软件股份有限公司 The dissection process system of expression formula and analyzing and processing method
CN103023766A (en) * 2012-11-23 2013-04-03 山东电力集团公司 Dynamic routing method based on expression judgment
CN106649212A (en) * 2016-09-12 2017-05-10 济南浪潮高新科技投资发展有限公司 Business data processing method and device
CN107092656B (en) * 2017-03-23 2019-12-03 中国科学院计算技术研究所 A kind of tree data processing method and system

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103440331A (en) * 2013-09-05 2013-12-11 五八同城信息技术有限公司 Reverse Polish and multi-way tree-based search engine query statement analyzing method
CN106648753A (en) * 2016-11-23 2017-05-10 北京航天自动控制研究所 Automatic criterion analysis method based on reverse Polish notation algorithm

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
中缀算术表达式的轻量化求值算法;白宇等;《计算机应用》;20131101(第11期);全文 *

Also Published As

Publication number Publication date
WO2019165706A1 (en) 2019-09-06
CN108491207A (en) 2018-09-04

Similar Documents

Publication Publication Date Title
CN108491207B (en) Expression processing method, device, equipment and computer readable storage medium
US8347272B2 (en) Call graph dependency extraction by static source code analysis
CN110968325B (en) Applet conversion method and device
CN112394942B (en) Distributed software development compiling method and software development platform based on cloud computing
CN109947431B (en) Code generation method, device, equipment and storage medium
CN111767056A (en) Source code compiling method, executable file running method and terminal equipment
US7428729B2 (en) Methods, systems, and computer program products for integrating legacy applications into a platform-independent environment
CN110659210A (en) Information acquisition method and device, electronic equipment and storage medium
CN114911541B (en) Processing method and device of configuration information, electronic equipment and storage medium
CN111258802A (en) Method for capturing application program crash information and related equipment
CN116009852A (en) Code construction method, device, computer equipment and storage medium
CN114047915B (en) Configuration application display method and device, electronic equipment and storage medium
CN113721928B (en) Binary analysis-based dynamic library clipping method
CN111273913B (en) Method and device for outputting application program interface data represented by specifications
CN114220550A (en) Single disease reporting general method and device, electronic equipment and storage medium
WO2018116522A1 (en) Determination device, determination method, and determination program
US9280441B2 (en) Detection and correction of race conditions in workflows
US11604718B1 (en) Profiling by unwinding stacks from kernel space using exception handling data
CN115951936B (en) Chip adaptation method, device, equipment and medium of vectorization compiler
CN113296834B (en) Android closed source service type information extraction method based on reverse engineering
CN117075912B (en) Method for program language conversion, compiling method and related equipment
CN110879722B (en) Method and device for generating logic schematic diagram and computer storage medium
CN113986346A (en) Analysis method and device for Dubbo interface implementation class
CN117112073A (en) Exception handling method, device, equipment and medium
CN113971028A (en) Data processing method, device, equipment, storage medium and computer program product

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant