Write a compiler for arithmetic expressions of the form: (op operand1 operand2) where op is either +,

Question:

Write a compiler for arithmetic expressions of the form:

(op operand1 operand2)

where op is either +, −, *, or / and the operands are either numbers or nested expressions.

An example is (* (+ 3 6) (− 7 9)). Assume that the target machine has instructions:

(move value register)

(add register-1 register-2)

(subtract register-1 register-2)

(times register-1 register-2)

(divide register-1 register-2)

All the arithmetic operations will leave the result in the first register argument. To simplify, assume an unlimited number of registers. Your compiler should take an arithmetic expression and return a list of these machine operations.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: