retagged by
16,428 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$
retagged by

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

20 votes
20 votes
4 answers
1
13 votes
13 votes
4 answers
2
Arjun asked Feb 7, 2019
9,458 views
Which one of the following kinds of derivation is used by LR parsers?LeftmostLeftmost in reverseRightmostRightmost in reverse
17 votes
17 votes
3 answers
3