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 grammarS → (S) | aLet 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

 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).valThe 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

 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

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

 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

 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

 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