SlideShare uma empresa Scribd logo
1 de 13
WELCOME TO A
JOURNEY TO
CS419

Dr. Hussien Sharaf
Computer Science Department

dr.sharaf@from-masr.com
FIRST


1.
2.
3.

Let X be a grammar symbol (a terminal or nonterminal or
), then the FIRST(X) can be computed by the following rules:
If X is terminal, then FIRST(X) is {X}.
If X → is a production, then add to FIRST(X).
If X is nontermianl and X → Y1 Y2 …… Yk is a production, then
place a in FIRST(X) if for some i, a is in FIRST(Yi), and is in
all of FIRST(Y1), ……., FIRST(Yi-1); that is, Y1 …...Yi-1 → . If is
in FIRST(Yj) for all j = 1, 2, ……., k, then add to FIRST(X).
For example ,everything in FIRST(Y1) is surely in FIRST(X). If
Y1 doesn’t derive , then we add nothing more to
FIRST(X), but if Y1 → , then we add FIRST(Y2) and so on.
Ali
Hussien

Dr. Hussien M. Sharaf

First(Ali)

Ali
2
FIRST SET EXAMPLE
Consider the following grammar:
E → TQ
Q → +TQ |
T → FR
R → *FR |
F → (E) | id
Then,
FIRST(E) = FIRST(T) = FIRST(F) = {(, id}.
FIRST(Q) = {+, }
FIRST(R) = {*, }


Dr. Hussien M. Sharaf

3
FOLLOW
To compute FOLLOW(A) for all nonterminals A, then
apply the following rules until nothing can be added to
any FOLLOW set:
1. Place $ in FOLLOW(S), where S is the start symbol and
$ is the input right endmarker.
i.e. $ ∈ FOLLOW(S)
2. If there is a production A → αBβ, then everything in
FIRST(β) except for is placed in FOLLOW(B).


i.e. (FIRST(β) ~

) ⊆ FOLLOW(B)

Ali Plays
Dr. Hussien M. Sharaf

Follow of Ali

Plays
4
FOLLOW
If there is a production A → αB, or [a production A
→ αBβ where FIRST(β) contains (i.e β → )], then
everything in FOLLOW(A) is in FOLLOW(B).
i.e. FOLLOW(A) ⊆ FOLLOW(B)
3.

Ali Plays
Dr. Hussien M. Sharaf

Follow of Ali

Plays
5
FOLLOW SET EXAMPLE
Consider again the previous grammar:
E → TQ
Q → +TQ |
First (‘)’) ⊆
T → FR
Follow(E) because
F → (E)
R → *FR |
E is the start
F → (E) | id
symbol
Then,
First(Q) ⊆ Follow(T)
Because 1. E → TQ
FOLLOW(E) = FOLLOW(Q) = { ) , $ }.
FOLLOW(T) = FOLLOW(R) ={ +, ), $ }
Follow(E) ⊆
Follow(T)
FOLLOW(F) = {*, +, ), $}


Because 2. Q →

Dr. Hussien M. Sharaf

First(Q) ⊆
Follow(T)
Because E → TQ

6
FOLLOW SET EXAMPLE
Consider again the previous grammar:
E → TQ
Q → +TQ |
T → FR
R → *FR |
F → (E) | id
FOLLOW(E) = FOLLOW(Q) = { ) , $ }.
FOLLOW(T) = FOLLOW(R) ={ +, ), $ }
FOLLOW(F) = { * , + , ) , $ }


First(R) ⊆ Follow(F)
Because T→ FR

Dr. Hussien M. Sharaf

First(R) ⊆ Follow(F)
Because 1. T→ FR
Follow(T) ⊆ Follow(F)
Because 2. R →

7
EXAMPLE 1

[ Alfred V. Aho, Compilers Principles, Techniques, and
Tools, 1986, Addison-Wesley, page 188]

Construct the parsing table for the following grammar:
1. E
TQ
2. Q
+TQ |
3. T → FR

4. R
5. F
E
Q

Dr. Hussien M. Sharaf

T
R
F

First Set
{(, id}
{+, }
{(, id}
{*, }
{(, id}

*FR |
(E) | id
Follow set
{$, )}
{$, )}
{+, ), $ }
{+, ), $}
{*, +, ), $}
8
EXAMPLE 1 (CONT.)
The parsing table for the previous grammar is:
1. E
TQ
2. Q
+TQ |
3. T → FR
id
E E

+

(
E

Q

id

Dr. Hussien M. Sharaf

$

TQ
Q

Q

R

R

T → FR

R
F

*FR |
(E) | id
)

