First and Follow Sets for a Grammar

Posted by Aimee Jones on Programmers See other posts from Programmers or by Aimee Jones
Published on 2013-01-03T01:48:47Z Indexed on 2013/11/11 22:12 UTC
Read the original article Hit count: 249

Filed under:
|
|

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 -> e 
F -> x
F -> e

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,e,x} |   {z}
E |  {y,e}  |  {x,z}
F |  {x,e}  |   {z}

© Programmers or respective owner

Related posts about compilers

Related posts about parsing