c4u.net.in

Polish mathematician ** Lukasiewicz** was the first to propose that the arithmatic expressions can be written in some different ways as well. His proposals were:

The detailing of arithmatic notations are as follows:

### Infix

### Prefix

### Postfix

The operator resides in between two adjacent operands. This in in accordance that an entire expression (if in bracket), is an like an operand. __Ex: A + B__

The operator resides immediately before the two continuous operands. __Ex: + A B__

The operator resides immediately after two continuous operands. __Ex: A B +__

The translation works in a specific manner. We use two registers and a stack here. The registers are to store infix and postfix expressions respectively while the stack for storing operators as encountered during translation. The detailed algorithm is as follows:

- Store the infix expression in register R1 and use R2 for storing postfix notation as we build it.
- From Left to Right, extract an element of R1 and do the following:
- If it is an operand, append it into the register R2.
- Else if it is an operator, do the following:
- If the stack is empty, PUSH it onto the stack.
- Else if the precedence of this operator is higher than the operator on TOS, PUSH it on to the stack.
- Else if the precedence of this operator is lower than the operator on TOS, POP the TOS, append in R2 and goto step b.
- Else if the precedence of this operator is equal to the TOS, POP the TOS append in R2 and goto step b.
- Else if it is an opening paranthesis PUSH it on to the stack, start a new stack hierarchy untill an closing paranthesis is found and goto step 2.
- Else if it is a closing paranthesis, POP every operator on stack untill the opening paranthesis is found.
- Else if reached on End of Expression, POP every operator remaining on the stack and append in R2.
- End of algorithm.