0 7
Priority level |
0 |
1 |
2 |
3 4 5) 6 7 |
Operator |
# |
( |
, |
+- */ @~ !%^ ) |
Description |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
First, generate inverse Polish expressions
First build a memory , another symbol stack , storage is left-to-right storage data, and the symbol stack adhere to the principle of LIFO, the calculation of the expression in order from left to right scan.
* read into a data (note: Numeric and function names are not single characters, need to be judged)
1. If the Zodan operator or function name, directly into the symbol stack, such as the sign ~ @ Max sin
2. If the right single-eye operator, directly into the memory stack, such as factorial! % with percent percent
3. If it is traffic, write directly to the memory, check whether the top of the symbol stack has a single-eye operator, and some words are all out of the stack, and write to the memory;
4. If the opening parenthesis "(", then directly into the symbol stack;
5.  Span style= "line-height:1.5;" > ")" ( Span style= "line-height:1.5;" >)
6. If the binocular operator, then the stack top symbol priority, if it is greater than the top of the stack, then the stack top symbol and write to the memory, until the top of the stack of the operation priority of the symbol;
7 . If the function parameter is concatenated with a comma "," the symbol stack data pops up until a left parenthesis ( or comma ) is encountered, and then the comma , into the symbol stack;
8 . If it is terminator (indicating that the expression has been read all), the symbol stack pops up and writes to the memory, otherwise continues to read the next data according to the above rules;
The inverse Polish-style generation process is described in steps below:
The expression is scanned from left to right and the characters marked red are the characters scanned for the current step:
0 to an expression End identifier " #
the post-processing expression is: the ( 8+4^2 ) *3#
1,2+(8+4^2)*3#:Scan "2", by rule3, the calculation amount2Press into the memory as follows:
Memory
Symbol stack: Temporary space
2,2+ (8+4^2)*3#:Scan "+", by rule6, press the plus sign into the symbol stack , as follows:
This article is from the "11486263" blog, please be sure to keep this source http://11496263.blog.51cto.com/11486263/1783907
Inverse Polish algorithm