in Compiler Design retagged by
16,504 views
21 votes
21 votes

Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let $X_1, X_2, X_3, X_4, X_5$, and $X_6$ be the placeholders for the non-terminals $D, T, L$ or $L_1$ in the following table:

$$\begin{array}{|l|l|} \hline  \text{Production rule} & \text{Semantic action} \\ \hline D \rightarrow T L & X_1.\text{type} = X_2.\text{type} \\ \hline T \rightarrow \text{int} & T.\text{type} = \text{int} \\ \hline T \rightarrow \text{float} & T.\text{type} = \text{float} \\ \hline
L \rightarrow L_1, id & X_3.\text{type}= X_4.\text{type}  \\ 
&\text{addType}(id. \text{entry}, X_5.\text{type})\\ \hline
L \rightarrow id & \text{addType}(id. \text{entry}, X_6.\text{type}) \\ \hline \end{array}$$

Which one of the following are appropriate choices for $X_1, X_2, X_3$ and $X_4$?

  1. $X_1=L, \: X_2=T, \: X_3=L_1, \: X_4 = L$
  2. $X_1=T, \: X_2=L, \: X_3=L_1, \: X_4 = T$
  3. $X_1=L, \: X_2=L, \: X_3=L_1, \: X_4 = T$
  4. $X_1=T, \: X_2=L, \: X_3=T, \: X_4 = L_1$
in Compiler Design retagged by
by
16.5k views

3 Comments

A can take value from S, whereas B can take value from A as well as S.
0
0

In option C X1= L and X2 = L is this allowed in inherited ?

just asking to be clear about it, though as per defination they have said inherit mean from parent or sibling. so it should also be a reason to eliminate option c
0
0

if the 5th option is give. 

  •  T
  • L
  • L1
  • L

is this also true.  

0
0

6 Answers

2 votes
2 votes

Since the production,

L → L1, id {X3.type = X4.type } , this production has L and L1, hence X3 and X4 cannot be T.

So option B, C and D cannot be correct.

Hence, A is correct answer.

2 votes
2 votes
The production
L → L1, id {X3.type = X4.type } ,

Above production has L and L1, hence X3 and X4 can not be T.
So option 1, 3 and 4 cannot be correct.
Hence, A is the correct answer.
Answer:

Related questions