1 / 7

Reverse Polish Notation

Reverse Polish Notation. Post-fix / Post-order. *. +. -. A. B. C. D. Doesn’t need brackets Completely unambiguous Simple to code using stack model HP Calculator. Infix vs Postfix. Match-o-matic. AB+C-D*E/F*G+. A+B/C*D-E*(F+G). AB*C*D+E-FG/+. A-B+C/D*(E+F)*G. AB/CD*+E-FG*+.

tamah
Télécharger la présentation

Reverse Polish Notation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Reverse Polish Notation

  2. Post-fix / Post-order * + - A B C D

  3. Doesn’t need brackets Completely unambiguous Simple to code using stack model HP Calculator Infix vs Postfix

  4. Match-o-matic AB+C-D*E/F*G+ A+B/C*D-E*(F+G) AB*C*D+E-FG/+ A-B+C/D*(E+F)*G AB/CD*+E-FG*+ A/B+C*D-E+F*G AB-CD/EF+*G*+ (A+B-C)*D/E*F+G AB+CD*+EF*G/- A*B*C+D-E+F/G (A+B+C*D)-(E*F/G) ABC/D*+EFG+*-

  5. Challenge • Write rules (pseudocode) for converting postfix to prefix

  6. Infix to Postfix conversion (manual) • An Infix to Postfix manual conversion algorithm is: 1. Completely parenthesize the infix expression according to order of priority you want. 2. Move each operator to its corresponding right parenthesis. 3. Remove all parentheses. • Examples: 3 + 4 * 5 (3 + (4 * 5) ) 3 4 5 * + a / b ^ c – d * e – a * c ^ 3 ^ 4 a b c ^ / d e * a c 3 4 ^ ^ * - - ((a / (b ^ c)) – ((d * e) – (a * (c ^ (3 ^ 4) ) ) ) ) Using normal mathematical operator precedence Not using normal mathematical operator precedence

  7. Infix to Prefix conversion (manual) • An Infix to Postfix manual conversion algorithm is: 1 Completely parenthesize the infix expression according to order of priority you want. 2 Move each operator to its corresponding left parenthesis. 3 Remove all parentheses. • Examples: 3 + 4 * 5 (3 + (4 * 5) ) 3 4 5 * + a / b ^ c – d * e – a * c ^ 3 ^ 4 a b c ^ / d e * a c 3 4 ^ ^ * - - ( (a / (b ^ c)) – ( (d * e) – (a * (c ^ (3 ^ 4) ) ) ) ) Using normal mathematical operator precedence Not using normal mathematical operator precedence

More Related