Parsing


Q1.

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
GateOverflow

Q2.

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.
GateOverflow

Q3.

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 ___________
GateOverflow

Q4.

Which one of the following statements is TRUE?
GateOverflow

Q5.

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?
GateOverflow

Q6.

A grammar is defined asA \rightarrow B CB \rightarrow x \mid B xC \rightarrow B \mid DD \rightarrow y \mid EyE \rightarrow zThe non terminal alphabet of the grammar is
GateOverflow

Q7.

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 _____________
GateOverflow

Q8.

Consider the augmented grammar given below: S'\rightarrow S S \rightarrow \lt L \gt |id L \rightarrow L,S|S Let I_0=CLOSURE(\{[S'\rightarrow \cdot S]\}) . The number of items in the set GOTO(I_0,\lt) is __________.
GateOverflow

Q9.

Given the grammars \rightarrow T^{*} S \mid TT \rightarrow U+T \mid UU \rightarrow a \mid bWhich of the following statements is wrong?
GateOverflow

Q10.

C onsider the following parse tree for the expression a#b$c$d#e#f, involving two binary operators $ and #. Which one of the following is correct for the given parse tree?
GateOverflow