GATE 2025 (Session 2)
65 questions
MCQ 32 · MSQ 18 · NAT 151-mark 30 · 2-mark 35
Questions 21–25 of 65
Consider the following statements about the use of backpatching in a compiler for intermediate code generation:
(I) Backpatching can be used to generate code for Boolean expression in one pass.
(II) Backpatching can be used to generate code for flow-of-control statements in one pass.
Which ONE of the following options is CORRECT?
(I) Backpatching can be used to generate code for Boolean expression in one pass.
(II) Backpatching can be used to generate code for flow-of-control statements in one pass.
Which ONE of the following options is CORRECT?
Answer: (C)
(I) Backpatching for Boolean expressions in one pass: TRUE — this is the main use of backpatching. At first, the jump targets in the and lists are left empty. They are filled in later, when the real target address is known. So no second pass is needed.
(II) Backpatching for flow-of-control statements (if/while) in one pass: also TRUE — the same method gives single-pass code for conditional and loop statements. The jump instructions are patched once the labels they need are decided.
Answer: Both (I) and (II) are correct.
(II) Backpatching for flow-of-control statements (if/while) in one pass: also TRUE — the same method gives single-pass code for conditional and loop statements. The jump instructions are patched once the labels they need are decided.
Answer: Both (I) and (II) are correct.
Given the following syntax-directed translation rules:
Which ONE is the CORRECT option among the following?
Which ONE is the CORRECT option among the following?
Answer: (C)
S-attributed means every attribute is synthesized, so it is computed only from the children. L-attributed means each inherited attribute of a child depends only on the parent's inherited attributes or on siblings to its left.
Rule 1 (): and are attributes of the children, and they are computed from and , so they are inherited. So the rule is not S-attributed. Also depends on , and is to the right of , so the dependency flows right to left. This breaks the L-attributed rule. Neither S-attributed nor L-attributed.
Rule 2 (): is an inherited attribute of the child , so the rule is not S-attributed. It depends only on , a left sibling, and is synthesized, so it is L-attributed. Not S-attributed, but L-attributed.
Rule 3 (): the only attribute defined is , computed from the children , so it is synthesized. S-attributed, and also L-attributed, since every S-attributed rule is L-attributed.
Answer: (C)
Rule 1 (): and are attributes of the children, and they are computed from and , so they are inherited. So the rule is not S-attributed. Also depends on , and is to the right of , so the dependency flows right to left. This breaks the L-attributed rule. Neither S-attributed nor L-attributed.
Rule 2 (): is an inherited attribute of the child , so the rule is not S-attributed. It depends only on , a left sibling, and is synthesized, so it is L-attributed. Not S-attributed, but L-attributed.
Rule 3 (): the only attribute defined is , computed from the children , so it is synthesized. S-attributed, and also L-attributed, since every S-attributed rule is L-attributed.
Answer: (C)
Consider a network that uses Ethernet and IPv4. Assume that IPv4 headers do not use any options field. Each Ethernet frame can carry a maximum of 1500 bytes in its data field. A UDP segment is transmitted. The payload (data) in the UDP segment is 7488 bytes.
Which ONE of the following choices has the CORRECT total number of fragments transmitted and the size of the last fragment including IPv4 header?
Which ONE of the following choices has the CORRECT total number of fragments transmitted and the size of the last fragment including IPv4 header?
Answer: (D)
An Ethernet frame can carry at most bytes in its data field. The IPv4 header bytes (no options). So each fragment can hold at most this much IP data: bytes. This is already a multiple of , so no more rounding is needed.
The UDP segment has a header of bytes payload of bytes, giving bytes. This becomes the data of the IP datagram, and it has to be fragmented:
. So there are full fragments of bytes each ( bytes in all), and one last fragment with bytes of data.
Total number of fragments: . The last fragment's total size, with its own -byte IP header, bytes.
Answer: 6 fragments, 116 bytes
The UDP segment has a header of bytes payload of bytes, giving bytes. This becomes the data of the IP datagram, and it has to be fragmented:
. So there are full fragments of bytes each ( bytes in all), and one last fragment with bytes of data.
Total number of fragments: . The last fragment's total size, with its own -byte IP header, bytes.
Answer: 6 fragments, 116 bytes
Which ONE of the following languages is accepted by a deterministic pushdown automaton?
Answer: (A)
A deterministic pushdown automaton (DPDA) accepts only the deterministic context-free languages (DCFLs). These form a proper subset of all context-free languages. Some CFLs, such as those where the machine must "guess" the midpoint of a string, are inherently non-deterministic. No DPDA can accept them. Only a general (non-deterministic) PDA can.
Every regular language can be recognized by a DFA. A DFA is also a valid DPDA that never uses its stack. So every regular language is accepted by some DPDA.
The other options are too broad, so a DPDA is not guaranteed to accept them. "Any context-free language" and "any NPDA-accepted language" mean the same, larger class, and the DPDA class is strictly smaller. "Any decidable language" is a far larger class, and it includes languages that are not even context-free.
Answer: Any regular language.
Every regular language can be recognized by a DFA. A DFA is also a valid DPDA that never uses its stack. So every regular language is accepted by some DPDA.
The other options are too broad, so a DPDA is not guaranteed to accept them. "Any context-free language" and "any NPDA-accepted language" mean the same, larger class, and the DPDA class is strictly smaller. "Any decidable language" is a far larger class, and it includes languages that are not even context-free.
Answer: Any regular language.
Let be Context-Free Grammars (CFGs) and be a regular expression. For a grammar , let denote the language generated by .
Which ONE among the following questions is decidable?
Which ONE among the following questions is decidable?
Answer: (D)
Check each question:
- Is ? Undecidable. If generates , the question asks whether generates everything. That is undecidable.
- Is ? Undecidable. It can be reduced from the Post Correspondence Problem, using two CFGs that generate the solutions of the two sides of a PCP instance.
- Is ? Undecidable. Take . Then the question asks whether (universality of a CFG), which is undecidable. So a question that includes this case cannot be easier.
- Is ? Decidable. Mark every non-terminal that has a production whose right side has only terminals and already marked non-terminals. Repeat until nothing new is marked. The language is empty exactly when the start symbol is never marked.
Answer: (D)
- Is ? Undecidable. If generates , the question asks whether generates everything. That is undecidable.
- Is ? Undecidable. It can be reduced from the Post Correspondence Problem, using two CFGs that generate the solutions of the two sides of a PCP instance.
- Is ? Undecidable. Take . Then the question asks whether (universality of a CFG), which is undecidable. So a question that includes this case cannot be easier.
- Is ? Decidable. Mark every non-terminal that has a production whose right side has only terminals and already marked non-terminals. Repeat until nothing new is marked. The language is empty exactly when the start symbol is never marked.
Answer: (D)