D.2 Problems for Chapter 5: Syntax-directed Translation
D.2.1 Syntax-directed Definition (SDD)
Problem 2.1.15 Given below the syntax-directed definition (SDD), construct the annotated parse tree for the input expression: “int a, b”.
D –> T L L.inh = T.type
T –> int T.type = integer
T –> float T.type = float
L –> L1, id L1.inh = L.inh
addType(id.entry,L.inh)
L –> id addType(id.entry,L.inh)
The annotated parse tree is:
Problem 2.1.16 Given below the SDD with the synthesized attribute val, draw the annotated parse tree for the expression (3+4)*(5+6).
L –> E L.val = E.val E –> T E.val = T.val E –> E1 + T E.val = E1.val + T.val T –> F T.val ...
Get Compilers: Principles and Practice now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.