Académique Documents
Professionnel Documents
Culture Documents
Mi Compilation-Analyse Lexicale Syntaxique PDF
Mi Compilation-Analyse Lexicale Syntaxique PDF
Mi Compilation-Analyse Lexicale Syntaxique PDF
Compilation
(INF 553)
Analyse syntaxique
François Pottier
30 janvier 2008
Pseudo-Pascal ASM
UPP LIN
Explicitation des
Allocation des registres
conventions d'appel
Grammaires algébriques
Analyse LL(1)
Analyse LR(1)
L’outil Menhir
Pipelining
Note
Grammaires algébriques
Analyse LL(1)
Analyse LR(1)
L’outil Menhir
Grammaires algébriques
Soient :
I Σ = {int, (, ), +, -, *, /}.
I V = {E}.
I S = E.
I L’ensemble P des productions est :
E → E+E
E → E-E
E → E*E
E → E/E
E → (E)
E → int
L(G) = {w ∈ Σ? | S →? w}
Exemples de dérivations
Arbres de dérivation
On peut préférer parler de dérivation en termes d’arbres et non en
termes de mots. Par exemple :
E E E
E + E E + E
E * E
E E E
E + E E + E E + E
Arbres de dérivation
E E
E + E E * E
int E * E E + E int
Ambiguı̈té
E → E+T T → T /F
E → E-T T → F
E → T F → (E)
T → T *F F → int
Remarque
Grammaires algébriques
Analyse LL(1)
Analyse LR(1)
L’outil Menhir
Principe
Exemple
E → E+T T → T /F
E → E-T T → F
E → T F → (E)
T → T *F F → int
Nouvelle modification
E → T E0 T → F T0
E0 → + T E0 T0 → * F T0
E0 → - T E0 T0 → / F T0
E0 → T0 →
F → int F → (E)
Quelques définitions
NULLABLE(a) ≥ faux
NULLABLE(A) ≥ NULLABLE(w) si (A → w) ∈ P
NULLABLE() ≥ vrai
NULLABLE(sw) ≥ NULLABLE(s) ∧ NULLABLE(w)
E → T E0 T → F T0
E0 → + T E0 T0 → * F T0
E0 → - T E0 T0 → / F T0
E0 → T0 →
F → int F → (E)
Les ensembles
Pourquoi LL(1) ?
Grammaires algébriques
Analyse LL(1)
Analyse LR(1)
L’outil Menhir
Principe
Principe
Construction LR(0)
Exemple
E → E+E
E → (E)
E → int
●E ε
ε
ε
ε ε
ε
E int (
+ E
E → E+●E E → (E●)
E )
E → E+E● E → (E)●
Interprétation de l’automate
Exemple d’exécution
Exemple d’exécution
Première possibilité : réduire.
Déterminisation
E → E+●E
E → ●E+E E +
E → ●E+E
E → ●(E) E → E●+E
E → ●(E)
E → ●int int E → ●int
int
( E → int●
E
int +
( +
E → (●E)
E → ●E+E E → (E●) E → E+E●
E → ●(E) E E → E●+E E → E●+E
E → ●int
) (conflit décaler/réduire)
( E → (E)●
Conflits LR(0)
De LR(0) à LR(1)
A → u • v [a]
Conflits LR(1)
LR(1) en pratique
E → E+E
E → (E)
E → int
Pourquoi LR(1) ?
Grammaires algébriques
Analyse LL(1)
Analyse LR(1)
L’outil Menhir
Menhir
Exemple de spécification
phrase :
e = expression ; EOF { e }
∗∗ The derivations that appear below have the following common factor :
∗∗ (The question mark symbol (?) represents the spot where the derivat
phrase
expression EOF
(?)
%left PLUS
Prudence !