Vous êtes sur la page 1sur 1

G4 :

I si B alors I sinon I I si B alors I I a B — b

On peut essayer de factoriser "si B alors I":


G'4 :
I - si B alors I I' I a
I' sinon I I 8
B-b

Eff = {I'} PREM(I) =

{si,a}
PREM(I') = {sinon}
PREM(B) ={b}

SUIV(I) = {$} U PREM(I') U SUIV(I') = {$, sinon}


SUIV(I') = SUIV(I)
SUIV(B) = {alors}

a b si alors sinon $
I I—a I — si B
alors I I'
I' B—b I' sinon I' - 8
E I
I' - 8

La grammaire n'est donc pas LL(1).

Solution : décider que l'on préférera systématiquement la règle I' sinon I, ce qui correspond à associer le sinon
avec le alors le plus proche, comme déjà vu par une autre méthode dans le TD n° 4.

Entrée Pile Opération/règle


si b alors si b alors a sinon a $ I$ I - si B alors I I'
si b alors si b alors a sinon a $ si B alors I I'$ dépiler
b alors si b alors a sinon a $ B alors I I'$ B—b
b alors si b alors a sinon a $ b alors I I'$ dépiler
alors si b alors a sinon a $ alors I I'$ dépiler
si b alors a sinon a $ I I'$ I — si B alors I I'
si b alors a sinon a $ si B alors I Dépiler
b alors a sinon a $ B alors I B—b
b alors a sinon a $ b alors I I'I'$ Dépiler
a sinon a $ alors I I'I'$ Dépiler
a sinon a $ I I'I'$ I— a
a sinon a $ Dépiler
sinon a $ I'I'$ I' — sinon I
sinon a $ sinon I I ' $ Dépiler
a$ I I' $ I—a
a$ a I' $ Dépiler
$ I' $ I' — 8
$ $ SUCCES

Vous aimerez peut-être aussi