retagged by
1,964 views
3 votes
3 votes

is it correct?

retagged by

3 Answers

1 votes
1 votes
The grammar is left recursive.

Remove left recursion and then find FIRST and FOLLOW.
1 votes
1 votes
Taking gammer from your comment

E -> E+T | T
T -> T*F | F
F -> (E) | id

Remove left recursion first

E -> TE'
E'  -> +TE' | $\epsilon$
T -> FT'
T' -> *FT' | $\epsilon$
F -> (E) | id

First (E) = { (, id }          Follow (E ) = { dollar, ), + }
First (T) = { (, id }          Follow (T) =  { dollar, +,*, ) }
First (F) = { (, id }          Follow (F) = { dollar, +, *, ) }

All your answers are correct.
0 votes
0 votes

@`JEET I had made program for SLR1 and CLR1 last sem, there I had to find the first and follow without changing the grammar. That's why I used this approach.

Taking grammar from the comment 

E -> E+T | T
T -> T*F | F
F -> (E) | id

If a production symbol has left recursion then ignore for the first time and find FIRST for all the other productions of that symbol. And if that symbol contains EPSILON then find the FIRST of the production which had left recursion.

Example: 

First(E) = FIRST(T) = FIRST(F) = { (, id }

If F had EPSILON,then check again the first of E+T, then you will even get + in the FIRST(E).

Finding follow is simple.

Related questions

4 votes
4 votes
1 answer
1
1 votes
1 votes
1 answer
2
learner_geek asked Jul 31, 2017
1,972 views
How to solve recursive first or follow problems as example in second question (First of A) please give detailed explanation.
0 votes
0 votes
0 answers
3
Ana_101 asked 3 hours ago
3 views
S - A BA - f S fA - b b B dB - ƐB - cFirst(S) =First(A) =First(B) =Follow(S) =Follow(A) =Follow(B) =
0 votes
0 votes
1 answer
4
Sajal Mallick asked Oct 13, 2023
166 views
Does Follow and First operation always apply on non left recursive grammar?