+TQ

T → FR

R
F

*

TQ

Q
T

4. R
5. F

R

*FR
F

(E)
9
FIRST AND FOLLOW EXAMPLE
S →A
 A → BC | DBC
 B → bB ΄|
 B ΄→ bB΄|
 C →c|
 D →a|d
FIRST(S) = { a, b, c, d,
FIRST(A) = { a, b, c, d,
FIRST(B) = { b, }
FIRST(B ΄) = { b, }
FIRST(C) = { c, }
FIRST(D) = { a, d }


Dr. Hussien M. Sharaf

}
}

FOLLOW(S) = { $ }
FOLLOW(A) = { $ }
FOLLOW(B) = { c, $ }
FOLLOW(B ΄) ={ c, $ }
FOLLOW(C) = { $ }
FOLLOW(D) = { b, c, $ }
10
EXAMPLE 2 PAGE 156
The parsing table for the following grammar is:
1. S

If_Stat | other

2. If_Stat

if(Exp) S Else_part
if

S

If_Stat

S

3. Else_part

If_Stat S

other

4. Exp

else

else S |

true | false
true

false

$

other

If_Stat
if(exp) S
Else_part

Else_part

Exp

Dr. Hussien M. Sharaf

Else_part
else S

Else_part
exp
true

exp
false
11
EXAMPLE 3
The parsing table for the following grammar is:
1. E

TQ

6. R

*FR

2.
3.
4.
5.

+TQ
-TQ

7. R
8. R
9. F
10.F

/FR

Q
Q
Q
T

FR
+

-

*

/

E
Q

(

)

1
2

3

F
Dr. Hussien M. Sharaf

8

6

7

4

5
8

9

$

1

5
8

id

4

T
R

(E)
id

8
10
12
THANK YOU

Mais conteúdo relacionado

Mais procurados

Derivatives power point
Derivatives power point Derivatives power point
Derivatives power point Ashley Smith
 
On Gr-Separation Axioms
 On Gr-Separation Axioms  On Gr-Separation Axioms
On Gr-Separation Axioms IJMER
 
On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...
On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...
On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...IOSR Journals
 
Algorithms presentation on Path Matrix, Bell Number and Sorting
Algorithms presentation on Path Matrix, Bell Number and SortingAlgorithms presentation on Path Matrix, Bell Number and Sorting
Algorithms presentation on Path Matrix, Bell Number and SortingRishabh Mehan
 
Operation on functions
Operation on functionsOperation on functions
Operation on functionsJeralyn Obsina
 
On Spaces of Entire Functions Having Slow Growth Represented By Dirichlet Series
On Spaces of Entire Functions Having Slow Growth Represented By Dirichlet SeriesOn Spaces of Entire Functions Having Slow Growth Represented By Dirichlet Series
On Spaces of Entire Functions Having Slow Growth Represented By Dirichlet SeriesIOSR Journals
 
δ ˆ – Closed Sets in Ideal Topological Spaces
δ ˆ – Closed Sets in Ideal Topological Spacesδ ˆ – Closed Sets in Ideal Topological Spaces
δ ˆ – Closed Sets in Ideal Topological SpacesIOSR Journals
 
International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI) International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI) inventionjournals
 
The Yoneda lemma and String diagrams
The Yoneda lemma and String diagramsThe Yoneda lemma and String diagrams
The Yoneda lemma and String diagramsRay Sameshima
 
5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.Jan Plaza
 
1.6 inverse function (optional)
1.6 inverse function (optional)1.6 inverse function (optional)
1.6 inverse function (optional)math123c
 
Maximal and Minimal α -Open Sets
Maximal and Minimal α -Open SetsMaximal and Minimal α -Open Sets
Maximal and Minimal α -Open SetsIJERA Editor
 
5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.Jan Plaza
 
Calculus II - 21
Calculus II - 21Calculus II - 21
Calculus II - 21David Mao
 
5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)Jan Plaza
 
Between α-closed Sets and Semi α-closed Sets
Between α-closed Sets and Semi α-closed SetsBetween α-closed Sets and Semi α-closed Sets
Between α-closed Sets and Semi α-closed SetsIJMER
 

Mais procurados (20)

Derivatives power point
Derivatives power point Derivatives power point
Derivatives power point
 
On Gr-Separation Axioms
 On Gr-Separation Axioms  On Gr-Separation Axioms
On Gr-Separation Axioms
 
Hw9
Hw9Hw9
Hw9
 
On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...
On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...
On Fuzzy  - Semi Open Sets and Fuzzy  - Semi Closed Sets in Fuzzy Topologic...
 
