First & Follow Sets Checks Simple Grammar

Here are a few questions that I asked in the quiz in the classroom and just want to check their correctness. Grammar:

S -> ABC
A -> df | epsilon
B -> f | epsilon
C -> g | epsilon

1.). Does the following set B contain g and epsilon (T / F)? Ans: F. Follow sets don't have epsilon, right? (Only $ aka end of input)

2.) Does the first set of S contain d, f, g, and epsilon (T / F)? Ans: T. I said this falsely because I thought that First (S) = First (A), which g is not part. Who is right?

+3
source share
1 answer
  • You're right. If epsilon is involved, it will be counted in the first set, not in the Follow set. If it is possible for the release to complete the line, then $ goes into the Follow set, not epsilon.
  • . S d, f g, . g. S, ? A , B , C - g. A, B C , S . , S, g, g First (S).
+4

Source: https://habr.com/ru/post/1708203/


All Articles