GATE CS 2024 Set 1 — Question 38
MCQ+2 / -0.67MediumFirst & Follow SetsSyntax AnalysisCompiler Design
Compiler Design → Syntax Analysis → First & Follow Sets
Last updated
Question
Consider the following grammar , with as the start symbol. The grammar has three incomplete productions denoted by (1), (2), and (3).The set of terminals is . The FIRST and FOLLOW sets of the different non-terminals are as follows..Which one of the following options CORRECTLY fills in the incomplete productions?
A.
(1) (2) (3)
B.
(1) (2) (3)
C.
(1) (2) (3)
D.
(1) (2) (3)
Correct answer
(A) (1) S arrow Rf (2) T arrow ε (3) R arrow cTR
Solution
We are given the FIRST sets for the non-terminals:
Let's analyze the incomplete productions based on these sets.1. Analyze Production (1) for :
The production contributes to .
The missing part (1) must contribute the remaining elements of , which are .
The existing productions contribute and to .
The missing part (2) must contribute to match .
The existing production contributes .
The missing part (3) must contribute to match .
Let's analyze the incomplete productions based on these sets.1. Analyze Production (1) for :
The production contributes to .
The missing part (1) must contribute the remaining elements of , which are .
- Option (B) & (C): . This starts with the terminal . Thus, it adds to , but it cannot add . So, (B) and (C) are incorrect.
- Option (A) & (D): . Since , this production adds (from ) and, because is nullable (), it also adds . Thus, contributes both and . This matches the requirement.
The existing productions contribute and to .
The missing part (2) must contribute to match .
- Option (A): . This correctly adds to .
- Option (D): . This would add to . However, is not in the given . Thus, (D) is incorrect.
The existing production contributes .
The missing part (3) must contribute to match .
- Option (A): . This starts with , satisfying the condition.
More questions on Syntax Analysis
2024 Set 2 Q21Consider the following two sets: | Set X | Set Y | | :--- | :--- | | P. Lexical Analyzer | 1.…2024 Set 1 Q26Which of the following is/are Bottom-Up Parser(s)?2024 Set 2 Q29Which of the following statements is/are FALSE?2024 Set 1 Q37Consider the following syntax-directed definition (SDD). | Production | Semantic Rules | | ------ |…2024 Set 1 Q39Consider the following pseudo-code. [code] Which one of the following options CORRECTLY specifies…
Practice GATE CS PYQs with adaptive difficulty
Timed practice, skill tracking, and AI explanations — free to start.
Start practicing free