Week 5 (Semantics) Activity
Consider the C code below. Describe the program state after each line is executed. Then convert each expression to postfix notation. Use the precedence table in the textbook (pp. 43-44).
Refresh the page to get a new set of expressions.
- b-- and b++ both evaluate to b, but then change the value of b
- The increment and decrement operations could happen at any time during the evaluation of the expression after they have returned their value. For any expression that makes use of increment or decrement, you should give all possible values.
- Boolean operators return 0 for False and 1 for True
- To get postfix from infix, draw an expression tree and then do a postorder traversal of the tree
- When drawing expression trees, unary operators like ++ or -- has only one child.
- When generating postfix notation, a unary operator like ++ or -- applies to the one operand that precedes it (e.g. "
a++-b++" becomes "
a ++ b ++ -").
- Don't forget that = is an operator too.