views:

131

answers:

3

I wonder how to determine the FIRST set of E with grammar:

E -> XYE | e
X -> x
Y -> y

Can anyone give me some direction?

+2  A: 
John Kugelman
A: 

Treat rules of the form A -> ...x... | ...y .... as two rules A -> ...x... and B -> ...y...

Form a set S initially containing rules of form E-> ....

then

Set a set P to empty.
Set a set F to empty.
Repeat until S is empty 
  Choose element of S, and call it R
  If R is in P, remove R from S
  Elsif R is of the form  A -> b ... 
    then { add b to F,
           add R to P,
           remove R from S}
  Else (R is the form A -> B ...)
     then  { place all rules of form B -> ... into S
             remove R from S}
End

WHen the loop terminates, F contains the tokens which are the First(F).

This does not take into account empty productions.

Ira Baxter
A: 

Fist thank you for answer my question
My friend for me answer that :
E-> XYE-> xYE. E-> XYE-> XyE ,E-> XYE-> XYXYE->XyXYE then : First(X)=y, First(Y)=x=>First(E)=y. But i'm not find to right.
i thing that :
E->e then add e to first(E)
X->x, then add x to first(E),
because epsilon number not in First(X) then end up
then First(E)={e,x}. but i'm not sure it right.

meoconbatchut