Académique Documents
Professionnel Documents
Culture Documents
Exercice 2
Exercice 3
Exercice 4
Peut-on mettre G3 sous forme LL(1) ? Peut-on néanmoins "déterminiser l'analyse" - par
un dispositif "ad hoc" ? interprétation ? (analyser : si b alors si b alors a sinon a en
produisant l’arbre d’analyse)
Exercice 5
Exercice 7
Exercice 1
1) anbcqd avec q≥n.
2) PREM(U) = {c,d}. PREM(S) = PREM(T) = {a,b}.
Table d’analyse
a b c d
S S → TU S → TU
T T → aTc T→ b
U U → cU U→ d
3) Simulation
abccd
abccd$ S$ S → TU
abccd$ TU$ T→ aTc
abccd$ aTcU$ Dépiler
bccd$ TcU$ T→ b
bccd$ bcU$ Dépiler
ccd$ cU$ Dépiler
cd$ U$ U → cU
cd$ cU$ Dépiler
d$ U$
U→ d
d$ d$ Dépiler
$ $ Succès
Dérivation :
S →TU → aTcU → abcU→ abccU→ abccd
aabcd
aabcd$ S$ S → TU
aabcd$ TU$ T → aTc
aabcd$ aTcU$ Dépiler
abcd$ TcU$ T → aTc
abcd$ aTccU$ Dépiler
bcd$ TccU$ T→ b
bcd$ bccU$ Dépiler
cd$ ccU$ Dépiler
d$ cU$ Clash - Echec
Exercice 2
- PREMIER :
• Eff = {E'} (variables effaçables)
• PREM(E) = PREM(F)
• PREM(E') = {+,-}
• PREM(F) = {-, (, id}
- SUIVANT
• au départ : SUIV(E) = { $ } les autres sont vides
• Règle 2 :
- SUIV(F) contient PREM(E')= {+,-}
- SUIV(E) contient ),
Au total : SUIV(F) = {+,-} et SUIV(E) ={), $}
• Règle 3 :
- Règle E F E' (E’ effaçable) : SUIV(E’) et SUIV(F) contiennent SUIV(E)
- Règles E’ + E et E’ - E : SUIV(E) contient SUIV(E’)
Au total :
- SUIV(E) = SUIV(E’) = SUIV(E) U SUIV(E’) de l’étape précédente = {),
$}
- SUIV(F) = SUIV(F) de l’étape précédente U SUIV(E’) = {+,-, ), $}
- TABLE D'ANALYSE
+ - ( ) id $
E E F E' E F E' E F E'
E' E' + E E' - E E' ε E' ε
F F-F F(E) F id
- Analyse de : - id - id
- Analyse de : - id - + id
Jusqu'à la dernière ligne, c'est la même chose.
Exercice 3
Deux problèmes : 1) G2 est récursive à gauche (récursion directe sur L) et 2) PREM( (L)
) et PREM( () ) contiennent tous deux (.
Eff = {L'}
PREM(S) = {(,at}
PREM(S') = PREM(L) U {)} = {(,),at}
PREM(L) = PREM(L') = PREM(S) = {(,at}
SUIVANT :
• Etape 1 : SUIV(S) = {$}
• Etape 2 :
- SUIV(L) contient {)}
- SUIV(S) contient PREM(L’)
Au total : SUIV(L) = {)}, SUIV(S) = {$, (, at}, les autres toujours vide
• Etape 3 :
- SUIV(S’) contient SUIV(S) (première règle)
- SUIV(L’) contient SUIV(L) (règle pour L)
- SUIV(S) contient SUIV(L) (règle pour L avec L’ effaçable)
- SUIV(S) contient SUIV(L’) (règle pour L ‘ avec L’ effaçable)
Au total : SUIV(L’) = SUIV(L) = {)}, SUIV(S’) = SUIV(S) = {$, (, at, )},
PREMIER SUIVANT
S ( at ( ) at $
S' ( ) at ( ) at $
L ( at )
L' ( at )
- Table d'analyse
( ) at $
S S ( S' S at
S' S' L) S' ) S' L)
L L S L' L S L'
L' L' S L' L' ε L' S L'
Exercice 4
G4 :
I si B alors I sinon I | si B alors I | a
Bb
Eff = {I'}
PREM(I) = {si,a}
PREM(I') = {sinon}
PREM(B) ={b}
a b si alors sinon $
I Ia I si B
alors I I'
E Bb
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.
a sinon a $ I I’I’$ I a
a sinon a $ a I’I’$ Dépiler
$ I’ $ I’ ε
$ $ SUCCES
Exercice 5
(a) Pour tout couple de productions Aw1 et Aw2, (w1 et w2 non vides) PREM(w1)
et PREM(w2) sont disjoints (pas de conflit entre 2 règles non vides).
(b) Si A est effaçable pour toute production Aw (w non vide) PREM(w) et SUIV(A)
sont disjoints (pas de conflit entre un effacement de A et une règle non vide).
Impossible : le langage parenthésé induit par (E) ne peut être reconnu par un automate.
Dans les 2 cas précédent, ce qui « marche » c’est que l’on peut reconnaître par un
automate le langage qui « mène » à un jeton discriminant (+ ,- $)
grammar LLetoile;
| facteur ;
ID : (('a'..'z')|('A'..'Z'))+ ;
NB : ('0'..'9')+ ;
Exercice 7
S ( S' | at
S' L) | )
L S L'
L' S L' | ε
Eff = {L'}
L’ apparaît dans la règle pour L. On la « duplique » et on supprime règle L’ ε Idem
pour L’.
S ( S' | at
S' L) | )
L S L' | S
L' S L' | S
On peut évidemment simplifier les 2 dernières règles :
S ( S' | at
S' L) | )
LSL|S
Remarque : on a réintroduit le non-déterminisme !