3 address code is a very common topic in many of the CS theories. I encountered it while studying Compiler Design. According to the Wikipedia article, it says -

Each TAC instruction has at most three operands and is typically a combination of assignment and a binary operator.

Now my query, does that mean I can assign a variable to another variable(operand) even if it doesn't changes any thing, as this action doesn't violates the exact meaning of TAC(at most three operands). Example for clarity:

a = b*c - d*4


t1 = b
t2 = c
t3 = d
t4 = t1*t2 
t5 = t3*4
t6 = t4 - t5
a = t6

In all the above lines, I haven't violated the TAC rule of at most 3 operands, but in the first 3 lines, I have assigned three variables to three different operands even if it isn't required.

Now technically will that be considered wrong? I know it's inefficient but is it wrong in technical terms? What I think is it's not wrong because the code optimization stage which comes after this will do the filtration if required. Still I want to know the opinions.


Three address code is an intermediate language used internally by (some) compilers. What is "right" depends on the specific rules that that compiler expects/enforces. Efficiency, as you state, is normally not an issue, as the intermediate language is designed for easy massaging and ultimately traslating into efficient target code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.