SlideShare a Scribd company logo
9
Most read
14
Most read
16
Most read
Arithmetic Expression –
INFIX TO POSTFIX
SARASWATHI RAMALINGAM
SRI AKILANDESWARI WOMENS
COLLEGE – WANDIWASH.
Arithmetic Expression
• Arithmetic Expression contains
– Operators (+,-,*,/,%,() )
– Operands (a..z)
– Ex:- (a*b),(a+b)-c
Classification of Expression
– Depending upon the position of the
operators with respect to the position of
the operands.
– Infix
– Prefix
– Postfix
Classification of Expression
INFIX PREFIX POSTFIX
Operator In between the
operands
Operator before the
operands
Operator after the
operands
Infix notation Prefix notation(Polish
notation)
Postfix notation(Reverse
Polish notation)
A+B +AB AB+
A+B*C +A*BC ABC*+
(A+B)*(C-D) *+AB-CD AB+CD-*
INFIX TO POSTFIX
• Conversion of Expression
• Evaluation of Postfix Expression
Conversion of Expression
• Steps
– Initialize an empty stack.
– Read the token from Infix string one at a
time from left to right.
Conversion of Expression
– If the scanned character is an operand
add it to the Postfix string.
– If the scanned character is an operator
• if the stack is empty push the character to
stack.
• If the stack is not empty, compare the
precedence of the character with element on
top of the stack.
Conversion of Expression
– If the character is a left parentheses,
push it on to the stack.
– If the character is a right parentheses,
• Repeatedly pop the stack and add popped out
element in to the string until a left
parentheses is encountered.
• Remove the left parentheses from the stack
and ignore it.
Conversion of Expression
• When top Stack has higher precedence over
the scanned character pop the stack else
push the scanned character to stack.
– (Repeat the step until the operator in the stack
has higher precedence than the scanned
character)
• After all the characters are read and the
stack is not empty then pop the stack and
add the string.
Example
A+B
1.
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
2
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
+ + A
3
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
+ + A
B + AB
AB+
Example
A+B*C
1.
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
2
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
+ + A
3
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
+ + A
B + AB
4
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
+ + A
B + AB
* +* AB
5
SYMBOL SCANNED STACK POSTFIX EXPRESSION
A A
+ + A
B + AB
* +* AB
C +* ABC
ABC*+

More Related Content

PDF
Solve the problem showing all steps. Thoroughly explain how and why you perfo...
PPTX
stack
PPTX
Infix to postfix conversion
PPTX
Stack and queue -polish notations
PDF
Topdown parsing
PDF
Applications of stack
PPT
Conversion of Infix To Postfix Expressions
PPTX
Labreportofai
Solve the problem showing all steps. Thoroughly explain how and why you perfo...
stack
Infix to postfix conversion
Stack and queue -polish notations
Topdown parsing
Applications of stack
Conversion of Infix To Postfix Expressions
Labreportofai

What's hot (19)

PDF
Assignment6
PPTX
LL(1) parsing
PPTX
Lecture 07 08 syntax analysis-4
PDF
Lecture9 syntax analysis_5
PDF
Lecture7 syntax analysis_3
PDF
Assignment8
PPTX
Polish
PDF
Lecture10 syntax analysis_6
PPT
Ll(1) Parser in Compilers
PPTX
3 operators-expressions-and-statements-120712073351-phpapp01
PDF
Lecture8 syntax analysis_4
PPTX
03. operators and-expressions
PDF
Lesson 5 .1 selection structure
DOC
Pcd(Mca)
PDF
Lesson 4.2 5th and 6th step
PPTX
Compiler: Syntax Analysis
PDF
Lesson 4.1 completing the problem solving process
PPTX
Stack application
PPTX
Assignment6
LL(1) parsing
Lecture 07 08 syntax analysis-4
Lecture9 syntax analysis_5
Lecture7 syntax analysis_3
Assignment8
Polish
Lecture10 syntax analysis_6
Ll(1) Parser in Compilers
3 operators-expressions-and-statements-120712073351-phpapp01
Lecture8 syntax analysis_4
03. operators and-expressions
Lesson 5 .1 selection structure
Pcd(Mca)
Lesson 4.2 5th and 6th step
Compiler: Syntax Analysis
Lesson 4.1 completing the problem solving process
Stack application
Ad

Similar to Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam (20)

