0

I have following grammar

E -> TX
X -> +E
     |epsilon
T -> intY
     | (E)
Y -> *T
     | epsilon

Is the below Follow set is correct for above grammar?

   E = {$, )}
   X = {$, )}
   T = {int, (, $}
   Y = {int, (, $}

2 Answers 2

1

First

First(E) -> {int, (}
First(X) -> {+, epl}
First(T) -> {int, (}
First(Y) -> {*, epl}

Follow

Follow(E) -> {$, )}
Follow(X) -> {Follow(E)}
Follow(T) -> {First(X) - epl, Follow(E)} -> {+, $, )} 
Follow(Y) -> {Follow(T)}

Why Follow(E) in Follow(T)? because First(X) has epsilon ->which give us E -> T production

Sign up to request clarification or add additional context in comments.

Comments

0

For the following grammar:

E -> TX

X -> +E |epsilon

T -> intY| (E)

Y -> *T| epsilon

Calculating the First of the set

FIRST(E) = FIRST(T) - epsilon U FIRST(X)

={int, (, +, epsilon }

FIRST(X) = FIRST(+E) - epsilon U epsilon

={+, epsilon}

FIRST(T) = FIRST(intY) - epsilon U FIRST( (E) )

={int, ( }

FIRST(Y) = FIRST(*T) - epsilon U epsilon

={*, epsilon}

Calculating of FOLLOW set

Follow(E) -> {$,)}

Follow(X) -> {$,)}

Follow(T) -> {+,$,)}

Follow(Y) -> {+,$,)}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.