GATE 2007
184 questions
MCQ 1841-mark 184
Questions 126–130 of 184
Which one of the following is a top-down parser?
Answer: (A)
Recursive descent parser: it is a TOP DOWN parser.
Operator precedence parser: it is a BOTTOM UP parser.
An LR(k) parser: it is a BOTTOM UP parser.
An LALR(k) parser: it is a BOTTOM UP parser.
Early binding refers to a binding performed at compile time and late binding refers to a binding performed at execution time. Consider the following statements:
i. Static scope facilitates w1 bindings.
ii. Dynamic scope requires w2 bindings.
iii. Early bindings w3 execution efficiency.
iv. Late bindings w4 execution efficiency.
The right choices of wl, w2, w3 and w4 (in that order) are
i. Static scope facilitates w1 bindings.
ii. Dynamic scope requires w2 bindings.
iii. Early bindings w3 execution efficiency.
iv. Late bindings w4 execution efficiency.
The right choices of wl, w2, w3 and w4 (in that order) are
Answer: (D)
Static scoping allows early binding, which happens at compile time. Early binding raises efficiency.
Dynamic scoping needs late binding, which happens at execution time. Late binding lowers efficiency because the binding must be done at runtime (but it gives more flexibility).
So the answer is (D).
Dynamic scoping needs late binding, which happens at execution time. Late binding lowers efficiency because the binding must be done at runtime (but it gives more flexibility).
So the answer is (D).
In a simplified computer the instructions are:
The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block:
Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?
| OP Rj, Ri | - Performs Rj OP Ri and stores the result in register Ri. |
| OP m,Ri | - Performs val OP Ri and stores the result in Ri. val denotes the content of memory location m. |
| MOV m, Ri | - Moves the content of memory location m to register Ri. |
| MOV Ri, m | - Moves the content of register Ri to memory location m. |
The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block:
Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block?
Answer: (B)
Meaning of the instructions: computes , with the memory value on the left. Only MOV moves data between memory and registers.
Code (the block is computed as written, with to as separate steps):
Why fewer is not possible: is computed first and is still needed at the last step, so it must stay in one register. To build and then , the other register must be loaded from memory with a MOV (OP works only on a register and a memory value, so a value cannot start in a register without a load). That is 2 loads. The result must end in memory, and only MOV can store it, so that is a third MOV. So at least 3.
Note: if algebraic regrouping were allowed, could be built in one register with only 2 MOVs (MOV ; SUB ; ADD ; ADD ; ADD ; MOV ). The key (B) assumes the block is computed as written.
Answer: (B)
Code (the block is computed as written, with to as separate steps):
- MOV
- ADD ()
- MOV
- ADD ()
- SUB (, because the memory value is on the left)
- SUB ()
- MOV (store the result)
Why fewer is not possible: is computed first and is still needed at the last step, so it must stay in one register. To build and then , the other register must be loaded from memory with a MOV (OP works only on a register and a memory value, so a value cannot start in a register without a load). That is 2 loads. The result must end in memory, and only MOV can store it, so that is a third MOV. So at least 3.
Note: if algebraic regrouping were allowed, could be built in one register with only 2 MOVs (MOV ; SUB ; ADD ; ADD ; ADD ; MOV ). The key (B) assumes the block is computed as written.
Answer: (B)
The contents of the text file t1.txt containing four lines are as follows :
a1 b1
a2 b2
a3 b2
a4 b1
The contents of the text file t2.txt containing five lines are as follows :
a1 c1
a2 c2
a3 c3
a4 c3
a5 c4
Consider the following Bourne shell script :
Which one of the following strings will NOT be present in the output generated when the above script is run? (Note that the given strings may be substrings of a printed line.)
a1 b1
a2 b2
a3 b2
a4 b1
The contents of the text file t2.txt containing five lines are as follows :
a1 c1
a2 c2
a3 c3
a4 c3
a5 c4
Consider the following Bourne shell script :
awk -F ' ' '{print $1, $2}' t1.txt |
while read a b ; do
awk -v aV=$a -v bV=$b -F ' ' '
aV == $1 {print aV, bV, $2}' t2.txt
done Which one of the following strings will NOT be present in the output generated when the above script is run? (Note that the given strings may be substrings of a printed line.)
Answer: (C)
The first awk prints the two columns of each line of t1.txt, so the loop reads the pairs (a, b) = (a1, b1), (a2, b2), (a3, b2), (a4, b1).
For each pair, the second awk scans t2.txt and prints aV, bV and column 2 of every t2 line whose column 1 equals aV.
a1 matches "a1 c1" and prints "a1 b1 c1".
a2 matches "a2 c2" and prints "a2 b2 c2".
a3 matches "a3 c3" and prints "a3 b2 c3".
a4 matches "a4 c3" and prints "a4 b1 c3".
(a5 in t2.txt matches nothing in t1.txt.)
So the output has "b1 c1", "b2 c3" and "b1 c3". The pair "b1 c2" never appears, because c2 goes with a2, and a2 goes with b2, not b1.
Answer: (C)
For each pair, the second awk scans t2.txt and prints aV, bV and column 2 of every t2 line whose column 1 equals aV.
a1 matches "a1 c1" and prints "a1 b1 c1".
a2 matches "a2 c2" and prints "a2 b2 c2".
a3 matches "a3 c3" and prints "a3 b2 c3".
a4 matches "a4 c3" and prints "a4 b1 c3".
(a5 in t2.txt matches nothing in t1.txt.)
So the output has "b1 c1", "b2 c3" and "b1 c3". The pair "b1 c2" never appears, because c2 goes with a2, and a2 goes with b2, not b1.
Answer: (C)
Consider the following statements about user level threads and kernel level threads. Which one of the following statements is FALSE?
Answer: (D)
A. True. A kernel thread switch needs a trap into the kernel and the kernel saves and restores thread state in its own data structures. A user level thread switch is done by a library in user space, with no kernel entry, so it is cheaper.
B. True. User level threads are managed by a library, so no special hardware or kernel support is needed.
C. True. The kernel knows about every kernel level thread, so it can dispatch threads of the same process to different processors.
D. False. The kernel schedules each kernel level thread separately. When one blocks, the kernel runs another thread of the same process. Blocking of all related threads happens with user level threads in the many-to-one model, where the kernel sees only one thread.
Answer: (D)
B. True. User level threads are managed by a library, so no special hardware or kernel support is needed.
C. True. The kernel knows about every kernel level thread, so it can dispatch threads of the same process to different processors.
D. False. The kernel schedules each kernel level thread separately. When one blocks, the kernel runs another thread of the same process. Blocking of all related threads happens with user level threads in the many-to-one model, where the kernel sees only one thread.
Answer: (D)