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.

21. Consider the grammar

S → (S) | a

Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar be n1, n2 and n3 respectively. The following relationship holds good
a. n1 < n2 < n3
b. n1 = n3 < n2
c. n1 = n2 = n3
d. n1 ≥ n3 ≥ n2
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).n1 = n3 < n2

22. Consider the following expression grammar. The seman­tic rules for expression calculation are stated next to each grammar production.

E → number E.val = number. val
| E '+' E E(1).val = E(2).val + E(3).val
| E '×' E E(1).val = E(2).val × E(3).val

The above grammar and the semantic rules are fed to a yacc tool (which is an LALR (1) parser generator) for parsing and evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar?
a. It detects recursion and eliminates recursion
b. It detects reduce-reduce conflict, and resolves
c. It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce action
d. It detects shift-reduce conflict, and resolves the conflict in favor of a reduce over a shift action
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce action

23. Consider the following expression grammar. The seman­tic rules for expression calculation are stated next to each grammar production.

E → number E.val = number. val
| E '+' E E(1).val = E(2).val + E(3).val
| E '×' E E(1).val = E(2).val × E(3).val

Assume the conflicts in Part (a) of this question are resolved and an LALR(1) parser is generated for parsing arithmetic expressions as per the given grammar. Consider an expression 3 × 2 + 1. What precedence and associativity properties does the generated parser realize?
a. Equal precedence and left associativity; ex­pression is evaluated to 7
b. Equal precedence and right associativity; ex­pression is evaluated to 9
c. Precedence of '×' is higher than that of '+', and both operators are left associative; expression is evaluated to 7
d. Precedence of '+' is higher than that of '×', and both operators are left associative; expression is evaluated to 9
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).Equal precedence and right associativity; ex­pression is evaluated to 9

24. Which of the following grammar rules violate the requirements of an operator grammar ? P, Q, R are nonterminals, and r, s, t are terminals.

1. P → Q R
2. P → Q s R
3. P → ε
4. P → Q t R r
a. 1 only
b. 1 and 3 only
c. 2 and 3 only
d. 3 and 4 only
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).1 and 3 only

25. Consider the grammar with the following translation rules and E as the start symbol.

E → E1 # T { E.value = E1.value * T.value }
| T{ E.value = T.value }
T → T1 & F { T.value = T1.value + F.value }
| F{ T.value = F.value }
F → num { F.value = num.value }

Compute E.value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 & 4.
a. 200
b. 180
c. 160
d. 40
View Answer Report Discuss Too Difficult! Search Google
Answer: (c).160

26. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
a. Removing left recursion alone
b. Factoring the grammar alone
c. Removing left recursion and factoring the grammar
d. None of these
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).None of these

27. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is:
a. n1 is necessarily less than n2
b. n1 is necessarily equal to n2
c. n1 is necessarily greater than n2
d. none of these
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).n1 is necessarily equal to n2

28. In a bottom-up evaluation of a syntax directed definition, inherited attributes can
a. always be evaluated
b. be evaluated only if the definition is L-­attributed
c. be evaluated only if the definition has synthesized attributes
d. never be evaluated
View Answer Report Discuss Too Difficult! Search Google
Answer: (b).be evaluated only if the definition is L-­attributed

29. Consider the grammar shown below S → i E t S S' | a S' → e S | ε E → b In the predictive parse table. M, of this grammar, the entries M[S', e] and M[S', $] respectively are
a. {S' → e S} and {S' → e}
b. {S' → e S} and {}
c. {S' → ε} and {S' → ε}
d. {S' → e S, S'→ ε} and {S' → ε}
View Answer Report Discuss Too Difficult! Search Google
Answer: (d).{S' → e S, S'→ ε} and {S' → ε}

30. Consider the grammar shown below.

S → C C
C → c C | d

The grammar is
a. LL(1)
b. SLR(1) but not LL(1)
c. LALR(1) but not SLR(1)
d. LR(1) but not LALR(1)
View Answer Report Discuss Too Difficult! Search Google
Answer: (a).LL(1)

Page 3 of 6