Algorithms presentation on Path Matrix, Bell Number and Sorting
Algorithms presentation on Path Matrix, Bell Number and SortingAlgorithms presentation on Path Matrix, Bell Number and Sorting
Algorithms presentation on Path Matrix, Bell Number and Sorting
 
Operation on functions
Operation on functionsOperation on functions
Operation on functions
 
On Spaces of Entire Functions Having Slow Growth Represented By Dirichlet Series
On Spaces of Entire Functions Having Slow Growth Represented By Dirichlet SeriesOn Spaces of Entire Functions Having Slow Growth Represented By Dirichlet Series
On Spaces of Entire Functions Having Slow Growth Represented By Dirichlet Series
 
δ ˆ – Closed Sets in Ideal Topological Spaces
δ ˆ – Closed Sets in Ideal Topological Spacesδ ˆ – Closed Sets in Ideal Topological Spaces
δ ˆ – Closed Sets in Ideal Topological Spaces
 
International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI) International Journal of Mathematics and Statistics Invention (IJMSI)
International Journal of Mathematics and Statistics Invention (IJMSI)
 
Ejercicios 4
Ejercicios 4Ejercicios 4
Ejercicios 4
 
The Yoneda lemma and String diagrams
The Yoneda lemma and String diagramsThe Yoneda lemma and String diagrams
The Yoneda lemma and String diagrams
 
5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.5.5 Injective and surjective functions. Dynamic slides.
5.5 Injective and surjective functions. Dynamic slides.
 
Ring homomorphism
Ring homomorphismRing homomorphism
Ring homomorphism
 
Taylor's series
 Taylor's  series   Taylor's  series
Taylor's series
 
1.6 inverse function (optional)
1.6 inverse function (optional)1.6 inverse function (optional)
1.6 inverse function (optional)
 
Maximal and Minimal α -Open Sets
Maximal and Minimal α -Open SetsMaximal and Minimal α -Open Sets
Maximal and Minimal α -Open Sets
 
5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.5.1 Defining and visualizing functions. Dynamic slides.
5.1 Defining and visualizing functions. Dynamic slides.
 
Calculus II - 21
Calculus II - 21Calculus II - 21
Calculus II - 21
 
5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)5.8 Permutations (dynamic slides)
5.8 Permutations (dynamic slides)
 
Between α-closed Sets and Semi α-closed Sets
Between α-closed Sets and Semi α-closed SetsBetween α-closed Sets and Semi α-closed Sets
Between α-closed Sets and Semi α-closed Sets
 

Destaque

Compiler First Set Follow Set Brief
Compiler First Set Follow Set BriefCompiler First Set Follow Set Brief
Compiler First Set Follow Set Briefsallypicnic
 
Theory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence ProblemTheory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence ProblemKaran Thakkar
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Animesh Chaturvedi
 

Destaque (20)

Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Lec4
Lec4Lec4
Lec4
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Compiler First Set Follow Set Brief
Compiler First Set Follow Set BriefCompiler First Set Follow Set Brief
Compiler First Set Follow Set Brief
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Theory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence ProblemTheory of Computer Science - Post Correspondence Problem
Theory of Computer Science - Post Correspondence Problem
 
Infos2014
Infos2014Infos2014
Infos2014
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Minimizing DFA
Minimizing DFAMinimizing DFA
Minimizing DFA
 
Theory of computing
Theory of computingTheory of computing
Theory of computing
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
NFA to DFA
NFA to DFANFA to DFA
NFA to DFA
 

Semelhante a Cs419 lec9 constructing parsing table ll1

Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)Siddhesh Pange
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up ParsingGerwin Ocsena
 
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
 
Steiner Tree Parameterized by Treewidth
Steiner Tree Parameterized by TreewidthSteiner Tree Parameterized by Treewidth
Steiner Tree Parameterized by TreewidthASPAK2014
 
ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)Alexandru Radovici
 
Design and analysis of algorithm By Creative Developper
Design and analysis of algorithm By Creative DevelopperDesign and analysis of algorithm By Creative Developper
Design and analysis of algorithm By Creative DevelopperOMKARVERMA12
 
A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...Alexander Decker
 
A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...Alexander Decker
 
5 top-down-parsers
5  top-down-parsers 5  top-down-parsers
5 top-down-parsers Saeed Parsa
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniquesd72994185
 
Contra  * Continuous Functions in Topological Spaces
Contra   * Continuous Functions in Topological SpacesContra   * Continuous Functions in Topological Spaces
Contra  * Continuous Functions in Topological SpacesIJMER
 
