A directory of Objective Type Questions covering all the Computer Science subjects. Here you can access and discuss Multiple choice questions and answers for various compitative exams and interviews.

31. Consider the translation scheme shown below

S → T R
R → + T {print ('+');} R | ε
T → num {print (num.val);}

Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will print
a. 9 + 5 + 2
b. 9 5 + 2 +
c. 9 5 2 + +
d. + + 9 5 2
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).9 5 + 2 +

32. Consider the syntax directed definition shown below.

S → id : = E {gen (id.place = E.place;);}
E → E1 + E2 {t = newtemp ( ); gen (t = El.place + E2.place;); E.place = t}
E → id {E.place = id.place;}

Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti's are the temporary variable names generated by newtemp. For the statement 'X: = Y + Z', the 3-address code sequence generated by this definition is
a. X = Y + Z
b. t1 = Y + Z; X = t1
c. t1 =Y; t2 = t1 + Z; X = t2
d. t1 = Y; t2 = Z; t3 = t1 + t2; X = t3
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).t1 = Y + Z; X = t1

33. Which of the following statements is false?
a. An unambiguous grammar has same leftmost and rightmost derivation
b. An LL(1) parser is a top-down parser
c. LALR is more powerful than SLR
d. An ambiguous grammar can never be LR(k) for any k
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).An unambiguous grammar has same leftmost and rightmost derivation

34. Which of the following derivations does a top-down parser use while parsing an input string? The input is assumed to be scanned in left to right order.
a. Leftmost derivation
b. Leftmost derivation traced out in reverse
c. Rightmost derivation
d. Rightmost derivation traced out in reverse
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).Leftmost derivation

35. Given the following expression grammar:

E -> E * F | F + E | F
F -> F - F | id

which of the following is true?
a. * has higher precedence than +
b. – has higher precedence than *
c. + and — have same precedence
d. + has higher precedence than *
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).– has higher precedence than *

36. Which one of the following is True at any valid state in shift-reduce parsing?
a. Viable prefixes appear only at the bottom of the stack and not inside
b. Viable prefixes appear only at the top of the stack and not inside
c. The stack contains only a set of viable prefixes
d. The stack never contains viable prefixes
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).The stack contains only a set of viable prefixes

37. In the context of abstract-syntax-tree (AST) and control-flow-graph (CFG), which one of the following is True?
a. In both AST and CFG, let node N2 be the successor of node N1. In the input program, the code corresponding to N2 is present after the code corresponding to N1
b. For any input program, neither AST nor CFG will contain a cycle
c. The maximum number of successors of a node in an AST and a CFG depends on the input program
d. Each node in AST and CFG corresponds to at most one statement in the input program
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).The maximum number of successors of a node in an AST and a CFG depends on the input program

38. Match the following:

List-I List-II
A. Lexical analysis 1. Graph coloring
B. Parsing 2. DFA minimization
C. Register allocation 3. Post-order traversal
D. Expression evaluation 4. Production tree

Codes:
A B C D
(a) 2 3 1 4
(b) 2 1 4 3
(c) 2 4 1 3
(d) 2 3 4 1
a. a
b. b
c. c
d. d
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).c

39. Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the most powerful, in that order?
a. SLR, LALR
b. Canonical LR, LALR
c. SLR, canonical LR
d. LALR, canonical LR
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).SLR, canonical LR

40. Consider the following grammar G.

S → F ⎪ H
F → p ⎪ c
H → d ⎪ c

Where S, F and H are non-terminal symbols, p, d and c are terminal symbols. Which of the following statement(s) is/are correct?

S1: LL(1) can parse all strings that are generated using grammar G.
S2: LR(1) can parse all strings that are generated using grammar G.
a. Only S1
b. Only S2
c. Both S1 and S2
d. Neither S1 and S2
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).Neither S1 and S2

Page 4 of 6