Homework 8

22C:18, Spring 1996

Due Tuesday Apr. 9, 1996 in discussion

Douglas W. Jones
This assignment forces you to do advanced work on the calculator problem from MP5 and to do advanced work in preparation for the final assignment.
  1. Consider the following input lines for the calculator. For each line that is valid, what output do you expect? For each line that is not valid, describe the nature of the errors:
    1. P(5+6*7/8%9)
    2. P(5+(6*7)/(8%9))
    3. V(5)=1PV(5)V(5)=V(5)+V(5)PV(5)
    4. V5=1-2+3-4+5 P(V5)
    5. V(1)=1 P(V(V(V(1))))

  2. What calculator operation from MP2, MP3 and MP4 is not appropriately designed to allow easy translation from this new calculator's input language set to the input language of the older calculator? To solve this problem, you will have to finish writing the pseudocode for the compiler for this new calculator's instruction set, at a level of detail comparable to that given for the cexpr procedure in the MP5 assignment.

    The only hint that will be given here is that you should pay close attention to the order of the items you end up pushing onto the stack and on the order of the items the old calculator instruction set expected to find on the stack. The solution to the problem is actually an easy one -- we can simply change the order of operands expected by one of the old calculator's operations before we use that part of the compiler from MP4.

  3. Consider the following extension to the defintion of statement given in MP5:
    	statement ::= P expression
    		   |  V ( expression ) = expression
    		   |  ( statement { statement } )
    		   |  L expression rop expression statement
    
            rop ::= > | = | <
    
    The new statements are a "begin end" block and a while loop. The former new feature is easy to understand -- one legal form of statement is a parenthesized sequence of statements. The second iterates the indicated statement as long as the indicated relation between the expressions remains true. Here is an example:
          V(1)=5 V(2)=1 L V(1) > 0 ( V(2)=V(2)*2 V(1)=V(1)-1 P V(1) P V(2) )
    
    What output does this produce?