Prerequisite for metric space
Prerequisite for metric spacePrerequisite for metric space
Prerequisite for metric spaceROHAN GAIKWAD
 
Operations on Functions.pdf
Operations on Functions.pdfOperations on Functions.pdf
Operations on Functions.pdfJetCarilloToledo
 

Semelhante a Cs419 lec9 constructing parsing table ll1 (20)

Top down parsing(sid) (1)
Top down parsing(sid) (1)Top down parsing(sid) (1)
Top down parsing(sid) (1)
 
First and follow set
First and follow setFirst and follow set
First and follow set
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
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.
 
First() and Follow()
First() and Follow()First() and Follow()
First() and Follow()
 
Steiner Tree Parameterized by Treewidth
Steiner Tree Parameterized by TreewidthSteiner Tree Parameterized by Treewidth
Steiner Tree Parameterized by Treewidth
 
ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)ALF 5 - Parser Top-Down (2018)
ALF 5 - Parser Top-Down (2018)
 
Design and analysis of algorithm By Creative Developper
Design and analysis of algorithm By Creative DevelopperDesign and analysis of algorithm By Creative Developper
Design and analysis of algorithm By Creative Developper
 
Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
 
ALF 5 - Parser Top-Down
ALF 5 - Parser Top-DownALF 5 - Parser Top-Down
ALF 5 - Parser Top-Down
 
A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...
 
A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...A common fixed point theorems in menger space using occationally weakly compa...
A common fixed point theorems in menger space using occationally weakly compa...
 
5 top-down-parsers
5  top-down-parsers 5  top-down-parsers
5 top-down-parsers
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniques
 
Contra  * Continuous Functions in Topological Spaces
Contra   * Continuous Functions in Topological SpacesContra   * Continuous Functions in Topological Spaces
Contra  * Continuous Functions in Topological Spaces
 
Prerequisite for metric space
Prerequisite for metric spacePrerequisite for metric space
Prerequisite for metric space
 
1. I. Hassairi.pdf
1.  I. Hassairi.pdf1.  I. Hassairi.pdf
1. I. Hassairi.pdf
 
1. I. Hassairi.pdf
1.  I. Hassairi.pdf1.  I. Hassairi.pdf
1. I. Hassairi.pdf
 
CONTINUITY ON N-ARY SPACES
CONTINUITY ON N-ARY SPACESCONTINUITY ON N-ARY SPACES
CONTINUITY ON N-ARY SPACES
 
Operations on Functions.pdf
Operations on Functions.pdfOperations on Functions.pdf
Operations on Functions.pdf
 

Mais de Arab Open University and Cairo University

Mais de Arab Open University and Cairo University (16)

File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
 
CS215 - Lec 7 managing records collection
CS215 - Lec 7  managing records collectionCS215 - Lec 7  managing records collection
CS215 - Lec 7 managing records collection
 
CS215 - Lec 6 record index
CS215 - Lec 6  record indexCS215 - Lec 6  record index
CS215 - Lec 6 record index
 
CS215 - Lec 5 record organization
CS215 - Lec 5  record organizationCS215 - Lec 5  record organization
CS215 - Lec 5 record organization
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
 
CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
 

