Compiler Design questions — page 3 of 5

Q9

GATE CS 2020 CSRuntime EnvironmentsMCQ1 mark−1/3 if wrong
Consider the following statements.

I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
III. Errors violating the condition ‘any variable must be declared before its use’ are detected during syntax analysis.

Which of the above statements is/are TRUE?
Show answer without attempting

Answer: D

Q24

GATE CS 2020 CSParsingNAT1 mark
Consider the following grammar.

S→aSB∣dS \rightarrow aSB \mid d
B→bB \rightarrow b

The number of reduction steps taken by a bottom-up parser while accepting the string aaadbbbaaadbbb is __________.
Show answer without attempting

Answer: 7

Q33

GATE CS 2020 CSSyntax Directed TranslationMCQ2 marks−2/3 if wrong
Consider the productions A→PQA \rightarrow PQ and A→XYA \rightarrow XY. Each of the five non-terminals A, P, Q, X, and Y has two attributes: ss is a synthesized attribute, and ii is an inherited attribute. Consider the following rules.

Rule 1: P.i=A.i+2P.i = A.i + 2, Q.i=P.i+A.iQ.i = P.i + A.i, and A.s=P.s+Q.sA.s = P.s + Q.s

Rule 2: X.i=A.i+Y.sX.i = A.i + Y.s and Y.i=X.s+A.iY.i = X.s + A.i

Which one of the following is TRUE?
Show answer without attempting

Answer: B

Q3

GATE CS 2019 CSParsingMCQ1 mark−1/3 if wrong
Which one of the following kinds of derivation is used by LR parsers?
Show answer without attempting

Answer: D

Q19

GATE CS 2019 CSParsingNAT1 mark
Consider the grammar given below:
S→AaS \to Aa
A→BDA \to BD
B→b∣ϵB \to b \mid \epsilon
D→d∣ϵD \to d \mid \epsilon

Let a,b,d,a, b, d, and $\$ be indexed as follows:
abd$\$
3210
Compute the FOLLOW set of the non-terminal BB and write the index values for the symbols in the FOLLOW set in the descending order. (For example, if the FOLLOW set is {a,b,d,$}\{a, b, d, \$\}, then the answer should be 3210)
Answer: __________.
Show answer without attempting

Answer: 31

Q36

GATE CS 2019 CSSyntax Directed TranslationMCQ2 marks−2/3 if wrong
Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X1,X2,X3,X4,X5,X_1, X_2, X_3, X_4, X_5, and X6X_6 be the placeholders for the non-terminals D,T,LD, T, L or L1L_1 in the following table:
Production ruleSemantic action
D→T  LD \to T \; LX1.type=X2.typeX_1.\text{type} = X_2.\text{type}
T→intT \to \text{int}T.type=intT.\text{type} = \text{int}
T→floatT \to \text{float}T.type=floatT.\text{type} = \text{float}
L→L1,idL \to L_1, \text{id}X3.type=X4.typeX_3.\text{type} = X_4.\text{type}; addType(id.entry,X5.type)\text{addType}(\text{id.entry}, X_5.\text{type})
L→idL \to \text{id}addType(id.entry,X6.type)\text{addType}(\text{id.entry}, X_6.\text{type})
Which one of the following are the appropriate choices for X1,X2,X3X_1, X_2, X_3 and X4X_4?
Show answer without attempting

Answer: A

Q43

GATE CS 2019 CSParsingNAT2 marks
Consider the augmented grammar given below:
S′→SS' \to S
S→(L)∣idS \to (L) \mid \text{id}
L→L,S∣SL \to L, S \mid S

