I am doing an exercise to create FIRST and FOLLOW sets for a grammar. I think what I did is correct but the answer is slightly different from mine. So need help from someone to verify this. Thank you. The grammar is :
P -> L
L -> I X
X -> ; L | EPSILON
I -> A | C | W
A -> id := E
C -> if E then L O endif
O -> else L | EPSILON
W -> while E do L end
E -> E2 R
R -> Op1 E2 R | EPSILON
E2 -> T S
S -> Op2 E2 | EPSILON
T -> c | id
Op1 -> < | = | !=
Op2 -> + | -
EPSILON is the real 'epsilon' And here is my answer the FIRST set for X:
FIRST(; L) = {;}
FOLLOW(X) = {$, else, end, endif}
But the answer given is:
FIRST(; L) = {;}
FOLLOW(X) = {$, else, end, endif, then}
Can someone please verify which one is the correct answer?Thanks :)