CMPSCI 187: Programming With Data Structures

David Mix Barrington

Fall, 2011

Discussion Assignment #3: Playing with the Postfix Evaluator

28 September 2011

Last Monday in lecture we reviewed the postfix evaluator from Section 3.5 of L&C. Today we will play with translating and evaluating postfix expressions.

Question 1:

The first set of questions asks you to evaluate some postfix expressions. Some are valid and some are not -- identify which ones are invalid and why, and evaluate the valid ones:

Question 2:

Translate the valid postfix expressions from Question 1 into infix expressions.

Question 3:

Next we will translate some infix expressions into postfix. (If you have time, evaluate these as well.) Remember the rule -- find the operator to be executed lasst, consider the infix experession as "R op S", translate R to R' and S to S' by the same rule, then write "R' S' op".

Question 4:

Every valid postfix expression has one more number than it has operators -- explain why.

Question 5:

An expression with k operators and k+1 numbers (and no parentheses) may or may not be a valid postfix expression. How can you tell?

Last modified 29 September 2011