Solution
The correct answer is {z, x}
Explanation:
To find the Follow set of the non-terminal R in the given grammar, we will analyze the production rules.
Grammar:
1. T → Qx
2. Q → RS
3. R → y | ϵ
4. S → z | ϵ
Step 1: Identify the rules involving R
From the production Q → RS :
- R appears before S , and we need to determine what can follow R .
Step 2: Determine Follow set of R
1. Check the Follow of Q :
- From T → Qx , the Follow of Q includes x .
- Thus, Follow(Q) = {x} .
2. From Q → RS :
- The symbols that can follow R are the symbols in the Follow set of S .
Step 3: Determine Follow of S
1. Check the productions for S :
- From S → z | ϵ :
- If S produces ϵ , we also consider what follows S in Q .
2. Follow of S :
- From Q → RS :
- The symbols that can follow S include the Follow of Q , which is x (from T ).
- Thus, Follow(S) = {x} .
Step 4: Combine results for R
Since S can produce ϵ :
- The Follow set of R will include everything in Follow(S) plus anything that follows Q .
- Therefore, the Follow set of R includes:
- The Follow of S : x
- The Follow of Q : Since R is at the end of Q , we include whatever follows Q .
Final Step: Conclusion
Combining all the above information, the Follow set of R is: Follow(R) = {z, x}
However, since R produces y (and indirectly through Q ), and because R is followed by S which can produce ϵ , we include z in Follow of R .
Thus, the correct answer is: 3) {z, x}