2 votes 2 votes Compute the FOLLOW set of $S$ for the following CFG : $S\rightarrow SPQR$ $P\rightarrow pPt/ \epsilon$ $Q\rightarrow qQ/\epsilon$ $R\rightarrow Rr/Qm/\epsilon $ Compiler Design compiler-design grammar first-and-follow + – Shivi rao asked Oct 28, 2017 edited Nov 7, 2023 by Hira Thakur Shivi rao 1.0k views answer comment Share Follow See all 10 Comments See all 10 10 Comments reply Show 7 previous comments Rishabh Gupta 2 commented Oct 29, 2017 reply Follow Share @Shivi You can't remove left recursion from it. A->Aa|b There is b, which let the A terminate. But in the given grammar, we do not have any terminating string. 1 votes 1 votes Shivi rao commented Oct 29, 2017 reply Follow Share What you think could be the ans to this 0 votes 0 votes Rishabh Gupta 2 commented Oct 29, 2017 reply Follow Share Hmm... I think it's wrong. But now I am confused too :/ We need an expert here... @Arjun Sir, @habibkhan 0 votes 0 votes Please log in or register to add a comment.
1 votes 1 votes follow of S=first of (PQR)={p,q,r,m,$} this should be the answer no problem in that follow of start symbol is always $ and take union of first of PQR and $ u get the answer here S is useless symbol no first of S abhishek tiwary answered Nov 3, 2017 edited Nov 3, 2017 by abhishek tiwary abhishek tiwary comment Share Follow See all 2 Comments See all 2 2 Comments reply Shivi rao commented Nov 3, 2017 reply Follow Share Could you please elaborate it...I am not getting 0 votes 0 votes AnilGoudar commented Nov 3, 2017 reply Follow Share S->SPQR P->pPt/ ϵ Q->qQ/ ϵ R->Rr/Qm/ ϵ S->SPQR From above, Follow(S) = First(PQR). Let's compute First(PQR). First(PQR) = First(P) = {p , epsilon} Hence, Follow(S) now will be = {p,} since First(P) is epsilon as P -> Epsilon, if we replace here, Follow(S) = First(PQR). Follow(S) = First(QR). //As P is replaced with epsilon. Continuing in the same way, First (QR) will be { q, epsilon}. Now, Follow(S) = First(R). //As Q is replaced with epsilon. Here is the tricky part, First(R) will be, 1) r due to production R -> Rr ( R will be replaced with epsilon) 2) m due to production R -> Qm ( Q will be replaced with epsilon as First of Q contains Epsilon) From above all, Follow of S = { p,q,r,m,dollar}. Dollar is by default is the follow of the start symbol. 2 votes 2 votes Please log in or register to add a comment.