GATE 2011
81 questions
MCQ 811-mark 40 · 2-mark 41
Questions 41–45 of 81
The lexical analysis for a modern computer language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?
Answer: (A)
Regular expressions can describe tokens such as identifiers, numbers and keywords. So finite automata are all that is needed, and they are also required.
Answer: Finite state automata
Answer: Finite state automata
In a compiler, keywords of a language are recognized during
Answer: (C)
Keywords such as if, while and int are tokens. The lexical analyzer finds them when it breaks the source program into tokens.
Answer: the lexical analysis of the program
Answer: the lexical analysis of the program
Consider two binary operators ' 'and '' with the precedence of operator being lower than that of the operator . Operator is right associative while operator is left associative. Which one of the following represents the parse tree for expression (7 3 4 3 2)?
Answer: (B)
The operator has higher precedence and is right associative, so we group it as .
The operator is left associative, so we group it as .
Tree: the root is . Its right child is 2 and its left child is . This matches figure B.
Answer: B
The operator is left associative, so we group it as .
Tree: the root is . Its right child is 2 and its left child is . This matches figure B.
Answer: B
Consider evaluating the following expression tree on a machine with load-store architecture in which memory can be accessed only through load and store instructions. The variables a, b, c, d and e are initially stored in memory. The binary operators used in this expression tree can be evaluated by the machine only when the operands are in registers. The instructions produce result only in a register. If no intermediate results can be stored in memory, what is the minimum number of registers needed to evaluate this expression?
Answer: (D)
A binary operator needs both operands in registers, and a leaf must be loaded into a register first. So needs 2 registers, and needs 2 registers. For : evaluate first (2 registers, result in 1), then load into a second register. So it also needs 2 registers.
The root has two subtrees, and , and each needs 2 registers. Whichever is done first leaves its result in 1 register while the other subtree still needs 2 registers of its own. So 3 registers are needed at that point, and 2 are not enough.
Schedule:
- Load c and d (2 registers). c + d R1.
- Load e R2. e R1 R1 (1 register still in use).
- Load a and b into R2 and R3 (3 registers in use). a b R2. Then R2 + R1.
Answer: (D)
The root has two subtrees, and , and each needs 2 registers. Whichever is done first leaves its result in 1 register while the other subtree still needs 2 registers of its own. So 3 registers are needed at that point, and 2 are not enough.
Schedule:
- Load c and d (2 registers). c + d R1.
- Load e R2. e R1 R1 (1 register still in use).
- Load a and b into R2 and R3 (3 registers in use). a b R2. Then R2 + R1.
Answer: (D)
A thread is usually defined as a 'light weight process' because an operating system (OS) maintains smaller data structures for a thread than for a process. In relation to this, which of the followings is TRUE?
Answer: (C)
All threads of one process use the same address space. So the OS keeps virtual memory information for each process, not for each thread.
A thread still has its own registers, its own stack and its own scheduling state. This makes options 1, 2 and 4 wrong.
Answer: On per-thread basis, the OS does not maintain virtual memory state
A thread still has its own registers, its own stack and its own scheduling state. This makes options 1, 2 and 4 wrong.
Answer: On per-thread basis, the OS does not maintain virtual memory state