Question: Write a compiler for arithmetic expressions of the form: (op operand1 operand2) where op is either +, , *, or / and the operands are

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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Management And Artificial Intelligence Questions!

Q:

a