Question 1 |

Consider the following grammar along with translation rules.

\begin{aligned} &S \rightarrow S_1 \# T & & \{S._{val}=S_{1.val}*T._{val} \} \\ &S \rightarrow T & & \{S._{val}=T._{val} \} \\ &T \rightarrow T_1 \% R & & \{T._{val}=T_{1.val} \div R._{val} \} \\ &T \rightarrow R & & \{T._{val}=R._{val} \} \\ &R \rightarrow id & & \{R._{val}=id._{val} \} \\ \end{aligned}

Here \# and \% are operators and id is a token that represents an integer and id_{.val} represents the corresponding integer value. The set of non-terminals is \{S,T,R,P \} and a subscripted non-terminal indicates an instance of the non-terminal.

Using this translation scheme, the computed value of S_{.val} for root of the parse tree for the expression 20 \# 10 \% 5 \# 8 \% 2 \% 2 is

\begin{aligned} &S \rightarrow S_1 \# T & & \{S._{val}=S_{1.val}*T._{val} \} \\ &S \rightarrow T & & \{S._{val}=T._{val} \} \\ &T \rightarrow T_1 \% R & & \{T._{val}=T_{1.val} \div R._{val} \} \\ &T \rightarrow R & & \{T._{val}=R._{val} \} \\ &R \rightarrow id & & \{R._{val}=id._{val} \} \\ \end{aligned}

Here \# and \% are operators and id is a token that represents an integer and id_{.val} represents the corresponding integer value. The set of non-terminals is \{S,T,R,P \} and a subscripted non-terminal indicates an instance of the non-terminal.

Using this translation scheme, the computed value of S_{.val} for root of the parse tree for the expression 20 \# 10 \% 5 \# 8 \% 2 \% 2 is

20 | |

65 | |

160 | |

80 |

Question 1 Explanation:

Question 2 |

Consider the augmented grammar with \{+, *, (, ), id \} as the set of terminals.

\begin{aligned}&S' \rightarrow S \\ &S \rightarrow S+R|R \\ &R \rightarrow R*P|P \\ &P \rightarrow (S)|id \end{aligned}

If I_0 is the set of two LR(0) items \{ [S' \rightarrow S.], [S \rightarrow S.+R] \}, then goto(closure(I_0 ),+) contains exactly ______ items.

\begin{aligned}&S' \rightarrow S \\ &S \rightarrow S+R|R \\ &R \rightarrow R*P|P \\ &P \rightarrow (S)|id \end{aligned}

If I_0 is the set of two LR(0) items \{ [S' \rightarrow S.], [S \rightarrow S.+R] \}, then goto(closure(I_0 ),+) contains exactly ______ items.

2 | |

3 | |

4 | |

5 |

Question 2 Explanation:

Question 3 |

Which one of the following statements is TRUE?

The LALR(1) parser for a grammar G cannot have reduce-reduce conflict if the
LR(1) parser for G does not have reduce-reduce conflict.
| |

Symbol table is accessed only during the lexical analysis phase. | |

Data flow analysis is necessary for run-time memory management. | |

LR(1) parsing is sufficient for deterministic context-free languages. |

Question 3 Explanation:

Question 4 |

Consider the following augmented grammar with \{ \#, @, <, >, a, b, c \} as the set of terminals.

\begin{array}{l} S' \rightarrow S \\ S \rightarrow S \# cS \\ S \rightarrow SS \\ S \rightarrow S @ \\ S \rightarrow < S > \\ S \rightarrow a \\ S \rightarrow b \\ S \rightarrow c \end{array}

Let I_0 = \text{CLOSURE}(\{S' \rightarrow \bullet S\}). The number of items in the set \text{GOTO(GOTO}(I_0 \lt ), \lt ) is ___________

\begin{array}{l} S' \rightarrow S \\ S \rightarrow S \# cS \\ S \rightarrow SS \\ S \rightarrow S @ \\ S \rightarrow < S > \\ S \rightarrow a \\ S \rightarrow b \\ S \rightarrow c \end{array}

Let I_0 = \text{CLOSURE}(\{S' \rightarrow \bullet S\}). The number of items in the set \text{GOTO(GOTO}(I_0 \lt ), \lt ) is ___________

6 | |

7 | |

8 | |

9 |

Question 4 Explanation:

Question 5 |

Consider the following C code segment:

a = b + c;

e = a + 1;

d = b + c;

f = d + 1;

g = e + f;

In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is _____________

a = b + c;

e = a + 1;

d = b + c;

f = d + 1;

g = e + f;

In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is _____________

11 | |

6 | |

5 | |

10 |

Question 5 Explanation:

There are 5 questions to complete.

in question no. 7 there will be b instead of d in production B

S→aSB∣d

B→b

Thank You Ankush Banik,

We have updated the question.

Nice webiste , Good

B option of Q20 is incomplete

Q41) this question should be the part of SDT. right?

This question covers multiple topics of Compiler Design subject including parsing and SDT.

Hello Sir/ Ma’am

In question 33, the lookahead of the second production rule is not defined, leads to create a confusion in ones mind.

The second production should like

X –> c.X, $

X –> .cX, $

X–> .d , $

Thanks for such awesome website for practicing PYQ😇

pls correct the question 33. it’s not same as gateoverflow question, bcz $ is missing at the end of the production of G2 Grammer

Q77. options C and D are incorrect.

Sentence should be: if a then if b then c:= d else c:= f