Home » Compiler Design » Compiler design miscellaneous » Question

Compiler design miscellaneous

  1. Consider the grammar rule E → E1 – E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any common sub-expression, in order to get shortest possible code.
    1. E1 should be evaluated first
    2. E2 should be evaluated first
    3. Evaluation of E1 and E2 should necessarily be interleaved
    4. Order to evaluation of E1 and E2 is of no consequence
Correct Option: B

E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2 also. So E2 should be evaluated first & then E1, so finally E1 will be in accumulator, otherwise need to use move & load instructions.
Hence (b) is correct option.



Your comments will be displayed only after manual approval.