



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




S A B y A S y | x B y S I 0 = closure([S’.S]) = { S’.S, S .A B, A .S y, A .x}
GOTO(I 0 ,S) = closure([S’S. , A S.y]} = { S’S. , A S.y}= I (^1) GOTO(I 0 ,A) = closure([S A.B]) = { S A.B, B .y S} = I (^2) GOTO(I 0 ,x) = closure([A x.]) = { A x.} = I (^3) NowI we’re done with I 0 , so we move on to I 1. We need to compute GOTO on 1 for^ symbol^ y,^ the^ only^ symbol^ to^ the^ right^ of^ the^ “.”^ in^ I^1. GOTO(I 1 ,y) = closure([A S y.]) = { A S y.} = I (^4) Thisy. finishes I 1 , and we move on to I 2. We need GOTO for symbols B and GOTO(I 2 ,B)=closure([S A B. ])={ S A B. } = I (^5) GOTO(I 2 ,y)=closure([B y. S])={B y. S, S.A B, A.Sy, A.x}=I (^6) Nowneither we’re has done any with symbols I 2. (^) toNeither the right I 3 nor of Ithe 4 has dot. anything So we to move offer, on tosince I and compute GOTO for symbol y.^5 , Next we compute GOTO on I 6 for S, A, and x. GOTO(I 6 ,S)=closure([B y S., A S.y]) = { B y S., A S.y} = I (^7) GOTO(I(notice 6 ,A)=closure([S this gives us an A.Bitem ])={ set Swe’ve A.B already , B seen.y S} before) = I (^2) GOTO(I 6 ,x)=closure([A x.])={ A x.} = I (^3) I 7 has nothing to contribute, so we move on to I 8 on symbol y. GOTO(I 8 ,y) = closure([A S y.])={ A S y.} = I (^4)
The grammar is not SLR, since there is a shift / reduce conflict from stateTogether 8 on with symbol the y.fact This that comes from the two items AS.y and ByS.
FOLLOW(S) = {$,y} FOLLOW(A) = {y} FOLLOW(B) = {$,y}
I0: S’S (^) .AB.S AA .Sy.x
I1: S’A (^) S.yS.
I2: SB (^) .ySA.B
I3: A x. I4: A Sy. I5: A AB. I6: B y.S
SA .AB.Sy A .x I7: B yS. A S.y LR(1) ITEM SETS I0: S’S .S, $.AB, $/y AA .Sy, y.x, y I1: S’A S., $S.y, y I2: S A.B, $/y
B .yS, $/y I3: A x., y I4: A Sy., y I5: A AB., $/y I6: B y.S, $/y SA .AB, $/y.Sy, y A .x, y I7: BA yS., $/yS.y, y
GOTO(I 3 ,f) = closure([Df.,e],[Ef.,d])={[Df.,e],[Ef.,d]}= I (^9) This finishes GOTO on I 3. Using I 4 we only have one, for symbol d. GOTO(I 4 ,d) = closure([SdDd.,$]) = {[SdDd.,$]} = I (^10) Similarly, on I 5 we have GOTO(I 5 ,d) = closure([SdEe.,$]) = {[SdEe.,$]} = I (^11) For I 6 there is nothing to do. For I 7 we calculate GOTO(I 7 ,e). GOTO(I 7 ,e) = closure([SeDe.,$]) = {[SeDe.,$]} = I (^12) A similar calculation for I 8 yields GOTO(I 8 ,e) = closure([SeEd.,$]) = {[SeEd.,$]} = I (^13) ThisDFA looksfinishes like all this: the LR(1)item sets since no other I (^) j contributes. The
I0: S’S (^) .d D d.S SS .e D e.d E e S .e E d I1: S’ S. I2: SS (^) d.E ed.D d DE .f.f
I3: S e.D e SD e.E d.f E .f I4: S d D.d I5: S d E.e I6: DE f.f.
I7: S e D.e I8: S e E.d I9: S d D d. I10: S d E e. I11: S e D e. I12: S e E d.
I0: S’S .S, $.d D d, $ SS .e D e, $.d E e, $ S .e E d, $ I1: S’ S. , $ I2: SS d.D d , $d.E e, $ DE .f, d.f, e I3: S e.D e , $ SD e.E d, $.f, e E .f, d I4: S d D.d, $ I5: S d E.e, $ I6: DE f., df., e I7: S e D.e, $ I8: S e E.d, $ I9: DE f., ef., d I10: S d D d. , $ I11: S d E e. , $ I12: S e D e. , $ I13: S e E d. , $
Is the Grammar LR(1)?Why or Why Not? Which LR(1) sets areMerged for LALR(1)? Is the Grammar LALR(1)?Why or Why Not?
B1 | i^ +------------+ := n; | | t8:= i4 ; |+------------+*
B3 | jmax := 1; |^ +------------+ | j := 2;| t1 := j-2 || | t2 :=t14; |+------------+*
B5 | t2 :=t2+4; |+------------+ | t3:=x[t2]; || Rest of B5 | | from t4| down is || | Unchanged+------------+ |
B9 | t8 :=t8-4;+--------------+ | | temp:=x[t8]; || Rest of B9 | | from t10| down is || | Unchanged+--------------+ |