Compiler Design questions

Q13

GATE CS 2022 CSParsingMCQ1 mark−1/3 if wrong
Which one of the following statements is TRUE?
Show answer without attempting

Answer: D

Q29

GATE CS 2022 CSParsingNAT1 mark
Consider the augmented grammar with {+,∗,(,),id}\{+, *, (, ), \text{id}\} as the set of terminals.

S′→SS' \to S
S→S+R∣RS \to S + R \mid R
R→R∗P∣PR \to R * P \mid P
P→(S)∣idP \to (S) \mid \text{id}

If I0I_0 is the set of two LR(0)LR(0) items {[S′→S∙],[S→S∙+R]}\bigl\{[S' \to S\bullet], [S \to S\bullet + R]\bigr\}, then goto(closure(I0),+)\text{goto}(\text{closure}(I_0), +) contains exactly __________ items.
Show answer without attempting

Answer: 5

Q65

GATE CS 2022 CSSyntax Directed TranslationNAT2 marks
Consider the following grammar along with translation rules.

S→S1#T{Sval=S1val∗Tval}S \to S_1 \# T \quad \{S_{\text{val}} = S_{1\text{val}} * T_{\text{val}}\}
S→T{Sval=Tval}S \to T \quad \{S_{\text{val}} = T_{\text{val}}\}
T→T1%R{Tval=T1val÷Rval}T \to T_1 \% R \quad \{T_{\text{val}} = T_{1\text{val}} \div R_{\text{val}}\}
T→R{Tval=Rval}T \to R \quad \{T_{\text{val}} = R_{\text{val}}\}
R→id{Rval=idval}R \to \text{id} \quad \{R_{\text{val}} = \text{id}_{\text{val}}\}

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

Using this translation scheme, the computed value of SvalS_{\text{val}} for root of the parse tree for the expression 20#10%5#8%2%220\#10\%5\#8\%2\%2 is _____________.
Show answer without attempting

Answer: 80

0/30 correct0 marks

Related topics in GATE CS