GATE 2010
82 questions
MCQ 821-mark 39 · 2-mark 43
Questions 41–45 of 82
Let L1 be a recursive language. Let L2 and L3 be languages that are recursively enumerable but not recursive. Which of the following statements is not necessarily true?
Answer: (B)
Here is recursive, so is also recursive. Also is RE, since every recursive language is RE. Go through each statement:
- (A) . This is RE recursive, and RE languages are closed under intersection, so it is RE. Always true.
- (C) and (D): and are the union and intersection of two RE languages, so both are RE. Always true.
- (B) . Since is RE but not recursive, is not RE (if both were RE, would be recursive). So the result need not be RE. For example, take , which is recursive. Then , which is not RE.
So (B) is the statement that is not necessarily true.
Answer: (B)
- (A) . This is RE recursive, and RE languages are closed under intersection, so it is RE. Always true.
- (C) and (D): and are the union and intersection of two RE languages, so both are RE. Always true.
- (B) . Since is RE but not recursive, is not RE (if both were RE, would be recursive). So the result need not be RE. For example, take , which is recursive. Then , which is not RE.
So (B) is the statement that is not necessarily true.
Answer: (B)
Which data structure in a compiler is used for managing information about variables and their attributes?
Answer: (B)
A symbol table holds each identifier together with its attributes, such as type, scope and location.
Answer: Symbol table
Answer: Symbol table
The grammar SaSa|bS|c is
Answer: (C)
The three productions begin with different terminals a, b and c. So their FIRST sets do not overlap the grammar is LL(1).
Any LL(1) grammar is also LR(1).
Answer: Both LL(1) and LR(1)
Any LL(1) grammar is also LR(1).
Answer: Both LL(1) and LR(1)
Which languages necessarily need heap allocation in the runtime environment?
Answer: (C)
- (A) A stack is enough for recursion. Each call gets an activation record that is removed when the call returns.
- (B) Dynamic scoping decides which variable a name means by looking along the chain of calls (deep access), or through a table of names (shallow access). Both work with stack frames, so no heap is needed.
- (D) Global variables are kept in static memory, so they need nothing more.
Dynamic data structures are different. Linked lists and trees are built at run time with malloc/new. Their memory must stay alive after a call ends, so it cannot depend on function calls. This means a heap is needed.
Answer: (C)
- (B) Dynamic scoping decides which variable a name means by looking along the chain of calls (deep access), or through a table of names (shallow access). Both work with stack frames, so no heap is needed.
- (D) Global variables are kept in static memory, so they need nothing more.
Dynamic data structures are different. Linked lists and trees are built at run time with malloc/new. Their memory must stay alive after a call ends, so it cannot depend on function calls. This means a heap is needed.
Answer: (C)
The program below uses six temporary variables a, b, c, d, e, f.
a =1
b= 10
c =20
d= a +b
e= c +d
f =c +e
b= c+ e
e =b +f
d =5 +e
return d +f
Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?
a =1
b= 10
c =20
d= a +b
e= c +d
f =c +e
b= c+ e
e =b +f
d =5 +e
return d +f
Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute this program without spilling?
Answer: (B)
A variable needs a register only while it is live (its value is used later). Live variables after each statement (counting the values that are held):
- before : are live (3). and are not used later, so they die here.
- after :
- after : (the old is never used again, because is set again later)
- after : (3 live together)
- after : ( and die, because the later is set again before it is used)
- after : ( dies)
- after : ( dies), then is returned.
At most 3 values are live at the same time, and 3 are live at some points, so 3 registers are needed.
Answer: (B)
- before : are live (3). and are not used later, so they die here.
- after :
- after : (the old is never used again, because is set again later)
- after : (3 live together)
- after : ( and die, because the later is set again before it is used)
- after : ( dies)
- after : ( dies), then is returned.
At most 3 values are live at the same time, and 3 are live at some points, so 3 registers are needed.
Answer: (B)