Infix To Postfix
Infix To Postfix
ON
V.Radhesyam
Assistant professor
Department of IT:VRSEC
Expressions
What is an expression?
An expression is a legal combination of operands and
operators.
(A+B)-C
(4/5)*(10+6)
Operands means
variable like x,y,z or constant like 5,4,0,2
Operator means
symbol like +,,*,/ used with operands.
Radhesyam.V 2
Expression representation
Radhesyam.V 3
Examples
Radhesyam.V 4
Components needed
Radhesyam.V 5
Rules to Convert Infix to Postfix
Expression
When the token is operand add it to the end of output
A left parenthesis: Push it onto the stack
A right parenthesis: Pop and display stack element until
a left parenthesis is encountered. And discard pair of parenthesis
If Stack is empty or incoming symbol has high precedence than
TOS :push it on to the Stack.
If incoming symbol has low precedence (equal) than TOS :Pop the
stack and TOS.
A left parenthesis in the stack is assumed to have lower priority
than that of operators
Radhesyam.V 6
Precedence
Radhesyam.V 7
Infix to postfix conversion
infixVect
(a+b-c)*d–(e+f)
postfixVect
Radhesyam.V
Infix to postfix conversion
infixVect
a+b-c)*d–(e+f)
postfixVect
( stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
+b-c)*d–(e+f)
postfixVect
a
( stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
b-c)*d–(e+f)
postfixVect
a
+
( stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
-c)*d–(e+f)
postfixVect
ab
+
( stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
c)*d–(e+f)
postfixVect
ab+
-
( stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
)*d–(e+f)
postfixVect
ab+c
-
( stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
*d–(e+f)
postfixVect
ab+c-
stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
d–(e+f)
postfixVect
ab+c-
* stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
–(e+f)
postfixVect
ab+c-d
* stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
(e+f)
postfixVect
ab+c–d*
- stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
e+f)
postfixVect
ab+c–d*
(
- stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
+f)
postfixVect
ab+c–d*e
(
- stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
f)
postfixVect
+ ab+c–d*e
(
- stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
)
postfixVect
+ ab+c–d*ef
(
- stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
postfixVect
ab+c–d*ef+
- stackVect
Radhesyam.V
Infix to postfix conversion
infixVect
postfixVect
ab+c–d*ef+-
stackVect
Radhesyam.V