Let I0=CLOSURE({[S′→∙S]})I_0 = \text{CLOSURE}(\{[S' \to \bullet S]\}). The number of items in the set GOTO(I0,()\text{GOTO}(I_0, \text{(}) is: __________.
Show answer without attempting

Answer: 5

Q8

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

Answer: B

Q37

GATE CS 2018 CSLexical AnalysisMCQ2 marks−2/3 if wrong
A lexical analyzer uses the following patterns to recognize three tokens T1,T2T_1, T_2, and T3T_3 over the alphabet {a,b,c}\{a, b, c\}.

T1T_1: a?(b∣c)∗aa? (b|c)^* a
T2T_2: b?(a∣c)∗bb? (a|c)^* b
T3T_3: c?(b∣a)∗cc? (b|a)^* c

Note that 'x?' means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the token that matches the longest possible prefix.

If the string bbaacabcbbaacabc is processed by the analyzer, which one of the following is the sequence of tokens it outputs?
Show answer without attempting

Answer: D

Q38

GATE CS 2018 CSParsingMCQ2 marks−2/3 if wrong
Consider the following parse tree for the expression a#b$c$d#e#fa \# b \$ c \$ d \# e \# f, involving two binary operators $\$ and #\#.

Which one of the following is correct for the given parse tree?
Question figure
Show answer without attempting

Answer: A

Q12

GATE CS 2017 CS-1Intermediate CodeMCQ1 mark−1/3 if wrong
Consider the following intermediate program in three address code
p = a - b
q = p * c
p = u * v
q = p + q
Which one of the following corresponds to a static single assignment form of the above code?
Show answer without attempting

Answer: B

Q43

GATE CS 2017 CS-1ParsingNAT2 marks
Consider the following grammar:
stmt -> if expr then expr else expr; stmt | ε
expr -> term relop term | term
term -> id | number
id -> a | b | c
number -> [0-9]
where relop is a relational operator (e.g., <,>,…<, >, \dots), ε\varepsilon refers to the empty statement, and if, then, else are terminals.

Consider a program PP following the above grammar containing ten if terminals. The number of control flow paths in PP is ____________. For example, the program
if e1 then e2 else e3
has 2 control flow paths, e1→e2e_1 \to e_2 and e1→e3e_1 \to e_3.
Show answer without attempting

Answer: 1024.0

Q5

GATE CS 2017 CS-2ParsingMCQ1 mark−1/3 if wrong
Match the following according to input (from the left column) to the compiler phase (in the right column) that processes it:

(P) Syntax tree
(Q) Character stream
(R) Intermediate representation
(S) Token stream

(i) Code generator
(ii) Syntax analyzer
(iii) Semantic analyzer
(iv) Lexical analyzer
Show answer without attempting

Answer: C

Q6

GATE CS 2017 CS-2ParsingMCQ1 mark−1/3 if wrong
Which of the following statements about parser is/are CORRECT?

I. Canonical LR is more powerful than SLR.
II. SLR is more powerful than LALR.
III. SLR is more powerful than Canonical LR.
Show answer without attempting

Answer: A

Q32

GATE CS 2017 CS-2ParsingMCQ2 marks−2/3 if wrong
Consider the following expression grammar G:

<br>E→E−T∣T<br>T→T+F∣F<br>F→(E)∣id<br>\begin{aligned}<br>E &\rightarrow E - T \mid T \\<br>T &\rightarrow T + F \mid F \\<br>F &\rightarrow (E) \mid id<br>\end{aligned}

Which of the following grammars is not left recursive, but is equivalent to G?
Show answer without attempting

Answer: C

Q19

GATE CS 2016 CS-1Intermediate CodeNAT1 mark
Consider the following code segment.
x = u - t;
y = x * v;
x = y + w;
y = t - z;
y = x * y;
The minimum number of total variables required to convert the above code segment to static single assignment form is ________.
Show answer without attempting

Answer: 10.0

Q36

GATE CS 2016 CS-1Runtime EnvironmentsMCQ2 marks−2/3 if wrong
What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?
a=3;
void n(x) {x = x * a; print(x);}
void m(y) {a = 1; a = y - a; n(a); print(a);}
void main() {m(a);}
Show answer without attempting

Answer: D

Q46

GATE CS 2016 CS-1Syntax Directed TranslationMCQ2 marks−2/3 if wrong
Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a, b}.
S→aA{print 1}S \to aA \{ \text{print } 1 \}
S→a{print 2}S \to a \{ \text{print } 2 \}
A→Sb{print 3}A \to Sb \{ \text{print } 3 \}
Using the above SDTS, the output printed by a bottom-up parser, for the input aab is:
Show answer without attempting

Answer: C

Q19

GATE CS 2016 CS-2Lexical AnalysisMCQ1 mark−1/3 if wrong
Match the following:

(P) Lexical analysis --- (i) Leftmost derivation
(Q) Top down parsing --- (ii) Type checking
(R) Semantic analysis --- (iii) Regular expressions
(S) Runtime environments --- (iv) Activation records
Show answer without attempting

Answer: B

Q45

GATE CS 2016 CS-2ParsingMCQ2 marks−2/3 if wrong
Which one of the following grammars is free from left recursion?
Show answer without attempting

Answer: B

0/200 correct0 marks

Related topics in GATE CS