The document discusses top-down parsing and LL parsers. It provides context about the topics covered in a lecture on compilers including slides written by Bogdan Nitulescu. The document then discusses LL(1) parsing and provides the generic recursive LL(1) parsing algorithm. Key terms discussed include FIRST and FOLLOW sets, nullable nonterminals, and using lookahead to deterministically select production rules during top-down recursive descent parsing.
Introduction to Lisp. A survey of lisp's history, current incarnations and advanced features such as list comprehensions, macros and domain-specific-language [DSL] support.
This slides describes the basic concepts of industrial-strength compiler design. This includes basic concept of static single-assignment form (SSA) and various optimizations such as dead code elimination, global value numbering, constant propagation, etc. This is intend for a 150 minutes undergraduate compiler class.
Introduction to Lisp. A survey of lisp's history, current incarnations and advanced features such as list comprehensions, macros and domain-specific-language [DSL] support.
This slides describes the basic concepts of industrial-strength compiler design. This includes basic concept of static single-assignment form (SSA) and various optimizations such as dead code elimination, global value numbering, constant propagation, etc. This is intend for a 150 minutes undergraduate compiler class.
LISP Language, LISP Introduction, List Processing, LISP Syntax, Lisp Comparison Structures, Lisp Applications. Using of LISP language in Artificial Intelligence
Invented by John McCarthy (1958)
Two simple data structure (atoms and lists)
Heavy use of recursion
Interpretive language
Variations
Scheme
Common Lisp (de facto industrial standard)
Most widely used AI programming language
Functional Programming Paradigm
Low maintenance overhead
LISP Language, LISP Introduction, List Processing, LISP Syntax, Lisp Comparison Structures, Lisp Applications. Using of LISP language in Artificial Intelligence
Invented by John McCarthy (1958)
Two simple data structure (atoms and lists)
Heavy use of recursion
Interpretive language
Variations
Scheme
Common Lisp (de facto industrial standard)
Most widely used AI programming language
Functional Programming Paradigm
Low maintenance overhead
The first “L” stands for scanning input from left to right. The second “L” for producing a leftmost derivation. The “1” for using one input symbol of look-ahead at each step to make parsing decisions.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Safalta Digital marketing institute in Noida, provide complete applications that encompass a huge range of virtual advertising and marketing additives, which includes search engine optimization, virtual communication advertising, pay-per-click on marketing, content material advertising, internet analytics, and greater. These university courses are designed for students who possess a comprehensive understanding of virtual marketing strategies and attributes.Safalta Digital Marketing Institute in Noida is a first choice for young individuals or students who are looking to start their careers in the field of digital advertising. The institute gives specialized courses designed and certification.
for beginners, providing thorough training in areas such as SEO, digital communication marketing, and PPC training in Noida. After finishing the program, students receive the certifications recognised by top different universitie, setting a strong foundation for a successful career in digital marketing.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
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
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 ETE’ ETE’
E’ E’+TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid F(E)
Tableau
de
Parsing:
(Aho,Sethi,Ullman, pp. 188)
Exemple de parser LL
35. INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid F(E)
(Aho,Sethi,Ullman, pp. 190)
43. 1. If A :
if a FIRST(), add A to M[A, a]
INPUTSYMBOLNON-
TERMINAL id + * ( ) $
E ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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 ETE’ ETE’
E’ E’ +TE’ E’ E’
T TFT’ TFT’
T’ T’ T’ *FT’ T’ T’
F Fid 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