SlideShare a Scribd company logo
1 of 5
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

More Related Content

More from grahamwell

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
 
Gm names n stuff
Gm   names n stuffGm   names n stuff
Gm names n stuffgrahamwell
 
Reverse polish notation
Reverse polish notationReverse polish notation
Reverse polish notationgrahamwell
 
Protocol layers
Protocol layersProtocol layers
Protocol layersgrahamwell
 

More from grahamwell (20)

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
 
Mtslesson
MtslessonMtslesson
Mtslesson
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Gm names n stuff
Gm   names n stuffGm   names n stuff
Gm names n stuff
 
Reverse polish notation
Reverse polish notationReverse polish notation
Reverse polish notation
 
Shunting yard
Shunting yardShunting yard
Shunting yard
 
Protocol layers
Protocol layersProtocol layers
Protocol layers
 

Reverse polish notation

  • 2. 6,2/1,2+* * / + 6 2 1 2 / 6,2,1,2,+*/ * + 6 2 1 2
  • 3. 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.
  • 4. 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
  • 5. 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