Último

Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Último (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

Cs419 lec9 constructing parsing table ll1

  • 1. WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Computer Science Department dr.sharaf@from-masr.com
  • 2. FIRST  1. 2. 3. Let X be a grammar symbol (a terminal or nonterminal or ), then the FIRST(X) can be computed by the following rules: If X is terminal, then FIRST(X) is {X}. If X → is a production, then add to FIRST(X). If X is nontermianl and X → Y1 Y2 …… Yk is a production, then place a in FIRST(X) if for some i, a is in FIRST(Yi), and is in all of FIRST(Y1), ……., FIRST(Yi-1); that is, Y1 …...Yi-1 → . If is in FIRST(Yj) for all j = 1, 2, ……., k, then add to FIRST(X). For example ,everything in FIRST(Y1) is surely in FIRST(X). If Y1 doesn’t derive , then we add nothing more to FIRST(X), but if Y1 → , then we add FIRST(Y2) and so on. Ali Hussien Dr. Hussien M. Sharaf First(Ali) Ali 2
  • 3. FIRST SET EXAMPLE Consider the following grammar: E → TQ Q → +TQ | T → FR R → *FR | F → (E) | id Then, FIRST(E) = FIRST(T) = FIRST(F) = {(, id}. FIRST(Q) = {+, } FIRST(R) = {*, }  Dr. Hussien M. Sharaf 3
  • 4. FOLLOW To compute FOLLOW(A) for all nonterminals A, then apply the following rules until nothing can be added to any FOLLOW set: 1. Place $ in FOLLOW(S), where S is the start symbol and $ is the input right endmarker. i.e. $ ∈ FOLLOW(S) 2. If there is a production A → αBβ, then everything in FIRST(β) except for is placed in FOLLOW(B).  i.e. (FIRST(β) ~ ) ⊆ FOLLOW(B) Ali Plays Dr. Hussien M. Sharaf Follow of Ali Plays 4
  • 5. FOLLOW If there is a production A → αB, or [a production A → αBβ where FIRST(β) contains (i.e β → )], then everything in FOLLOW(A) is in FOLLOW(B). i.e. FOLLOW(A) ⊆ FOLLOW(B) 3. Ali Plays Dr. Hussien M. Sharaf Follow of Ali Plays 5
  • 6. FOLLOW SET EXAMPLE Consider again the previous grammar: E → TQ Q → +TQ | First (‘)’) ⊆ T → FR Follow(E) because F → (E) R → *FR | E is the start F → (E) | id symbol Then, First(Q) ⊆ Follow(T) Because 1. E → TQ FOLLOW(E) = FOLLOW(Q) = { ) , $ }. FOLLOW(T) = FOLLOW(R) ={ +, ), $ } Follow(E) ⊆ Follow(T) FOLLOW(F) = {*, +, ), $}  Because 2. Q → Dr. Hussien M. Sharaf First(Q) ⊆ Follow(T) Because E → TQ 6
  • 7. FOLLOW SET EXAMPLE Consider again the previous grammar: E → TQ Q → +TQ | T → FR R → *FR | F → (E) | id FOLLOW(E) = FOLLOW(Q) = { ) , $ }. FOLLOW(T) = FOLLOW(R) ={ +, ), $ } FOLLOW(F) = { * , + , ) , $ }  First(R) ⊆ Follow(F) Because T→ FR Dr. Hussien M. Sharaf First(R) ⊆ Follow(F) Because 1. T→ FR Follow(T) ⊆ Follow(F) Because 2. R → 7
  • 8. EXAMPLE 1 [ Alfred V. Aho, Compilers Principles, Techniques, and Tools, 1986, Addison-Wesley, page 188] Construct the parsing table for the following grammar: 1. E TQ 2. Q +TQ | 3. T → FR 4. R 5. F E Q Dr. Hussien M. Sharaf T R F First Set {(, id} {+, } {(, id} {*, } {(, id} *FR | (E) | id Follow set {$, )} {$, )} {+, ), $ } {+, ), $} {*, +, ), $} 8
  • 9. EXAMPLE 1 (CONT.) The parsing table for the previous grammar is: 1. E TQ 2. Q +TQ | 3. T → FR id E E + ( E Q id Dr. Hussien M. Sharaf $ TQ Q Q R R T → FR R F *FR | (E) | id ) +TQ T → FR R F * TQ Q T 4. R 5. F R *FR F (E) 9
  • 10. FIRST AND FOLLOW EXAMPLE S →A  A → BC | DBC  B → bB ΄|  B ΄→ bB΄|  C →c|  D →a|d FIRST(S) = { a, b, c, d, FIRST(A) = { a, b, c, d, FIRST(B) = { b, } FIRST(B ΄) = { b, } FIRST(C) = { c, } FIRST(D) = { a, d }  Dr. Hussien M. Sharaf } } FOLLOW(S) = { $ } FOLLOW(A) = { $ } FOLLOW(B) = { c, $ } FOLLOW(B ΄) ={ c, $ } FOLLOW(C) = { $ } FOLLOW(D) = { b, c, $ } 10
  • 11. EXAMPLE 2 PAGE 156 The parsing table for the following grammar is: 1. S If_Stat | other 2. If_Stat if(Exp) S Else_part if S If_Stat S 3. Else_part If_Stat S other 4. Exp else else S | true | false true false $ other If_Stat if(exp) S Else_part Else_part Exp Dr. Hussien M. Sharaf Else_part else S Else_part exp true exp false 11
  • 12. EXAMPLE 3 The parsing table for the following grammar is: 1. E TQ 6. R *FR 2. 3. 4. 5. +TQ -TQ 7. R 8. R 9. F 10.F /FR Q Q Q T FR + - * / E Q ( ) 1 2 3 F Dr. Hussien M. Sharaf 8 6 7 4 5 8 9 $ 1 5 8 id 4 T R (E) id 8 10 12