evaluator class the evaluator class manages two stacks one stack records pending operators ( +)and one records pending operands ( temporary results are computed as new operators are sent from calcgui and pushed onto the operands stack as you can see from thisthe magic of expression evaluation boils down to juggling the operator and operand stacks in sensethe calculator implements little stack-based languageto evaluate the expressions being entered while scanning expression strings from left to right as they are enteredoperands are pushed along the waybut operators delimit operands and may trigger temporary results before they are pushed because it records states and performs transitionssome might use the term state machine to describe this calculator language implementation here' the general scenario when new operator is seen ( when an operator button or key is pressed)the prior operand in the entry field is pushed onto the operands stack the operator is then added to the operators stackbut only after all pending operators of higher precedence have been popped and applied to pending operands ( pressing makes any pending operators on the stack fire when "evalis pressedall remaining operators are popped and applied to all remaining operandsand the result is the last remaining value on the operands stack in the endthe last value on the operands stack is displayed in the calculator' entry fieldready for use in another operation this evaluation algorithm is probably best described by working through examples let' step through the entry of few expressions and watch the evaluation stacks grow pycalc stack tracing is enabled with the debugme flag in the moduleif truethe operator and operand stacks are displayed on stdout each time the evaluator class is about to apply an operator and reduce (popthe stacks run pycalc with console window to see the traces tuple holding the stack lists (operators operandsis printed on each stack reductiontops of stacks are at the ends of the lists for instancehere is the console output after typing and evaluating simple string entered keys" [result (['*'][' '' '](['+'][' '' '][on '+pressdisplays " "[on 'evalpressdisplays " "note that the pending (stackedsubexpression is evaluated when the is pressedoperators bind tighter than +so the code is evaluated immediately before the operator is pushed when the button is pressedthe entry field contains we push onto the operands stackreduce the subexpression ( )push its result onto operandspush text and language