Question: Augment the attribute grammar of Figure 4.5, Figure 4.6, or Exercise 4.21 to initialize a synthesized attribute in every syntax tree node that indicates the
Augment the attribute grammar of Figure 4.5, Figure 4.6, or Exercise 4.21 to initialize a synthesized attribute in every syntax tree node that indicates the location (line and column) at which the corresponding construct appears in the source program. You may assume that the scanner initializes the location of every token.
Figure 4.5:

Figure 4.6:

Data From Exercise 4.21:
Write an attribute grammar based on the CFG of Figure 4.11 that will build a syntax tree with the structure described in Figure 4.14.
+ Ez + T E1.ptr := make bin_op("+", E2.ptr, T.ptr) E1 E1 + E, T E1.ptr := make.bin_op("-", E2.ptr, T.ptr) E T E.ptr := T.ptr , * F T1 ptr := make bin.op("x", T2.ptr, F.ptr) T1 T1 + T, / F T1.ptr := make bin_op(":", T2.ptr, F.ptr) T F T.ptr := F.ptr F1 F2 F1.ptr := make.un.op("+/", F2.ptr) F (E ) F.ptr := E.ptr F const F.ptr := makeleaf(const.val)
Step by Step Solution
3.39 Rating (165 Votes )
There are 3 Steps involved in it
ANSWER E2 T E1ptr makebinop E2ptr Tptr E1location E2location E2 T E1ptr makebinop E2ptr Tptr E1... View full answer
Get step-by-step solutions from verified subject matter experts
