SlideShare uma empresa Scribd logo
1 de 7
Reverse
Polish
Notation
BEDMAS
BIDMAS
BODMAS
PEMDAS
6,2/1,2+*
                *
    /                     +
6       2           1          2
            /           6,2,1,2,+*/

                    *
                         +

6       2           1         2
Evaluating RPN
• Uses a stack and two simple rules. Reading
  left to right …….
• 1. If a value appears next in the
  expression, push this value on to the stack.
• 2. If an operator appears next, pop two items
  from the top of the stack and push the result
  of the operation on to the stack.
Reverse Polish Notation Examples

    7,4+3-        7+4-3

    1,2*3+        1*2+3

    1,2+3*        (1+2) *3

    5,9,2*+       5+9*2

    1,2*3,4*+     1*2+3*4
Converting from infix to postfix
         ‘Shunting yard algorithm’

• Read each character                  • Calculator - another
• If its an operand, add it to
  the output
• If it’s an operator then
   – If there’s a higher BODMAS
     priority operator at the top of
     the stack, pop it
   – Push it on the stack
• At the end, pop everything
  off the operator stack
Reverse polish notation

Mais conteúdo relacionado

Mais procurados

Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary treeKrish_ver2
 
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYDATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1Shashwat Shriparv
 
Instruction Formats
Instruction FormatsInstruction Formats
Instruction FormatsRaaviKapoor
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of treeSiddhi Viradiya
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular setsSampath Kumar S
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxAlbin562191
 
Data Representation of Strings
Data Representation of StringsData Representation of Strings
Data Representation of StringsProf Ansari
 
Floating point arithmetic operations (1)
Floating point arithmetic operations (1)Floating point arithmetic operations (1)
Floating point arithmetic operations (1)cs19club
 

Mais procurados (20)

Expression trees
Expression treesExpression trees
Expression trees
 
Instruction format
Instruction formatInstruction format
Instruction format
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Shift reduce parser
Shift reduce parserShift reduce parser
Shift reduce parser
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDYDATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
DATA STRUCTURES AND ALGORITHMS UNIT-3 TREES PREPARED BY M V BRAHMANANDA REDDY
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Instruction Formats
Instruction FormatsInstruction Formats
Instruction Formats
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Array
ArrayArray
Array
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
Data Representation of Strings
Data Representation of StringsData Representation of Strings
Data Representation of Strings
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Floating point arithmetic operations (1)
Floating point arithmetic operations (1)Floating point arithmetic operations (1)
Floating point arithmetic operations (1)
 

Mais de grahamwell

Excel =if function
Excel =if functionExcel =if function
Excel =if functiongrahamwell
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average grahamwell
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?grahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch developgrahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch developgrahamwell
 
The software story
The software storyThe software story
The software storygrahamwell
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphicsgrahamwell
 
Database field types
Database field typesDatabase field types
Database field typesgrahamwell
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and typesgrahamwell
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and typesgrahamwell
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9grahamwell
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your projectgrahamwell
 
The rail fence
The rail fenceThe rail fence
The rail fencegrahamwell
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryptiongrahamwell
 
Server side scripts
Server side scriptsServer side scripts
Server side scriptsgrahamwell
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and controlgrahamwell
 

Mais de grahamwell (20)

Pseudocode
PseudocodePseudocode
Pseudocode
 
Excel =if function
Excel =if functionExcel =if function
Excel =if function
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
The software story
The software storyThe software story
The software story
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphics
 
Database field types
Database field typesDatabase field types
Database field types
 
Databases 101
Databases 101Databases 101
Databases 101
 
Kodu controls
Kodu controlsKodu controls
Kodu controls
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and types
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and types
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your project
 
The rail fence
The rail fenceThe rail fence
The rail fence
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryption
 
Server side scripts
Server side scriptsServer side scripts
Server side scripts
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and control
 

Reverse polish notation

  • 3. 6,2/1,2+* * / + 6 2 1 2 / 6,2,1,2,+*/ * + 6 2 1 2
  • 4. Evaluating RPN • Uses a stack and two simple rules. Reading left to right ……. • 1. If a value appears next in the expression, push this value on to the stack. • 2. If an operator appears next, pop two items from the top of the stack and push the result of the operation on to the stack.
  • 5. Reverse Polish Notation Examples 7,4+3- 7+4-3 1,2*3+ 1*2+3 1,2+3* (1+2) *3 5,9,2*+ 5+9*2 1,2*3,4*+ 1*2+3*4
  • 6. Converting from infix to postfix ‘Shunting yard algorithm’ • Read each character • Calculator - another • If its an operand, add it to the output • If it’s an operator then – If there’s a higher BODMAS priority operator at the top of the stack, pop it – Push it on the stack • At the end, pop everything off the operator stack