Looking for follow set of Grammar in discrete math

62 Views Asked by At

$E\rightarrow Tx$
$x\rightarrow +E|$empty string
$T\rightarrow (E)|intY$
$Y\rightarrow*T|$empty string
I had hard time looking for follow set for $T$ and $Y$. Cause it will trace back to each other. If I do $Y$, then it will trace back to $T$ when $T$ trace back to $Y$. It is a loop. So how do I look for follow set under this circumstance? Thank you.

1

There are 1 best solutions below

0
On BEST ANSWER

I hope it can help you.

FOLLOW function

FOLLOW(A) is defined as the set of terminal symbols that appear immediately to the RHS of A.

  1. for the start symbol S place in FOLLOW(S).
  2. if there is a production $A \to \alpha B\beta$ then everything in FIRST$(\beta)$ without $\epsilon$ is to be placed in FOLLOW(B).
  3. if there is a production $A \to \alpha B\beta$ or $A \to \alpha B$ and FIRST$(\beta)=\{\epsilon\}$ then FOLLOW(A)=FOLLOW(B). that means everything in FOLLOW(A) is in FOLLOW(B).

$E\to TX \\ X\to+E|\epsilon \\ T\to(E)|intY \\ Y\to*T|\epsilon$

$E\to \underline {\text{T}}\text{X}\tag{ 2}$

FIRST [X]$-\{\epsilon\}$ $\subseteq $ FOLLOW [T]

{+} $\subseteq $FOLLOW [T]

$T\to (\underline{E})\tag{ 1,2}$

FIRST [ ) ]$-\{\epsilon\}$ $\subseteq $ FOLLOW [E]

{),\$} $\subseteq $FOLLOW [E]


$E\to \text{T}\underline{\text{X}}\tag{ 3}$

FOLLOW(E) $\subseteq$ FOLLOW(X)

$\bullet$ $\epsilon \in FISRT(X) $ so :

FOLLOW(E) $\subseteq$ FOLLOW(T)

$X\to \text{+}\underline{\text{E}}\tag{ 3}$

FOLLOW(X) $\subseteq$ FOLLOW(E)

$T\to \text{int}\underline{\text{Y}}\tag{ 3}$

FOLLOW(T) $\subseteq$ FOLLOW(Y)

$Y\to \text{*}\underline{\text{T}}\tag{ 3}$

FOLLOW(Y) $\subseteq$ FOLLOW(T)


  1. FOLLOW(E) $\subseteq$ FOLLOW(X)
  2. FOLLOW(X) $\subseteq$ FOLLOW(E)

FOLLOW(X) = FOLLOW(E) = $\{),\$\}$


  1. FOLLOW(T) $\subseteq$ FOLLOW(Y)
  2. FOLLOW(Y) $\subseteq$ FOLLOW(T)

FOLLOW(T) = FOLLOW(Y)

  1. {+} $\subseteq$ FOLLOW(T)
  2. FOLLOW(E) $\subseteq$ FOLLOW(T)

FOLLOW(T) = FOLLOW(Y) = $\{),\$,+\}$


(1) FOLLOW(A) $\subseteq$ FOLLOW(B) : FOLLOW( B ) contains at least the FOLLOW( A ) as a subset.

(2)First and Follow Sets Example