PPTX
Unit 2 application of stack
PPTX
infix,postfix,prefixavabanwnwnwjjjj.pptx
PPTX
Polish Notation In Data Structure
PPTX
Data structures (Infix, Prefix and Postfix notations).pptx
PPTX
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
PDF
Infix to Postfix Conversion.pdf
PPTX
UNIT_I_LEC for subject fds unit 1 vu_V.pptx
PPTX
week9-prefixinfixandpostfixnotations-191013065821.pptx
PPTX
infixtopostfixconversion-110304220159-phpapp01.pptx
PPT
Arithmetic notation conversion infix to1
PPT
Unit IV-infix to postfix and eval.ppt dsa
PPT
MO 2020 DS Stacks 3 AB.ppt
PPTX
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
PPTX
Stack application in infix to prefix expression
PPTX
data structure stack appplication in python
PPTX
Prefix, Infix and Post-fix Notations
PPT
Infix to Postfix Conversion Using Stack
PPTX
Infix to postfix
PDF
The concept of stack is extremely important in computer science and .pdf
Unit 2 application of stack
infix,postfix,prefixavabanwnwnwjjjj.pptx
Polish Notation In Data Structure
Data structures (Infix, Prefix and Postfix notations).pptx
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
Infix to Postfix Conversion.pdf
UNIT_I_LEC for subject fds unit 1 vu_V.pptx
week9-prefixinfixandpostfixnotations-191013065821.pptx
infixtopostfixconversion-110304220159-phpapp01.pptx
Arithmetic notation conversion infix to1
Unit IV-infix to postfix and eval.ppt dsa
MO 2020 DS Stacks 3 AB.ppt
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
Stack application in infix to prefix expression
data structure stack appplication in python
Prefix, Infix and Post-fix Notations
Infix to Postfix Conversion Using Stack
Infix to postfix
The concept of stack is extremely important in computer science and .pdf
Ad

More from SaraswathiRamalingam (20)

PPTX
PPTX
XSL - XML STYLE SHEET
PPTX
PPTX
PPTX
XML DTD DOCUMENT TYPE DEFINITION
PPTX
Georg scheutz - Charles babbage - Saraswathi Ramalingam
PPTX
Dennis ritchie - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PPTX
LAB PROGRAMS SARASWATHI RAMALINGAM
PPTX
C PROGRAMS - SARASWATHI RAMALINGAM
XSL - XML STYLE SHEET
XML DTD DOCUMENT TYPE DEFINITION
Georg scheutz - Charles babbage - Saraswathi Ramalingam
Dennis ritchie - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAM
C PROGRAMS - SARASWATHI RAMALINGAM

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Lesson notes of climatology university.
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Types and Its function , kingdom of life
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Final Presentation General Medicine 03-08-2024.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Weekly quiz Compilation Jan -July 25.pdf
Anesthesia in Laparoscopic Surgery in India
Final Presentation General Medicine 03-08-2024.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
VCE English Exam - Section C Student Revision Booklet
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Lesson notes of climatology university.
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
human mycosis Human fungal infections are called human mycosis..pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Types and Its function , kingdom of life
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf

Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam

  • 1. Arithmetic Expression – INFIX TO POSTFIX SARASWATHI RAMALINGAM SRI AKILANDESWARI WOMENS COLLEGE – WANDIWASH.
  • 2. Arithmetic Expression • Arithmetic Expression contains – Operators (+,-,*,/,%,() ) – Operands (a..z) – Ex:- (a*b),(a+b)-c
  • 3. Classification of Expression – Depending upon the position of the operators with respect to the position of the operands. – Infix – Prefix – Postfix
  • 4. Classification of Expression INFIX PREFIX POSTFIX Operator In between the operands Operator before the operands Operator after the operands Infix notation Prefix notation(Polish notation) Postfix notation(Reverse Polish notation) A+B +AB AB+ A+B*C +A*BC ABC*+ (A+B)*(C-D) *+AB-CD AB+CD-*
  • 5. INFIX TO POSTFIX • Conversion of Expression • Evaluation of Postfix Expression
  • 6. Conversion of Expression • Steps – Initialize an empty stack. – Read the token from Infix string one at a time from left to right.
  • 7. Conversion of Expression – If the scanned character is an operand add it to the Postfix string. – If the scanned character is an operator • if the stack is empty push the character to stack. • If the stack is not empty, compare the precedence of the character with element on top of the stack.
  • 8. Conversion of Expression – If the character is a left parentheses, push it on to the stack. – If the character is a right parentheses, • Repeatedly pop the stack and add popped out element in to the string until a left parentheses is encountered. • Remove the left parentheses from the stack and ignore it.
  • 9. Conversion of Expression • When top Stack has higher precedence over the scanned character pop the stack else push the scanned character to stack. – (Repeat the step until the operator in the stack has higher precedence than the scanned character) • After all the characters are read and the stack is not empty then pop the stack and add the string.
  • 10. Example A+B 1. SYMBOL SCANNED STACK POSTFIX EXPRESSION A A
  • 11. 2 SYMBOL SCANNED STACK POSTFIX EXPRESSION A A + + A
  • 12. 3 SYMBOL SCANNED STACK POSTFIX EXPRESSION A A + + A B + AB AB+
  • 13. Example A+B*C 1. SYMBOL SCANNED STACK POSTFIX EXPRESSION A A
  • 14. 2 SYMBOL SCANNED STACK POSTFIX EXPRESSION A A + + A
  • 15. 3 SYMBOL SCANNED STACK POSTFIX EXPRESSION A A + + A B + AB
  • 16. 4 SYMBOL SCANNED STACK POSTFIX EXPRESSION A A + + A B + AB * +* AB
  • 17. 5 SYMBOL SCANNED STACK POSTFIX EXPRESSION A A + + A B + AB * +* AB C +* ABC ABC*+