Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Explain the principal components of the semantics of grammars of Figures 4.5, 4.6. What are action routines? Explain their usage in the process of constructing

Explain the principal components of the semantics of grammars of Figures 4.5, 4.6.

image text in transcribedimage text in transcribed

What are action routines? Explain their usage in the process of constructing attribute parse trees. Support your explanations with Figures 4.7, 4.8

image text in transcribedimage text in transcribed

El.ptr := make.bin-op("+". E2.ptr. Tptr) E1 El.ptr := make.bin-op("-". E2.pt. Tptr) ET D> E.ptr := Tptr T1 T2 * F Ti.ptr := make.bin-op("x", T2.ptr, Eptr) T1 T2 / F Tptr := make.bin.op("-". T2.ptr, Fptr) D> Fl.ptr := make-un-op("+-,, F2.ptr) D FptrE.ptr F const Fptr := makeleat(const.val) FIGURE 4.5 Bottom-up (S-attributed) attribute grammar to construct a syntax tree. The symbol +/ is used (as it is on calculators) to indicate change of sign E TTT D E.ptr TT.ptr TT2.st := make-bin.op("+". TTI.st. Tptr) TTI.ptr := TT2.ptr TT2.st := make-bin-op("-". TT,.st. Tptr) TTI.ptr := TT2.ptr T FFT FT, * FFT; FT2.st := make-bin-op("X". FTist. Eptr) FT,.ptr := FT2.ptr FT--+ / FFT; D FT2.st: make.binop("+", FT1.st, Fptr) FT,.ptr := FT2.ptr Fj.ptr := make-un-op(". F2.ptr) F (E) D Fptr E.ptr F const Eptr := makeJeaf(const.val) FIGURE 4.6 Top-down (L-attributed) attribute grammar to construct a syntax tree. Here the st attribute, like the ptr attribute (and unlike the st attribute of Figure 4.3), is a pointer to a syntax tree node 3 const 2 const 3 const I FIGURE 4.7 Construction of a syntax tree for (1 +3) * 2 via decoration of a bottom-up parse tree, using the grammar of Figure 4.5. This figure reads fromm bottom to top. In diagram (a), the values of the constants 1 and 3 have been placed in new syntax tree leaves. Pointers to these leaves propagate up into the attributes of E and T. In (b), the pointers to these leaves become child pointers of a new internal + node. In (c) the pointer to this node propagates up into the attributes of T, and a new leaf is created for 2. Finally in (d), the pointers from Tand Fbecome child pointers of a new internal node, and a pointer to this node propagates up into the attributes of E. FT FT conat FIGURE 4.8 Construction of a syntax tree via decoration of a top-down parse tree, using the grammar of Figure 4.6. In the top diagram, (a), the value of the constant 1 has been placed in a new syntax tree leafA pointer to this leaf then propagates to the st attribute of TT. In (b), a second leaf has been created to hold the constant 3. Pointers to the two leaves then become child pointers of a new internal + node, a pointer to which propagates from the st attribute of the bottom-most TT, where it was created, all the way up and over to the st attribute of the top-most FT. In (c), a third leaf has been created for the constant 2. Pointers to this leaf and to the node then become the children of a new x node, of the lower FT, where it was created, all the way to the root of the tree a pointer to which propagates from the st El.ptr := make.bin-op("+". E2.ptr. Tptr) E1 El.ptr := make.bin-op("-". E2.pt. Tptr) ET D> E.ptr := Tptr T1 T2 * F Ti.ptr := make.bin-op("x", T2.ptr, Eptr) T1 T2 / F Tptr := make.bin.op("-". T2.ptr, Fptr) D> Fl.ptr := make-un-op("+-,, F2.ptr) D FptrE.ptr F const Fptr := makeleat(const.val) FIGURE 4.5 Bottom-up (S-attributed) attribute grammar to construct a syntax tree. The symbol +/ is used (as it is on calculators) to indicate change of sign E TTT D E.ptr TT.ptr TT2.st := make-bin.op("+". TTI.st. Tptr) TTI.ptr := TT2.ptr TT2.st := make-bin-op("-". TT,.st. Tptr) TTI.ptr := TT2.ptr T FFT FT, * FFT; FT2.st := make-bin-op("X". FTist. Eptr) FT,.ptr := FT2.ptr FT--+ / FFT; D FT2.st: make.binop("+", FT1.st, Fptr) FT,.ptr := FT2.ptr Fj.ptr := make-un-op(". F2.ptr) F (E) D Fptr E.ptr F const Eptr := makeJeaf(const.val) FIGURE 4.6 Top-down (L-attributed) attribute grammar to construct a syntax tree. Here the st attribute, like the ptr attribute (and unlike the st attribute of Figure 4.3), is a pointer to a syntax tree node 3 const 2 const 3 const I FIGURE 4.7 Construction of a syntax tree for (1 +3) * 2 via decoration of a bottom-up parse tree, using the grammar of Figure 4.5. This figure reads fromm bottom to top. In diagram (a), the values of the constants 1 and 3 have been placed in new syntax tree leaves. Pointers to these leaves propagate up into the attributes of E and T. In (b), the pointers to these leaves become child pointers of a new internal + node. In (c) the pointer to this node propagates up into the attributes of T, and a new leaf is created for 2. Finally in (d), the pointers from Tand Fbecome child pointers of a new internal node, and a pointer to this node propagates up into the attributes of E. FT FT conat FIGURE 4.8 Construction of a syntax tree via decoration of a top-down parse tree, using the grammar of Figure 4.6. In the top diagram, (a), the value of the constant 1 has been placed in a new syntax tree leafA pointer to this leaf then propagates to the st attribute of TT. In (b), a second leaf has been created to hold the constant 3. Pointers to the two leaves then become child pointers of a new internal + node, a pointer to which propagates from the st attribute of the bottom-most TT, where it was created, all the way up and over to the st attribute of the top-most FT. In (c), a third leaf has been created for the constant 2. Pointers to this leaf and to the node then become the children of a new x node, of the lower FT, where it was created, all the way to the root of the tree a pointer to which propagates from the st

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

=+a) Write the equation of the regression line.

Answered: 1 week ago

Question

3. How does nonverbal communication express cultural values?

Answered: 1 week ago

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago