SlideShare a Scribd company logo
ALF
Parser Top-Down
Bibliographie pour aujourd'hui
Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey
D. Ullman, Compilers: Principles, Techniques,
and Tools (2nd Edition)
– Chapitre 4
• 4.4
Contenu
• Les parser
• LL
Alexander Aiken
• Américain
• Stanford
• LL(*)
• MOSS
• ANTLR
Slides
Partie de slides sont écrie par
Bogdan Nitulescu
Notation BNF
RFC 2616 HTTP/1.1 June 1999
HTTP-date = rfc1123-date | rfc850-date | asctime-date
rfc1123-date = wkday "," SP date1 SP time SP "GMT“
rfc850-date = weekday "," SP date2 SP time SP "GMT“
asctime-date = wkday SP date3 SP time SP 4DIGIT
date1 = 2DIGIT SP month SP 4DIGIT
; day month year (e.g., 02 Jun 1982)
date2 = 2DIGIT "-" month "-" 2DIGIT
; day-month-year (e.g., 02-Jun-82)
date3 = month SP ( 2DIGIT | ( SP 1DIGIT ))
; month day (e.g., Jun 2)
time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
; 00:00:00 - 23:59:59
wkday = "Mon" | "Tue" | "Wed“
| "Thu" | "Fri" | "Sat" | "Sun“
weekday = "Monday" | "Tuesday" | "Wednesday“
| "Thursday" | "Friday" | "Saturday" | "Sunday“
month = "Jan" | "Feb" | "Mar" | "Apr“
| "May" | "Jun" | "Jul" | "Aug"
| "Sep" | "Oct" | "Nov" | "Dec"
Arbre de dérivation / syntactique
E  E + E
E  E * E
E  n
n : [0-9]+
Lexer
2 * 3 + 4 * 5
n * n + n * n
2 3 4 5
parser
n n n n
2 3 4 5
* *
+
n n n n
2 3 4 5
E * E E * E
E + E
E
• jetons (tokens)
• Valeurs
• Grammaire
• Arbre de dérivation
• Arbre syntactique
Types d’analyse syntactique
 Descendent (top-down)
 Avec backtracking
 Prédictive
 Descendent récursive, LL avec un tableau
 Ascendant (bottom-up)
 Avec backtracking
 Shift-reduce
 LR(0),SLR,LALR, LR canonique
–Instr
–id = Expr ;
–id = ( Expr ) ;
–id = ( Expr + Expr ) ;
–id = ( id + Expr ) ;
–id = ( id + id ) ;
id = ( id + id ) ;
id = ( id + id ) ;
id = ( id + id ) ;
id = ( id + id ) ;
id = ( id + id ) ;
id = ( id + id ) ;
• LL: La chaîne de jetons est itérée à partir du côté
gauche (L)
• Le non-terminal le plus à gauche est dérivé (L)
Dérivation gauche, top down
–Instr
–id = Expr ;
–id = Expr + Expr ;
–id = ( Expr ) + Expr ;
–id = ( id ) + Expr ;
–id = ( id ) + ( Expr ) ;
–id = ( id + id ) ;
id = ( id ) + ( id ) ;
id = ( id ) + ( id ) ;
id = ( id ) + ( id ) ;
id = ( id ) + ( id ) ;
id = ( id ) + ( id ) ;
id = ( id ) + ( id ) ;
id = ( id ) + ( id ) ;
• Comment choisir la production utilisée pour la
dérivation?
• Backtracking?
Dérivation gauche, top down
Parser LL, LR
 Nous devrions éviter backtracking
 Une grammaire qui permet le parser déterministe
 LL(k) lit left-to-right, dérivation left
 LR(k) lit left-to-right, dérivation right
 K – lookahead (combien de tokens sont lus)
 LL(k) < LR(k)
 L'algorithme est indépendant du langage, la
grammaire dépend du langage
Analyse descendent récursive
 Non-terminal -> fonction
 Si le symbole apparaît dans la partie droite
de production -> appel la fonction
 Si le symbole apparaît dans la partie
