# Parsing

 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
 A 20 B 65 C 160 D 80
GATE CSE 2022   Compiler Design
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.
 A 2 B 3 C 4 D 5
GATE CSE 2022   Compiler Design
Question 2 Explanation:
 Question 3
Which one of the following statements is TRUE?
 A 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. B Symbol table is accessed only during the lexical analysis phase. C Data flow analysis is necessary for run-time memory management. D LR(1) parsing is sufficient for deterministic context-free languages.
GATE CSE 2022   Compiler Design
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 ___________
 A 6 B 7 C 8 D 9
GATE CSE 2021 SET-2   Compiler Design
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 11 B 6 C 5 D 10
GATE CSE 2021 SET-1   Compiler Design
Question 5 Explanation:
 Question 6
Consider the following statements.

S1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2: For any context-free grammar, there is a parser that takes at most $O(n^3)$ time to parse a string of length n.

Which one of the following options is correct?
 A S1 is true and S2 is false B S1 is false and S2 is true C S1 is true and S2 is true D S1 is false and S2 is false
GATE CSE 2021 SET-1   Compiler Design
Question 6 Explanation:
 Question 7
A grammar is defined as
$A \rightarrow B C$
$B \rightarrow x \mid B x$
$C \rightarrow B \mid D$
$D \rightarrow y \mid Ey$
$E \rightarrow z$
The non terminal alphabet of the grammar is
 A $\{A, B, C, D, E\}$ B $\{B, C, D, E\}$ C $\{A, B, C, D, E,x,y,z\}$ D $\{x,y,z\}$
ISRO CSE 2020   Compiler Design
Question 7 Explanation:
 Question 8
A given grammar is called ambiguous if
 A two or more productions have the same non-terminal on the left hand side B a derivation tree has more than one associated sentence C there is a sentence with more than one derivation tree corresponding to it D brackets are not present in the grammar
ISRO CSE 2020   Compiler Design
Question 8 Explanation:
 Question 9
Given the grammar
$s \rightarrow T^{*} S \mid T$
$T \rightarrow U+T \mid U$
$U \rightarrow a \mid b$
Which of the following statements is wrong?
 A Grammar is not ambiguous B Priority of + over * is ensured C Right to left evaluation of * and + happens D None of these
ISRO CSE 2020   Compiler Design
Question 9 Explanation:
 Question 10
Consider the following grammar.

$S\rightarrow aSB|d$
$B\rightarrow b$

The number of reduction steps taken by a bottom-up parser while accepting the string $aaadbbb$ is___________.
 A 5 B 6 C 7 D 8
GATE CSE 2020   Compiler Design
Question 10 Explanation:
There are 10 questions to complete.

### 4 thoughts on “Parsing”

1. in question no. 7 there will be b instead of d in production B
S→aSB∣d
B→b