50 likes | 184 Vues
This document explores the evaluation of Polish notation expressions, focusing on the translation from infix to Polish format. It covers the process of creating an interactive expression evaluator based on the principles outlined in Kruse/Ryba Chapter 13. The key steps include evaluating the left and right subtrees of expression trees, performing operations, and handling various token types. Highlighting the importance of object-oriented data structures, the text provides a framework to systematically evaluate complex expressions efficiently.
E N D
Object Oriented Data Structures The Polish Notation The IdeaEvaluation of Polish ExpressionsTranslation form Infix to PolishInteractive Expression Evaluator Kruse/Ryba ch13
Expression Trees • Evaluate the left subtree • Evaluate the right subtree • Perform the operator Kruse/Ryba ch13
:= / x x + a - 2 b 0.5 - x b 2 c x a 4 Kruse/Ryba ch13
Error_code Expression::evaluate_prefix(Value & result){ Token t; Value the_argument, first_argument, second_argument; if( (get_token(t) ==fail) return fail; switch (t.kind() ) { case unaryop: if(evaluate_prefix(the_argument) == fail) return fail; else result = do_unary(t, the_argument); break; case binaryop: if(evaluate_prefix(first_argument) == fail) return fail; if(evaluate_prefix(second_argument) == fail) return fail; else result = do_binary(t, first_argument, second_argument); break; case operand: result = get_value(t); break; } return success Kruse/Ryba ch13
Thus Ends Chapter 13and the Book Kruse/Ryba ch13