Consider the following syntax-directed definition .
Given as the input, which one of the following options is the value computed by the (in the attribute )?
GATE CSE 2024Compiler Design › Syntax-Directed Translation & Intermediate CodeVerified
(A) 45 45 45
Parse the input MMLK according to S -> D H T U. Since the string is M M L K, D handles the two M's, H handles the L, T uses its ε-production (no C is present), and U handles the K. Evaluate the synthesized attributes bottom-up and add them at S.
Only the first two M's are consumed by D; the L is consumed by H; T consumes no input and takes its ε-production value -5; K is consumed by U. Summing D.val=5, H.val=40, T.val=-5, U.val=5 yields 45.
Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.