GATE 2003
107 questions
MCQ 1071-mark 107
Questions 76–80 of 107
Consider the grammar shown below.
S C C
C cC | d
The grammar is
S C C
C cC | d
The grammar is
Answer: (A)
For : , so this rule goes in cells [S, c] and [S, d].
For C, the two rules start with different terminals: and . They do not overlap and neither rule can give , so no FOLLOW check is needed. So goes in [C, c] and goes in [C, d].
Every cell of the parsing table has at most one rule, so the grammar is LL(1).
An -free LL(1) grammar is also SLR(1), and so LALR(1) and LR(1) as well. So (B) and (D) are wrong, because they say the grammar is not SLR(1) or not LALR(1). (C) is wrong because it says the grammar is not LL(1).
Note: for a rule to be LL(1), must be empty. If contains , then must also be empty. This test checks LL(1) without building the table.
Answer: (A)
For C, the two rules start with different terminals: and . They do not overlap and neither rule can give , so no FOLLOW check is needed. So goes in [C, c] and goes in [C, d].
Every cell of the parsing table has at most one rule, so the grammar is LL(1).
An -free LL(1) grammar is also SLR(1), and so LALR(1) and LR(1) as well. So (B) and (D) are wrong, because they say the grammar is not SLR(1) or not LALR(1). (C) is wrong because it says the grammar is not LL(1).
Note: for a rule to be LL(1), must be empty. If contains , then must also be empty. This test checks LL(1) without building the table.
Answer: (A)
Let G = ({S}, {a, b} R, S) be a context free grammar where the rule set R is
Which of the following statements is true?
Which of the following statements is true?
Answer: (C)
The problem becomes easier if we write ( in place of terminal and ) in place of terminal .
the set of balanced parentheses [every left parenthesis has a matching right parenthesis, and they are well nested].
Examples: .
(A) The string has three different derivation trees:
, where the left S becomes and the right S becomes
, where the right S becomes and the left S becomes
So G is ambiguous, and (A) is false.
(B) Joining two balanced strings gives a balanced string, for example and give . So (B) is false.
(C) We can build a deterministic PDA for : push each left parenthesis on the stack and pop one for each right parenthesis. Accept when the input ends with an empty stack. So (C) is true.
(D) We cannot build a DFA for , because a stack is needed to count the unmatched left parentheses without limit. So (D) is false.
Answer: (C)
the set of balanced parentheses [every left parenthesis has a matching right parenthesis, and they are well nested].
Examples: .
(A) The string has three different derivation trees:
, where the left S becomes and the right S becomes
, where the right S becomes and the left S becomes
So G is ambiguous, and (A) is false.
(B) Joining two balanced strings gives a balanced string, for example and give . So (B) is false.
(C) We can build a deterministic PDA for : push each left parenthesis on the stack and pop one for each right parenthesis. Accept when the input ends with an empty stack. So (C) is true.
(D) We cannot build a DFA for , because a stack is needed to count the unmatched left parentheses without limit. So (D) is false.
Answer: (C)
Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
Answer: (D)
An LL(1) parser works top down, and it can only use a grammar that is unambiguous, not left recursive and left factored. Removing left recursion and left factoring fix only the last two. Neither one removes ambiguity, so an ambiguous grammar stays ambiguous after both steps, and an ambiguous grammar is never LL(1). Some context-free languages are inherently ambiguous, so no unambiguous grammar exists for them at all.
Even an unambiguous grammar for a deterministic context-free language may not be convertible: some deterministic CFLs have no LL(k) grammar for any . (Every deterministic CFL does have an LR(1) grammar.)
So (A), (B) and (C) are not enough for an arbitrary CFG.
Answer: (D)
Even an unambiguous grammar for a deterministic context-free language may not be convertible: some deterministic CFLs have no LL(k) grammar for any . (Every deterministic CFL does have an LR(1) grammar.)
So (A), (B) and (C) are not enough for an arbitrary CFG.
Answer: (D)
If the strings of a language L can be effectively enumerated in lexicographic (i.e. alphabetic) order, which of the following statements is true?
Answer: (D)
Here "lexicographic order" means shorter strings first, and strings of equal length in alphabetical order, so every string has only finitely many strings before it.
is recursive: if L is finite, it is regular and so recursive. If L is infinite, to test a word w, run the enumeration. If w comes out, accept. If a word later than w comes out first, reject, because w has been passed and will not appear. An infinite L always produces such a later word, so this always halts.
need not be context-free or regular. Take . Its strings can be enumerated in this order (test each candidate string), but it is not a CFL (pumping : the pumped part cannot contain both a's and c's). So (B) and (C) are wrong. (A) is wrong because can be enumerated in order and is infinite.
Answer: (D)
is recursive: if L is finite, it is regular and so recursive. If L is infinite, to test a word w, run the enumeration. If w comes out, accept. If a word later than w comes out first, reject, because w has been passed and will not appear. An infinite L always produces such a later word, so this always halts.
need not be context-free or regular. Take . Its strings can be enumerated in this order (test each candidate string), but it is not a CFL (pumping : the pumped part cannot contain both a's and c's). So (B) and (C) are wrong. (A) is wrong because can be enumerated in order and is infinite.
Answer: (D)
Define languages L0 and L1 as follows :
L0 = {< M, w, 0 > | M halts on w}
L1 = {< M, w, 1 > | M does not halts on w} Here is a triplet, whose first component. M is an encoding of a Turing Machine, second component, w, is a string, and third component, i, is a bit. Let . Which of the following is true ?Answer: (D)
Suppose is recursively enumerable, so some TM accepts exactly the strings of .
For any : if M halts on w, and if M does not halt on w. Exactly one of the two triplets is in .
Run on both triplets in parallel, a step at a time on each, because one run may never stop. One of them is in , so accepts it. If it is the one with bit 0, M halts on w; if it is the one with bit 1, M does not halt. That decides the halting problem, which is impossible. So is not recursively enumerable.
The same works for : if M does not halt on w, and if M halts on w. Again exactly one of the two triplets is in . If were recursively enumerable, with a machine , running on both triplets in parallel would decide halting. So is not recursively enumerable either.
Neither nor is recursively enumerable.
Answer: (D)
For any : if M halts on w, and if M does not halt on w. Exactly one of the two triplets is in .
Run on both triplets in parallel, a step at a time on each, because one run may never stop. One of them is in , so accepts it. If it is the one with bit 0, M halts on w; if it is the one with bit 1, M does not halt. That decides the halting problem, which is impossible. So is not recursively enumerable.
The same works for : if M does not halt on w, and if M halts on w. Again exactly one of the two triplets is in . If were recursively enumerable, with a machine , running on both triplets in parallel would decide halting. So is not recursively enumerable either.
Neither nor is recursively enumerable.
Answer: (D)