GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 2.21

Postfix and addition association

Compiler Design · Intermediate Code · Full GATE CSE 1995 paper

GATE 1995, Q2.21 2 marks · MCQ
Report issue

Intermediate Code

Question 2.21, GATE 1995: Convert A+B*(C+D)/F+D*E to postfix using ordinary precedence and left associativity.
Tap to enlarge
Your answer
Answer & solution

Answer: Exact: ABCD+*F/+DE*+; listed B reassociates the additions (no official key was published)

First convert C+D to CD+, multiply by B to obtain BCD+*, and divide by F to obtain BCD+*F/. Ordinary left-associative addition then combines A with that term, before adding DE*, yielding ABCD+*F/+DE*+. Listed B is ABCD+*F/DE*++, which instead parses A+(B*(C+D)/F+D*E). These have the same value over exact arithmetic because addition is associative, explaining the intended B, but they are not identical parse-tree conversions and can differ with floating-point rounding. The distinction is retained rather than labeling the printed postfix exactly left associative.

Original paper, page 5