gauche de production – la production est
choisi en fonction des jetons (tokens)
suivants (lookahead)
MatchToken (token) {
if (lookahead != token) throw error();
lookahead = lexer.getNextToken();
}
rfc850-date = weekday "," SP date2 SP time SP "GMT“
ParseRFC850Date() {
ParseWeekDay();
MatchToken(",");
MatchToken(SP);
ParseDate2();
MatchToken(SP);
ParseTime();
MatchToken(SP);
MatchToken("GMT“);
}
Fonction pour parser le non-
terminal rfc850-date
Analyse descendent récursive
Avec la grammaire
E  E + T | T
T  T  F | F
F  ( E ) | id
Un parser descendant entre dans une boucle infinie
lorsque vous essayez de parser cette grammaire
E E
+E T
E
+E T
+E T
E
+E T
+E T
+E T
(Aho,Sethi,Ullman, pp. 176)
Récursivité gauche
Grammaire des
expression
E  E + T | T
T  T  F | F
F  ( E ) | id
Peut être écrive sans la récursivité gauche
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
(Aho,Sethi,Ullman, pp. 176)
ε – string vide
Récursivité gauche
Exemple de parser récursive
ParseE() {
ParseT(); ParseE1();
}
ParseE1() {
if (lookahead==“+”)
{
MatchToken(“+”);
ParseT();
ParseE1();
}
}
ParseT() {
ParseF(); ParseT1();
}
ParseT1() {
if (lookahead==“*”)
{
MatchToken(“*”);
ParseF();
ParseT1();
}
}
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
ParseF() {
if (lookahead == “(“) {
MatchToken(“(“); ParseE(); MatchToken(“)”);
}
else
MatchToken(T_ID);
}
Comment choisir entre deux productions?
Comment pouvons-nous savoir quelles conditions de poser
a if?
Lorsque nous émettons des erreurs?
ParseF() {
if (lookahead == “(“) {
MatchToken(“(“);
ParseE();
MatchToken(“)”);
}
else if (lookahead == T_ID)
{
MatchToken(T_ID);
}
else throw error();
}
F  ( E )
F  id
T’  *FT’
T’  ε
ParseT1() {
if (lookahead==“*”) {
MatchToken(“*”);
ParseF();
ParseT1();
}
else if (lookahead == “+”) { }
else if (lookahead == “)”) { }
else if (lookahead == T_EOF) { }
else throw error();
}
Analyse descendent récursive
Les conditions pour if
• FIRST
– Ensemble de terminaux-préfixées pour le non-terminal
• FOLLOW
– Ensemble de terminaux suivantes pour le non-terminal
• NULLABLE
– Ensemble de non-terminaux qui peut etre derive en ε
FIRST
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
1. If X is a terminal, FIRST(X) = {X}
FIRST(id) = {id}
FIRST() = {}
FIRST(+) = {+}
ENSEBLES:
2. If X   , then   FIRST(X)
4. If X  Y1 Y2 ••• Yk
FIRST(() = {(}
FIRST()) = {)}
FIRST (pseudocode):
and a FIRST(Yi)
then a  FIRST(X)
FIRST(F) = {(, id}
FIRST(T) = FIRST(F) = {(, id}
FIRST(E) = FIRST(T) = {(, id}
FIRST(E’) = {} {+, }
FIRST(T’) = {} {, }
(Aho,Sethi,Ullman, pp. 189)
*
3. If X  Y1 Y2 ••• Yk
and Y1••• Yi-1 
and a FIRST(Y1)
then a  FIRST(X)
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
1. If S is the start symbol, then $  FOLLOW(S)
FOLLOW(E) = {$}
FOLLOW(E’) = { ), $}
ENSEBLES:
2. If A  B,
and a  FIRST()
and a  
then a  FOLLOW(B)
3. If A  B
and a  FOLLOW(A)
then a  FOLLOW(B)
FOLLOW – pseudocode:
{ ), $}
3a. If A  B
and
and a  FOLLOW(A)
then a  FOLLOW(B)
*  
FOLLOW(T) = { ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
 et  - string de terminaux et non-
terminaux
A et B – non-terminaux,
$ - fin du text
(Aho,Sethi,Ullman,
pp. 189)
FOLLOW
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
1. If S is the start symbol, then $  FOLLOW(S)
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
3. If A  B
and a  FOLLOW(A)
then a  FOLLOW(B)
3a. If A  B
and
and a  FOLLOW(A)
then a  FOLLOW(B)
*  
FOLLOW(T) = { ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
2. If A  B,
and a  FIRST()
and a  
then a  FOLLOW(B)
{+, ), $}
(Aho,Sethi,Ullman, pp. 189)
GRAMMAIRE:
ENSEBLES:
FOLLOW – règles:
FOLLOW
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
1. If S is the start symbol, then $  FOLLOW(S)
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW(T) = {+, ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
2. If A  B,
and a  FIRST()
and a  
then a  FOLLOW(B)
3. If A  B
and a  FOLLOW(A)
then a  FOLLOW(B)
FOLLOW(T’) = {+, ), $}
3a. If A  B
and
and a  FOLLOW(A)
then a  FOLLOW(B)
*  
(Aho,Sethi,Ullman, pp. 189)
GRAMMAIRE:
ENSEBLES:
FOLLOW – règles:
FOLLOW
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
1. If S is the start symbol, then $  FOLLOW(S)
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW(T) = {+, ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
2. If A  B,
and a  FIRST()
and a  
then a  FOLLOW(B)
3. If A  B
and a  FOLLOW(A)
then a  FOLLOW(B)
FOLLOW(T’) = {+, ), $}
3a. If A  B
and
and a  FOLLOW(A)
then a  FOLLOW(B)
*  
FOLLOW(F) = {+, ), $}
(Aho,Sethi,Ullman, pp. 189)
GRAMMAIRE:
ENSEBLES:
FOLLOW – règles:
FOLLOW
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
1. If S is the start symbol, then $  FOLLOW(S)
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW(T) = {+, ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
3. If A  B
and a  FOLLOW(A)
then a  FOLLOW(B)
FOLLOW(T’) = {+, ), $}
3a. If A  B
and
and a  FOLLOW(A)
then a  FOLLOW(B)
*  
FOLLOW(F) = {+, ), $}
2. If A  B,
and a  FIRST()
and a  
then a  FOLLOW(B)
{+, , ), $}
(Aho,Sethi,Ullman, pp. 189)
GRAMMAIRE:
ENSEBLES:
FOLLOW – règles:
FOLLOW
L’algo générique récursive LL(1)
A  a B … x
A  C D … y
…
ParseA() {
if (lookahead in FIRST(a B … x FOLLOW(A)) {
MatchToken(a); ParseB(); … MatchToken(x);
}
else if (lookahead in FIRST(C D … y FOLLOW(A))
{
ParseC(); ParseD(); … MatchToken(y);
}
…
else throw error();
}
• Pour chaque non-terminal crée une fonction de parser.
• Pour chaque règle Aα ajouter un test
if (lookahead in FIRST(αFOLLOW(A)) )
• Pour chaque non-terminal dans a appeler la fonction de parser.
• Pour chaque terminal dans a, vérifier le lookahead(match)
Récursivité gauche
Quand une grammaire a au moins une forme de production
A  Aα
nous disons qu'il est une grammaire récursive gauche.
Le parsers descendent ne fonctionnent pas (sans
backtracking) sur les grammaire récursives gauche.
(Aho,Sethi,Ullman, pp. 176)
Récursivité peut ne pas être immédiat
A  Bα
B  A β
Elimination récursivité gauche
• Cela se fait par la réécriture de la
grammaire
E  E + T | T
T  T  F | F
F  ( E ) | id
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
(Aho,Sethi,Ullman, pp. 176)
List  List Item | Item
List  Item List’
List’  Item List’ | ε
Cas général (récursivité immédiat):
A → Aβ1 |Aβ2 | ... |Aβm | α1 | α2 | ... | αn
A → α1A' | α2A' | ... | αnA‘
A' → β1A' | β2A' | ... | βmA'| ε
E  E + T | T
T  T  F | F
F  ( E ) | id
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
Elimination récursivité gauche
• Pour une instruction if:
• Pour parser avec LL, elle doit être factorise:
Factorisation gauche
 Cas général:
A → αβ1 | αβ2 | ... | αβn | δ
 Factorise:
A → αA' | δ
A' → β1 | β2 | ... | βn
Factorisation gauche
Elimination des ambiguïtés
 Ambigu: Ε → Ε + Ε | Ε * Ε | a | ( E )
1. Ε → Ε + T | T
T → T * F | F
F → a | ( E )
2. Ε → T + E | T
T → F * T | F
F → a | ( E )
 La précédence des operateurs
 La associativité gauche ou droite
 Productions qui peuvent produire l'ambiguïté:
X → aAbAc
 Cas général:
A → A B A | α1 | α2 | ... | αn
 Désambiguïsât:
A → A' B A | A‘
A' → α1 | α2 | ... | αn
Elimination des ambiguïtés
Parser automatique
• Automate push-down
• Le parser est fait avec un automate est un
tableau
• Langage LL(1) si il n'a pas de conflits dans
le tableau
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
Grammaire:
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’+TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
Tableau
de
Parsing:
(Aho,Sethi,Ullman, pp. 188)
Exemple de parser LL
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
PILE:
id idid+ INPUT:
Predictive Parsing
Program
E
$
$ OUTPUT:
E
T
E’
$
T E’
TABLEAU
DE
PARSING:
Exemple de parser LL
T
E’
$
T
E’
$
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
id idid+ INPUT:
Predictive Parsing
Program
$ OUTPUT:
E
F
T’
E’
$
F T’
T E’
(Aho,Sethi,
Ullman,
pp. 186)
PILE:
TABLEAU
DE
PARSING:
Exemple de parser LL
(Aho,Sethi,
Ullman,
pp. 188)
T
E’
$
T
E’
$
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
id idid+ INPUT:
Predictive Parsing
Program
$ OUTPUT:
E
F
T’
E’
$
F T’
T E’
id
T’
E’
$
id
PILE:
TABLEAU
DE
PARSING:
Exemple de parser LL
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
id idid+ INPUT:
Predictive Parsing
Program
$ OUTPUT:
E
T’
E’
$
F T’
T E’
id
Quand l’action c’est Top(Pile) = input ≠ $ : ‘Pop’ de la pile, avance la bande de input.
(Aho,Sethi,
Ullman,
pp. 188)
PILE:
TABLEAU
DE
PARSING:
Exemple de parser LL
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
id idid+ INPUT:
Predictive Parsing
Program
$ OUTPUT:
E
F T’
T E’
id 
T’
E’
$
E’
$
(Aho,Sethi,
Ullman,
pp. 188)
PILE:
TABLEAU
DE
PARSING:
Exemple de parser LL
E
F T’
T E’
id 
T+ E’
F T’
id F T’
id 

Et ainsi, il construit
l’arbre de dérivation:
E’  +TE’
T  FT’
F  id
T’   FT’
F  id
T’  
E’  
Quand Top(Pile) = input = $
Le parser arrêt et accepte l’input
(Aho,Sethi,
Ullman,
pp. 188)
Exemple de parser LL
Remplir de tableau
• FIRST
– Ensemble de terminaux-préfixées pour le non-terminal
• FOLLOW
– Ensemble de terminaux suivantes pour le non-terminal
• NULLABLE
– Ensemble de non-terminaux qui peut etre derive en ε
Reguli pentru construit tabela de parsare
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
TABLEAU
DE
PARSING:
1. If A  :
if a  FIRST(), add A   to M[A, a]
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)
1. If A  :
if a  FIRST(), add A   to M[A, a]
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
TABLEAU
DE
PARSING:
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
1. If A  :
if a  FIRST(), add A   to M[A, a]
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
TABLEAU
DE
PARSING:
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
TABLEAU
DE
PARSING:
1. If A  :
if a  FIRST(), add A   to M[A, a]
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
1. If A  :
if a  FIRST(), add A   to M[A, a]
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
TABLEAU
DE
PARSING:
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
1. If A  :
if a  FIRST(), add A   to M[A, a]
2. If A  :
if   FIRST(), add A   to M[A, b]
for each terminal b  FOLLOW(A),
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
TABLEAU
DE
PARSING:
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
1. If A  :
if a  FIRST(), add A   to M[A, a]
2. If A  :
if   FIRST(), add A   to M[A, b]
for each terminal b  FOLLOW(A),
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
TABLEAU
DE
PARSING:
E  TE’
E’  +TE’ | 
T  FT’
T’  FT’ | 
F  ( E ) | id
GRAMMAIRE:
FOLLOW(E) = {), $}
FOLLOW(E’) = { ), $}
FOLLOW SETS:
FOLLOW(T) = {+, ), $}
FOLLOW(T’) = {+, ), $}
FOLLOW(F) = {+, , ), $}
FIRST(F) = {(, id}
FIRST(T) = {(, id}
FIRST(E) = {(, id}
FIRST(E’) = {+, }
FIRST(T’) = { , }
FIRST SETS:
1. If A  :
if a  FIRST(), add A   to M[A, a]
2. If A  :
if   FIRST(), add A   to M[A, b]
for each terminal b  FOLLOW(A),
3. If A  :
if   FIRST(), and $  FOLLOW(A),
add A   to M[A, $]
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’  E’ 
T TFT’ TFT’
T’ T’ T’ *FT’ T’  T’ 
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
TABLEAU
DE
PARSING:
Utilisation de parser LL(1)
 Grammaires
 Non ambigu
 Factorise
 Non récursive a gauche
 On peut montrer que la grammaire G est LL (1) si et
seulement si pour deux productions de la forme
A  , A  , avec    les conditions suivantes
sont satisfaites:
 FIRST()  FIRST() = 
 Si  * ε alors FIRST()  FOLLOW(A) = et si  * ε
alors FIRST()  FOLLOW(A) = .
Avantage/désavantage LL(1)
 Facile de écrive ‘aux main’
 Vite, facile de comprendre
 La grammaire doit être transforme
 L’arbre de dérivation et diffèrent de l’arbre sémantique
E
F T’
T E’
id 
T+ E’
F T’
id F T’
id 

E
F
T
TE
id
+
F
id
F
id
T
Parser LL
• ANTLR
– Java
– LL (*)
– Factorisation
Règles EBNF
Something?
Something*
Something+
SomethingQ -> ε
| Something
SomethingStar -> ε
| Something SomethingStar
SomethingPlus ->
Something SomethingStar
Sujets
• Les parser
• LL
– Eviter l’ambiguïté
– Factorisation
– Eviter la récursivité gauche
• Algorithme général récursive LL
Questions

More Related Content

What's hot

Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
wahab khan
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorial
Nilt1234
 
Application of Stacks
Application of StacksApplication of Stacks
Application of Stacks
Ain-ul-Moiz Khawaja
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
Lisp
LispLisp
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
Ravi Rao
 
Parsing example
Parsing exampleParsing example
Parsing example
Shraddha Patel
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
DivyeshKumar Jagatiya
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
maamir farooq
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfixSenthil Kumar
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
David Gu
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
Dabbal Singh Mahara
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
Self-Employed
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7Kumar
 

What's hot (18)

Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence) Advance LISP (Artificial Intelligence)
Advance LISP (Artificial Intelligence)
 
Lisp tutorial
Lisp tutorialLisp tutorial
Lisp tutorial
 
Application of Stacks
Application of StacksApplication of Stacks
Application of Stacks
 
Stack
StackStack
Stack
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Lisp
LispLisp
Lisp
 
(Ai lisp)
(Ai lisp)(Ai lisp)
(Ai lisp)
 
Parsing example
Parsing exampleParsing example
Parsing example
 
Stack Operation In Data Structure
Stack Operation In Data Structure Stack Operation In Data Structure
Stack Operation In Data Structure
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
My lecture infix-to-postfix
My lecture infix-to-postfixMy lecture infix-to-postfix
My lecture infix-to-postfix
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Stack
StackStack
Stack
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Infix prefix postfix
Infix prefix postfixInfix prefix postfix
Infix prefix postfix
 
Data structure lecture7
Data structure lecture7Data structure lecture7
Data structure lecture7
 

Similar to ALF 5 - Parser Top-Down (2018)

Top down and botttom up 2 LATEST.
Top down     and botttom up 2 LATEST.Top down     and botttom up 2 LATEST.
Top down and botttom up 2 LATEST.
Gerwin Ocsena
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 
compiler-lecture-6nn-14112022-110738am.ppt
compiler-lecture-6nn-14112022-110738am.pptcompiler-lecture-6nn-14112022-110738am.ppt
compiler-lecture-6nn-14112022-110738am.ppt
SheikhMuhammadSaad3
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
Siddhesh Pange
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniques
d72994185
 
LL(1) Parsers
LL(1) ParsersLL(1) Parsers
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
KHYATI PATEL
 
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPTCh4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
FutureTechnologies3
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx
venkatapranaykumarGa
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
Akhil Kaushik
 
7-parsing-error and Jake were centered at Gondar began
7-parsing-error and Jake were centered at Gondar began7-parsing-error and Jake were centered at Gondar began
7-parsing-error and Jake were centered at Gondar began
KiyaMama
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
ASHOK KUMAR REDDY
 
関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡
Naoki Kitora
 
11CS10033.pptx
11CS10033.pptx11CS10033.pptx
11CS10033.pptx
ssuser0be977
 

Similar to ALF 5 - Parser Top-Down (2018) (20)

Top down and botttom up 2 LATEST.
Top down     and botttom up 2 LATEST.Top down     and botttom up 2 LATEST.
Top down and botttom up 2 LATEST.
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
compiler-lecture-6nn-14112022-110738am.ppt
compiler-lecture-6nn-14112022-110738am.pptcompiler-lecture-6nn-14112022-110738am.ppt
compiler-lecture-6nn-14112022-110738am.ppt
 
Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniques
 
LL(1) Parsers
LL(1) ParsersLL(1) Parsers
LL(1) Parsers
 
Left factor put
Left factor putLeft factor put
Left factor put
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
 
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPTCh4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
 
6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx6-Practice Problems - LL(1) parser-16-05-2023.pptx
6-Practice Problems - LL(1) parser-16-05-2023.pptx
 
Ch5b
Ch5bCh5b
Ch5b
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Ch8b
Ch8bCh8b
Ch8b
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
 
Bottomupparser
BottomupparserBottomupparser
Bottomupparser
 
7-parsing-error and Jake were centered at Gondar began
7-parsing-error and Jake were centered at Gondar began7-parsing-error and Jake were centered at Gondar began
7-parsing-error and Jake were centered at Gondar began
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡関数プログラミングことはじめ in 福岡
関数プログラミングことはじめ in 福岡
 
Ch8a
Ch8aCh8a
Ch8a
 
11CS10033.pptx
11CS10033.pptx11CS10033.pptx
11CS10033.pptx
 

More from Alexandru Radovici

SdE2 - Pilot Tock
SdE2 - Pilot TockSdE2 - Pilot Tock
SdE2 - Pilot Tock
Alexandru Radovici
 
SdE2 - Systèmes embarquées
SdE2 - Systèmes embarquéesSdE2 - Systèmes embarquées
SdE2 - Systèmes embarquées
Alexandru Radovici
 
SdE2 - Planification, IPC
SdE2 - Planification, IPCSdE2 - Planification, IPC
SdE2 - Planification, IPC
Alexandru Radovici
 
ALF1 - Introduction
ALF1 - IntroductionALF1 - Introduction
ALF1 - Introduction
Alexandru Radovici
 
SdE2 - Introduction
SdE2 - IntroductionSdE2 - Introduction
SdE2 - Introduction
Alexandru Radovici
 
MDAD 6 - AIDL and Services
MDAD 6 - AIDL and ServicesMDAD 6 - AIDL and Services
MDAD 6 - AIDL and Services
Alexandru Radovici
 
MDAD 5 - Threads
MDAD 5 - ThreadsMDAD 5 - Threads
MDAD 5 - Threads
Alexandru Radovici
 
MDAD 4 - Lists, adapters and recycling
MDAD 4 - Lists, adapters and recyclingMDAD 4 - Lists, adapters and recycling
MDAD 4 - Lists, adapters and recycling
Alexandru Radovici
 
MDAD 3 - Basics of UI Applications
MDAD 3 - Basics of UI ApplicationsMDAD 3 - Basics of UI Applications
MDAD 3 - Basics of UI Applications
Alexandru Radovici
 
MDAD 2 - Introduction to the Android Framework
MDAD 2 - Introduction to the Android FrameworkMDAD 2 - Introduction to the Android Framework
MDAD 2 - Introduction to the Android Framework
Alexandru Radovici
 
MDAD 1 - Hardware
MDAD 1 - HardwareMDAD 1 - Hardware
MDAD 1 - Hardware
Alexandru Radovici
 
MDAD 0 - Introduction
MDAD 0 - IntroductionMDAD 0 - Introduction
MDAD 0 - Introduction
Alexandru Radovici
 
SdE 11 - Reseau
SdE 11 - ReseauSdE 11 - Reseau
SdE 11 - Reseau
Alexandru Radovici
 
SdE 10 - Threads
SdE 10 - ThreadsSdE 10 - Threads
SdE 10 - Threads
Alexandru Radovici
 
SdE 8 - Synchronisation de execution
SdE 8 - Synchronisation de executionSdE 8 - Synchronisation de execution
SdE 8 - Synchronisation de execution
Alexandru Radovici
 
SdE 8 - Memoire Virtuelle
SdE 8 - Memoire VirtuelleSdE 8 - Memoire Virtuelle
SdE 8 - Memoire Virtuelle
Alexandru Radovici
 
SdE 7 - Gestion de la Mémoire
SdE 7 - Gestion de la MémoireSdE 7 - Gestion de la Mémoire
SdE 7 - Gestion de la Mémoire
Alexandru Radovici
 
SdE 6 - Planification
SdE 6 - PlanificationSdE 6 - Planification
SdE 6 - Planification
Alexandru Radovici
 
SdE 5 - Planification
SdE 5 - PlanificationSdE 5 - Planification
SdE 5 - Planification
Alexandru Radovici
 
ALF 6 - Parser
ALF 6 - ParserALF 6 - Parser
ALF 6 - Parser
Alexandru Radovici
 

More from Alexandru Radovici (20)

SdE2 - Pilot Tock
SdE2 - Pilot TockSdE2 - Pilot Tock
SdE2 - Pilot Tock
 
SdE2 - Systèmes embarquées
SdE2 - Systèmes embarquéesSdE2 - Systèmes embarquées
SdE2 - Systèmes embarquées
 
SdE2 - Planification, IPC
SdE2 - Planification, IPCSdE2 - Planification, IPC
SdE2 - Planification, IPC
 
ALF1 - Introduction
ALF1 - IntroductionALF1 - Introduction
ALF1 - Introduction
 
SdE2 - Introduction
SdE2 - IntroductionSdE2 - Introduction
SdE2 - Introduction
 
MDAD 6 - AIDL and Services
MDAD 6 - AIDL and ServicesMDAD 6 - AIDL and Services
MDAD 6 - AIDL and Services
 
MDAD 5 - Threads
MDAD 5 - ThreadsMDAD 5 - Threads
MDAD 5 - Threads
 
MDAD 4 - Lists, adapters and recycling
MDAD 4 - Lists, adapters and recyclingMDAD 4 - Lists, adapters and recycling
MDAD 4 - Lists, adapters and recycling
 
MDAD 3 - Basics of UI Applications
MDAD 3 - Basics of UI ApplicationsMDAD 3 - Basics of UI Applications
MDAD 3 - Basics of UI Applications
 
MDAD 2 - Introduction to the Android Framework
MDAD 2 - Introduction to the Android FrameworkMDAD 2 - Introduction to the Android Framework
MDAD 2 - Introduction to the Android Framework
 
MDAD 1 - Hardware
MDAD 1 - HardwareMDAD 1 - Hardware
MDAD 1 - Hardware
 
MDAD 0 - Introduction
MDAD 0 - IntroductionMDAD 0 - Introduction
MDAD 0 - Introduction
 
SdE 11 - Reseau
SdE 11 - ReseauSdE 11 - Reseau
SdE 11 - Reseau
 
SdE 10 - Threads
SdE 10 - ThreadsSdE 10 - Threads
SdE 10 - Threads
 
SdE 8 - Synchronisation de execution
SdE 8 - Synchronisation de executionSdE 8 - Synchronisation de execution
SdE 8 - Synchronisation de execution
 
SdE 8 - Memoire Virtuelle
SdE 8 - Memoire VirtuelleSdE 8 - Memoire Virtuelle
SdE 8 - Memoire Virtuelle
 
SdE 7 - Gestion de la Mémoire
SdE 7 - Gestion de la MémoireSdE 7 - Gestion de la Mémoire
SdE 7 - Gestion de la Mémoire
 
SdE 6 - Planification
SdE 6 - PlanificationSdE 6 - Planification
SdE 6 - Planification
 
SdE 5 - Planification
SdE 5 - PlanificationSdE 5 - Planification
SdE 5 - Planification
 
ALF 6 - Parser
ALF 6 - ParserALF 6 - Parser
ALF 6 - Parser
 

Recently uploaded

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

ALF 5 - Parser Top-Down (2018)

  • 2. Bibliographie pour aujourd'hui Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman, Compilers: Principles, Techniques, and Tools (2nd Edition) – Chapitre 4 • 4.4
  • 4. Alexander Aiken • Américain • Stanford • LL(*) • MOSS • ANTLR
  • 5. Slides Partie de slides sont écrie par Bogdan Nitulescu
  • 6. Notation BNF RFC 2616 HTTP/1.1 June 1999 HTTP-date = rfc1123-date | rfc850-date | asctime-date rfc1123-date = wkday "," SP date1 SP time SP "GMT“ rfc850-date = weekday "," SP date2 SP time SP "GMT“ asctime-date = wkday SP date3 SP time SP 4DIGIT date1 = 2DIGIT SP month SP 4DIGIT ; day month year (e.g., 02 Jun 1982) date2 = 2DIGIT "-" month "-" 2DIGIT ; day-month-year (e.g., 02-Jun-82) date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) ; month day (e.g., Jun 2) time = 2DIGIT ":" 2DIGIT ":" 2DIGIT ; 00:00:00 - 23:59:59 wkday = "Mon" | "Tue" | "Wed“ | "Thu" | "Fri" | "Sat" | "Sun“ weekday = "Monday" | "Tuesday" | "Wednesday“ | "Thursday" | "Friday" | "Saturday" | "Sunday“ month = "Jan" | "Feb" | "Mar" | "Apr“ | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec"
  • 7. Arbre de dérivation / syntactique E  E + E E  E * E E  n n : [0-9]+ Lexer 2 * 3 + 4 * 5 n * n + n * n 2 3 4 5 parser n n n n 2 3 4 5 * * + n n n n 2 3 4 5 E * E E * E E + E E • jetons (tokens) • Valeurs • Grammaire • Arbre de dérivation • Arbre syntactique
  • 8. Types d’analyse syntactique  Descendent (top-down)  Avec backtracking  Prédictive  Descendent récursive, LL avec un tableau  Ascendant (bottom-up)  Avec backtracking  Shift-reduce  LR(0),SLR,LALR, LR canonique
  • 9. –Instr –id = Expr ; –id = ( Expr ) ; –id = ( Expr + Expr ) ; –id = ( id + Expr ) ; –id = ( id + id ) ; id = ( id + id ) ; id = ( id + id ) ; id = ( id + id ) ; id = ( id + id ) ; id = ( id + id ) ; id = ( id + id ) ; • LL: La chaîne de jetons est itérée à partir du côté gauche (L) • Le non-terminal le plus à gauche est dérivé (L) Dérivation gauche, top down
  • 10. –Instr –id = Expr ; –id = Expr + Expr ; –id = ( Expr ) + Expr ; –id = ( id ) + Expr ; –id = ( id ) + ( Expr ) ; –id = ( id + id ) ; id = ( id ) + ( id ) ; id = ( id ) + ( id ) ; id = ( id ) + ( id ) ; id = ( id ) + ( id ) ; id = ( id ) + ( id ) ; id = ( id ) + ( id ) ; id = ( id ) + ( id ) ; • Comment choisir la production utilisée pour la dérivation? • Backtracking? Dérivation gauche, top down
  • 11. Parser LL, LR  Nous devrions éviter backtracking  Une grammaire qui permet le parser déterministe  LL(k) lit left-to-right, dérivation left  LR(k) lit left-to-right, dérivation right  K – lookahead (combien de tokens sont lus)  LL(k) < LR(k)  L'algorithme est indépendant du langage, la grammaire dépend du langage
  • 12. Analyse descendent récursive  Non-terminal -> fonction  Si le symbole apparaît dans la partie droite de production -> appel la fonction  Si le symbole apparaît dans la partie gauche de production – la production est choisi en fonction des jetons (tokens) suivants (lookahead)
  • 13. MatchToken (token) { if (lookahead != token) throw error(); lookahead = lexer.getNextToken(); } rfc850-date = weekday "," SP date2 SP time SP "GMT“ ParseRFC850Date() { ParseWeekDay(); MatchToken(","); MatchToken(SP); ParseDate2(); MatchToken(SP); ParseTime(); MatchToken(SP); MatchToken("GMT“); } Fonction pour parser le non- terminal rfc850-date Analyse descendent récursive
  • 14. Avec la grammaire E  E + T | T T  T  F | F F  ( E ) | id Un parser descendant entre dans une boucle infinie lorsque vous essayez de parser cette grammaire E E +E T E +E T +E T E +E T +E T +E T (Aho,Sethi,Ullman, pp. 176) Récursivité gauche
  • 15. Grammaire des expression E  E + T | T T  T  F | F F  ( E ) | id Peut être écrive sans la récursivité gauche E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id (Aho,Sethi,Ullman, pp. 176) ε – string vide Récursivité gauche
  • 16. Exemple de parser récursive ParseE() { ParseT(); ParseE1(); } ParseE1() { if (lookahead==“+”) { MatchToken(“+”); ParseT(); ParseE1(); } } ParseT() { ParseF(); ParseT1(); } ParseT1() { if (lookahead==“*”) { MatchToken(“*”); ParseF(); ParseT1(); } } E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id ParseF() { if (lookahead == “(“) { MatchToken(“(“); ParseE(); MatchToken(“)”); } else MatchToken(T_ID); }
  • 17. Comment choisir entre deux productions? Comment pouvons-nous savoir quelles conditions de poser a if? Lorsque nous émettons des erreurs? ParseF() { if (lookahead == “(“) { MatchToken(“(“); ParseE(); MatchToken(“)”); } else if (lookahead == T_ID) { MatchToken(T_ID); } else throw error(); } F  ( E ) F  id T’  *FT’ T’  ε ParseT1() { if (lookahead==“*”) { MatchToken(“*”); ParseF(); ParseT1(); } else if (lookahead == “+”) { } else if (lookahead == “)”) { } else if (lookahead == T_EOF) { } else throw error(); } Analyse descendent récursive
  • 18. Les conditions pour if • FIRST – Ensemble de terminaux-préfixées pour le non-terminal • FOLLOW – Ensemble de terminaux suivantes pour le non-terminal • NULLABLE – Ensemble de non-terminaux qui peut etre derive en ε
  • 19. FIRST E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: 1. If X is a terminal, FIRST(X) = {X} FIRST(id) = {id} FIRST() = {} FIRST(+) = {+} ENSEBLES: 2. If X   , then   FIRST(X) 4. If X  Y1 Y2 ••• Yk FIRST(() = {(} FIRST()) = {)} FIRST (pseudocode): and a FIRST(Yi) then a  FIRST(X) FIRST(F) = {(, id} FIRST(T) = FIRST(F) = {(, id} FIRST(E) = FIRST(T) = {(, id} FIRST(E’) = {} {+, } FIRST(T’) = {} {, } (Aho,Sethi,Ullman, pp. 189) * 3. If X  Y1 Y2 ••• Yk and Y1••• Yi-1  and a FIRST(Y1) then a  FIRST(X)
  • 20. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: 1. If S is the start symbol, then $  FOLLOW(S) FOLLOW(E) = {$} FOLLOW(E’) = { ), $} ENSEBLES: 2. If A  B, and a  FIRST() and a   then a  FOLLOW(B) 3. If A  B and a  FOLLOW(A) then a  FOLLOW(B) FOLLOW – pseudocode: { ), $} 3a. If A  B and and a  FOLLOW(A) then a  FOLLOW(B) *   FOLLOW(T) = { ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , }  et  - string de terminaux et non- terminaux A et B – non-terminaux, $ - fin du text (Aho,Sethi,Ullman, pp. 189) FOLLOW
  • 21. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id 1. If S is the start symbol, then $  FOLLOW(S) FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} 3. If A  B and a  FOLLOW(A) then a  FOLLOW(B) 3a. If A  B and and a  FOLLOW(A) then a  FOLLOW(B) *   FOLLOW(T) = { ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } 2. If A  B, and a  FIRST() and a   then a  FOLLOW(B) {+, ), $} (Aho,Sethi,Ullman, pp. 189) GRAMMAIRE: ENSEBLES: FOLLOW – règles: FOLLOW
  • 22. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id 1. If S is the start symbol, then $  FOLLOW(S) FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW(T) = {+, ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } 2. If A  B, and a  FIRST() and a   then a  FOLLOW(B) 3. If A  B and a  FOLLOW(A) then a  FOLLOW(B) FOLLOW(T’) = {+, ), $} 3a. If A  B and and a  FOLLOW(A) then a  FOLLOW(B) *   (Aho,Sethi,Ullman, pp. 189) GRAMMAIRE: ENSEBLES: FOLLOW – règles: FOLLOW
  • 23. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id 1. If S is the start symbol, then $  FOLLOW(S) FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW(T) = {+, ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } 2. If A  B, and a  FIRST() and a   then a  FOLLOW(B) 3. If A  B and a  FOLLOW(A) then a  FOLLOW(B) FOLLOW(T’) = {+, ), $} 3a. If A  B and and a  FOLLOW(A) then a  FOLLOW(B) *   FOLLOW(F) = {+, ), $} (Aho,Sethi,Ullman, pp. 189) GRAMMAIRE: ENSEBLES: FOLLOW – règles: FOLLOW
  • 24. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id 1. If S is the start symbol, then $  FOLLOW(S) FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW(T) = {+, ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } 3. If A  B and a  FOLLOW(A) then a  FOLLOW(B) FOLLOW(T’) = {+, ), $} 3a. If A  B and and a  FOLLOW(A) then a  FOLLOW(B) *   FOLLOW(F) = {+, ), $} 2. If A  B, and a  FIRST() and a   then a  FOLLOW(B) {+, , ), $} (Aho,Sethi,Ullman, pp. 189) GRAMMAIRE: ENSEBLES: FOLLOW – règles: FOLLOW
  • 25. L’algo générique récursive LL(1) A  a B … x A  C D … y … ParseA() { if (lookahead in FIRST(a B … x FOLLOW(A)) { MatchToken(a); ParseB(); … MatchToken(x); } else if (lookahead in FIRST(C D … y FOLLOW(A)) { ParseC(); ParseD(); … MatchToken(y); } … else throw error(); } • Pour chaque non-terminal crée une fonction de parser. • Pour chaque règle Aα ajouter un test if (lookahead in FIRST(αFOLLOW(A)) ) • Pour chaque non-terminal dans a appeler la fonction de parser. • Pour chaque terminal dans a, vérifier le lookahead(match)
  • 26. Récursivité gauche Quand une grammaire a au moins une forme de production A  Aα nous disons qu'il est une grammaire récursive gauche. Le parsers descendent ne fonctionnent pas (sans backtracking) sur les grammaire récursives gauche. (Aho,Sethi,Ullman, pp. 176) Récursivité peut ne pas être immédiat A  Bα B  A β
  • 27. Elimination récursivité gauche • Cela se fait par la réécriture de la grammaire E  E + T | T T  T  F | F F  ( E ) | id E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id (Aho,Sethi,Ullman, pp. 176) List  List Item | Item List  Item List’ List’  Item List’ | ε
  • 28. Cas général (récursivité immédiat): A → Aβ1 |Aβ2 | ... |Aβm | α1 | α2 | ... | αn A → α1A' | α2A' | ... | αnA‘ A' → β1A' | β2A' | ... | βmA'| ε E  E + T | T T  T  F | F F  ( E ) | id E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id Elimination récursivité gauche
  • 29. • Pour une instruction if: • Pour parser avec LL, elle doit être factorise: Factorisation gauche
  • 30.  Cas général: A → αβ1 | αβ2 | ... | αβn | δ  Factorise: A → αA' | δ A' → β1 | β2 | ... | βn Factorisation gauche
  • 31. Elimination des ambiguïtés  Ambigu: Ε → Ε + Ε | Ε * Ε | a | ( E ) 1. Ε → Ε + T | T T → T * F | F F → a | ( E ) 2. Ε → T + E | T T → F * T | F F → a | ( E )  La précédence des operateurs  La associativité gauche ou droite
  • 32.  Productions qui peuvent produire l'ambiguïté: X → aAbAc  Cas général: A → A B A | α1 | α2 | ... | αn  Désambiguïsât: A → A' B A | A‘ A' → α1 | α2 | ... | αn Elimination des ambiguïtés
  • 33. Parser automatique • Automate push-down • Le parser est fait avec un automate est un tableau • Langage LL(1) si il n'a pas de conflits dans le tableau
  • 34. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id Grammaire: INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’+TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) Tableau de Parsing: (Aho,Sethi,Ullman, pp. 188) Exemple de parser LL
  • 35. INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) PILE: id idid+ INPUT: Predictive Parsing Program E $ $ OUTPUT: E T E’ $ T E’ TABLEAU DE PARSING: Exemple de parser LL
  • 36. T E’ $ T E’ $ INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) id idid+ INPUT: Predictive Parsing Program $ OUTPUT: E F T’ E’ $ F T’ T E’ (Aho,Sethi, Ullman, pp. 186) PILE: TABLEAU DE PARSING: Exemple de parser LL
  • 37. (Aho,Sethi, Ullman, pp. 188) T E’ $ T E’ $ INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) id idid+ INPUT: Predictive Parsing Program $ OUTPUT: E F T’ E’ $ F T’ T E’ id T’ E’ $ id PILE: TABLEAU DE PARSING: Exemple de parser LL
  • 38. INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) id idid+ INPUT: Predictive Parsing Program $ OUTPUT: E T’ E’ $ F T’ T E’ id Quand l’action c’est Top(Pile) = input ≠ $ : ‘Pop’ de la pile, avance la bande de input. (Aho,Sethi, Ullman, pp. 188) PILE: TABLEAU DE PARSING: Exemple de parser LL
  • 39. INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) id idid+ INPUT: Predictive Parsing Program $ OUTPUT: E F T’ T E’ id  T’ E’ $ E’ $ (Aho,Sethi, Ullman, pp. 188) PILE: TABLEAU DE PARSING: Exemple de parser LL
  • 40. E F T’ T E’ id  T+ E’ F T’ id F T’ id   Et ainsi, il construit l’arbre de dérivation: E’  +TE’ T  FT’ F  id T’   FT’ F  id T’   E’   Quand Top(Pile) = input = $ Le parser arrêt et accepte l’input (Aho,Sethi, Ullman, pp. 188) Exemple de parser LL
  • 41. Remplir de tableau • FIRST – Ensemble de terminaux-préfixées pour le non-terminal • FOLLOW – Ensemble de terminaux suivantes pour le non-terminal • NULLABLE – Ensemble de non-terminaux qui peut etre derive en ε
  • 42. Reguli pentru construit tabela de parsare E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: TABLEAU DE PARSING: 1. If A  : if a  FIRST(), add A   to M[A, a] INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)
  • 43. 1. If A  : if a  FIRST(), add A   to M[A, a] INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: TABLEAU DE PARSING:
  • 44. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: 1. If A  : if a  FIRST(), add A   to M[A, a] INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare TABLEAU DE PARSING:
  • 45. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: TABLEAU DE PARSING: 1. If A  : if a  FIRST(), add A   to M[A, a] INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare
  • 46. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: 1. If A  : if a  FIRST(), add A   to M[A, a] INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare TABLEAU DE PARSING:
  • 47. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: 1. If A  : if a  FIRST(), add A   to M[A, a] 2. If A  : if   FIRST(), add A   to M[A, b] for each terminal b  FOLLOW(A), INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare TABLEAU DE PARSING:
  • 48. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: 1. If A  : if a  FIRST(), add A   to M[A, a] 2. If A  : if   FIRST(), add A   to M[A, b] for each terminal b  FOLLOW(A), INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare TABLEAU DE PARSING:
  • 49. E  TE’ E’  +TE’ |  T  FT’ T’  FT’ |  F  ( E ) | id GRAMMAIRE: FOLLOW(E) = {), $} FOLLOW(E’) = { ), $} FOLLOW SETS: FOLLOW(T) = {+, ), $} FOLLOW(T’) = {+, ), $} FOLLOW(F) = {+, , ), $} FIRST(F) = {(, id} FIRST(T) = {(, id} FIRST(E) = {(, id} FIRST(E’) = {+, } FIRST(T’) = { , } FIRST SETS: 1. If A  : if a  FIRST(), add A   to M[A, a] 2. If A  : if   FIRST(), add A   to M[A, b] for each terminal b  FOLLOW(A), 3. If A  : if   FIRST(), and $  FOLLOW(A), add A   to M[A, $] INPUTSYMBOLNON- TERMINAL id + * ( ) $ E ETE’ ETE’ E’ E’ +TE’ E’  E’  T TFT’ TFT’ T’ T’ T’ *FT’ T’  T’  F Fid F(E) (Aho,Sethi,Ullman, pp. 190)Reguli pentru construit tabela de parsare TABLEAU DE PARSING:
  • 50. Utilisation de parser LL(1)  Grammaires  Non ambigu  Factorise  Non récursive a gauche  On peut montrer que la grammaire G est LL (1) si et seulement si pour deux productions de la forme A  , A  , avec    les conditions suivantes sont satisfaites:  FIRST()  FIRST() =   Si  * ε alors FIRST()  FOLLOW(A) = et si  * ε alors FIRST()  FOLLOW(A) = .
  • 51. Avantage/désavantage LL(1)  Facile de écrive ‘aux main’  Vite, facile de comprendre  La grammaire doit être transforme  L’arbre de dérivation et diffèrent de l’arbre sémantique E F T’ T E’ id  T+ E’ F T’ id F T’ id   E F T TE id + F id F id T
  • 52. Parser LL • ANTLR – Java – LL (*) – Factorisation
  • 53. Règles EBNF Something? Something* Something+ SomethingQ -> ε | Something SomethingStar -> ε | Something SomethingStar SomethingPlus -> Something SomethingStar
  • 54. Sujets • Les parser • LL – Eviter l’ambiguïté – Factorisation – Eviter la récursivité gauche • Algorithme général récursive LL