Search code examples
parsingcompiler-constructiongrammar

Confusion in finding follow of Gammar


I have confusion in finding follow of Grammar

S->(L)|a
L->L,S|S

Follow(L)={$ ,} or Follow(L)= {$}
Which one is right and why ?


Solution

  • Both are incorrect.

    FOLLOW(A) of non-terminal A is the set of terminal symbols 
    that can follow in the derivation sequence
    

    FOLLOW(L), check where it appears in the right hand side of productions. It is there in

                 S->(L)  
    

    when this production is considered for derivation, what follows L is ).

                L->L,S
    

    similarly, when this production is considered for derivation, what follows L is ,.

               FOLLOW(L) = {),,}