GATE 2004
199 questions
MCQ 1991-mark 199
Questions 126–130 of 199
Which of the following grammar rules violate the requirements of an operator grammar? P, Q, R are nonterminals, and r,s,t are terminals.
Answer: (B)
An operator grammar cannot have:
(i) has two adjacent non-terminals, so it violates the rule.
(ii) has the terminal s between Q and R, so it is allowed.
(iii) is an production, so it violates the rule.
(iv) has a terminal between Q and R and ends with a terminal, so it is allowed.
So (i) and (iii) violate the requirements.
Answer: (B)
- An production (a nullable right side).
- Two adjacent non-terminals on the of a production.
(i) has two adjacent non-terminals, so it violates the rule.
(ii) has the terminal s between Q and R, so it is allowed.
(iii) is an production, so it violates the rule.
(iv) has a terminal between Q and R and ends with a terminal, so it is allowed.
So (i) and (iii) violate the requirements.
Answer: (B)
Let be a pushdown automaton, where
Which one of the following strings is not a member of L(M)?
Which one of the following strings is not a member of L(M)?
Answer: (D)
Read as: in state p, read u, pop , go to q, push . A string is accepted if the PDA can read all of it and end in the final state f.
In s, any a or b that is read pushes one a (the first two transitions). The only other move from s is on an input a with an a on the stack: it pops that a and goes to f. In f, every a or b read pops one a. The state f can be reached only through that move.
So a string is accepted exactly when it can be written as , where x is the part pushed, the a is the move to f, and y is the rest. The stack holds a's, the middle a pops one, and each symbol of y pops one more, so we need .
aaa: . Accepted.
aabab: , and . Accepted.
baaba: . Accepted.
bab: the only a is the middle one, so and . After that a pops the only pushed a, the stack is empty and the last b has nothing to pop. Every other path ends in s, which is not final. So bab is rejected.
Answer: (D)
In s, any a or b that is read pushes one a (the first two transitions). The only other move from s is on an input a with an a on the stack: it pops that a and goes to f. In f, every a or b read pops one a. The state f can be reached only through that move.
So a string is accepted exactly when it can be written as , where x is the part pushed, the a is the move to f, and y is the rest. The stack holds a's, the middle a pops one, and each symbol of y pops one more, so we need .
aaa: . Accepted.
aabab: , and . Accepted.
baaba: . Accepted.
bab: the only a is the middle one, so and . After that a pops the only pushed a, the stack is empty and the last b has nothing to pop. Every other path ends in s, which is not final. So bab is rejected.
Answer: (D)
The language {} is
Answer: (B)
Not regular: the machine must compare the number of s with , which has no bound. By the pumping lemma, take and pump a part of the first a's. The number of a's changes while the number of c's stays fixed, so the string leaves the language.
Context-free: write . A grammar is
, .
A PDA does the same job. Start with a bottom marker on the stack. Push one symbol for each , then one for each (a state change ensures the b's come after the a's). On move to a popping state (again by state change, so no a or b comes after a c) and pop one symbol for each . Accept only when the input ends and the stack shows only , so the number of c's equals exactly.
So the language is context-free but not regular.
Answer: (B)
Context-free: write . A grammar is
, .
A PDA does the same job. Start with a bottom marker on the stack. Push one symbol for each , then one for each (a state change ensures the b's come after the a's). On move to a popping state (again by state change, so no a or b comes after a c) and pop one symbol for each . Accept only when the input ends and the stack shows only , so the number of c's equals exactly.
So the language is context-free but not regular.
Answer: (B)
L1 is a recursively enumerable language over . An algorithm A effectively enumerates its words as w1, w2, w3, ... define another language L2 over U{#} as
{wi # wj : wi, wj L1, i j}.
Here # is a new symbol. Consider the following assertions.
{wi # wj : wi, wj L1, i j}.
Here # is a new symbol. Consider the following assertions.
S1 : L1 is recursive implies L2 is recursive
S2 : L2 is recursive implies L1 is recursive Which of the following statements is true ?Answer: (A)
Take the enumeration to list each word of once.
S1 is true. Let D decide . Given input x, check that x has the form with u, v over . Run D on u and on v, and reject if either is not in . If both are in , algorithm A will list both of them. Run A until both have appeared, then accept exactly when u appears before v (that is, ). This always halts, so is recursive.
S2 is true. Let D2 decide . If is empty, it is recursive. Otherwise let be the first word A lists. Given a word x: if , accept. Otherwise give to D2. If x is in and , then x is some with , so is in and D2 accepts. If x is not in , D2 rejects. So is recursive. (The case is handled separately because is strict.)
Answer: (A)
S1 is true. Let D decide . Given input x, check that x has the form with u, v over . Run D on u and on v, and reject if either is not in . If both are in , algorithm A will list both of them. Run A until both have appeared, then accept exactly when u appears before v (that is, ). This always halts, so is recursive.
S2 is true. Let D2 decide . If is empty, it is recursive. Otherwise let be the first word A lists. Given a word x: if , accept. Otherwise give to D2. If x is in and , then x is some with , so is in and D2 accepts. If x is not in , D2 rejects. So is recursive. (The case is handled separately because is strict.)
Answer: (A)
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.
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.
Answer: (C)
By the semantic rules in the question, # means multiplication and & means addition.
Looking at the productions:
- & (+) has higher precedence than # (*), because & is farther from the start symbol.
- Both & and # are left associative.
So the expression is evaluated as
Answer: (C)