Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let ๐‘‹1, ๐‘‹2, ๐‘‹3, ๐‘‹4, ๐‘‹5, and ๐‘‹6 be the placeholders

Q. Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let ๐‘‹1, ๐‘‹2, ๐‘‹3, ๐‘‹4, ๐‘‹5, and ๐‘‹6 be the placeholders for the non- terminals D, T, L or L1 in the following table:

Production ruleSemantic action
D โ†’ T L๐‘‹1.type = ๐‘‹2.type
T โ†’ intT.type = int
T โ†’ floatT.type = float
L โ†’ L1 , id๐‘‹3.type = ๐‘‹4.type addType(id.entry, ๐‘‹5.type)
L โ†’ idaddType(id.entry, ๐‘‹6.type)

Which one of the following are the appropriate choices for ๐‘‹1, ๐‘‹2, ๐‘‹3 and ๐‘‹4?

(A) ๐‘‹1 = ๐ฟ , ๐‘‹2 = ๐‘‡, ๐‘‹3 = ๐ฟ1, ๐‘‹4 = ๐ฟ(B) ๐‘‹1 = ๐‘‡ , ๐‘‹2 = ๐ฟ, ๐‘‹3 = ๐ฟ1, ๐‘‹4 = ๐‘‡
(C) ๐‘‹1 = ๐ฟ , ๐‘‹2 = ๐ฟ, ๐‘‹3 = ๐ฟ1, ๐‘‹4 = ๐‘‡(D) ๐‘‹1 = ๐‘‡ , ๐‘‹2 = ๐ฟ, ๐‘‹3 = ๐‘‡, ๐‘‹4 = ๐ฟ1

Solution:

The correct answer is X1ย = L, X2ย = T, X3ย = L1, X4ย = L

According to Inherited attribute definition, an attribute is inherited if the attribute value of a parse-tree node is determined from attribute values of its parent and siblings.

So, semantic rules should be as following below:

D โ†’ TL {L.idtype = T.stype}

T โ†’ int {T.stype = int}

T โ†’ float {T.stype = float}

L โ†’ L1, id {L1.itype = L.itype}

           addtype(id.entry, L.itype)

L โ†’ id addtype(id.entry, L.itype)

Take Mock Tests

Government Schemes Mock Test Start Test!
Political Science Mock Test โ€“ 42 Start Test
History Test โ€“ 190 Start Test
Quantitative Aptitude Test Start Test!
Data Interpretation - Mock Test Start Test!
General Awareness - Mock Test Start Test!
Reasoning Ability - Mock Test Start Test!
We will be happy to hear your thoughts

Leave a reply

Gkseries.com
Logo
Register New Account