Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm studying for a Compiler Construction module I'm doing and I have a sample question as follows:

Calculate the FIRST and FOLLOW sets for the following grammar..
S -> uBDz
B -> Bv
B -> w
D -> EF
E -> y
E -> ε 
F -> x
F -> ε

I have tried to figure it out so far but I'm a bit unsure if I'm correct. Could someone verify if I'm doing it right, and if not, what am I missing? My answer is below:

    FIRST   |   FOLLOW

S |  {u}    |   {$}
B |  {w}    | {y,x,v,z}
D | {y,ε,x} |   {z}
E |  {y,ε}  |  {x,z}
F |  {x,ε}  |   {z}
share|improve this question
I've checked your solution by hand and ran it in my parsing library, and it is correct. I'm not entirely sure how to answer your question. – Alex ten Brink Jan 19 at 18:31
Thanks for the confirmation on it being correct. I think I've figured it out but I'm in the same boat as you, can't really explain it. I id my exam and it seemed to go well anyway! – Aimee Jones Jan 19 at 22:54
When I said "I'm not entirely sure how to answer your question", I meant that I'm not sure how to 'prove' that your solution is really correct. I'm quite sure they are correct though, having implemented a compiler and multiple parsing algorithms myself. Anyway, I hope you did well on your exam. – Alex ten Brink Jan 19 at 23:39

1 Answer

I was using this page as a guide for anyone that's finding it difficult in future. It provides good step by step instructions for calculating the first and follow sets.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.