Which of the following statement(s) is/are TRUE while computing \(First \) and…
2025
Which of the following statement(s) is/are TRUE while computing \(First \) and \(Follow \) during top down parsing by a compiler?
- A.
For a production
\( 𝐴 → 𝜖, 𝜖\)will be added to\(𝐹𝑖𝑟𝑠𝑡(𝐴)\). - B.
If there is any input right end marker, it will be added to
\(𝐹𝑖𝑟𝑠𝑡(𝑆)\), where\(S\)is the start symbol. - C.
For a production
\(𝐴 → 𝜖, 𝜖\)will be added to\(𝐹𝑜𝑙𝑙𝑜𝑤(𝐴)\). - D.
If there is any input right end marker, it will be added to
\(𝐹𝑜𝑙𝑙𝑜𝑤(𝑆)\), where\(S\)is the start symbol.
Attempted by 134 students.
Show answer & explanation
Correct answer: A, D
Correct statements:
If a nonterminal has a production that derives the empty string (A → ε), then ε is included in First(A). Explanation: First(A) lists the terminals that can begin strings derived from A and also includes ε when A can derive the empty string.
The input right end marker (commonly $) is added to Follow(S) for the start symbol S. Explanation: Follow(S) contains symbols that can appear immediately after S; since nothing follows the start symbol in a complete sentential form, the end marker belongs to Follow(S).
Why the other statements are false:
The input right end marker is not added to First(S). First sets contain possible starting terminals (and possibly ε), while the end marker indicates the end of input and is not a starting terminal.
ε is not added to Follow(A). Follow sets list terminals (and possibly the end marker) that can appear immediately after A; ε is not such a terminal and therefore does not belong in Follow.
A video solution is available for this question — log in and enroll to watch it.