SlideShare a Scribd company logo
SYNTAX
ANALYSIS
OR
PARSING
Lecture 06
FOLLOW EXAMPLE
 S  a S e | B
 B  b B C f | C
 C  c C g | d | ε
 FIRST(C) =
 FIRST(B) =
 FIRST(S) =
 FOLLOW(C) =
 FOLLOW(B) =
 FOLLOW(S) = {$}
Assume the first non-terminal is the start symbol
1. If A is start symbol, put $ in FOLLOW(A)
2. Productions of the form B  α A β,
Add FIRST(β) – {ε} to FOLLOW(A)
3. Productions of the form B  α A or
B  α A β where β ⇒*
ε
Add FOLLOW(B) to FOLLOW(A)
2
FOLLOW EXAMPLE
 S  a S e | B
 B  b B C f | C
 C  c C g | d | ε
 FIRST(C) = {c,d,ε}
 FIRST(B) = {b,c,d,ε}
 FIRST(S) = {a,b,c,d,ε}
 FOLLOW(C) =
 FOLLOW(B) =
 FOLLOW(S) = { }$, e
{c,d} ∪ FOLLOW(S)
= {c,d,e,$}
{f,g} ∪ FOLLOW(B)
= {c,d,e,f,g,$}
3
PREDICTIVE PARSING
4
PREDICTIVE PARSING
 LL(1) Grammars
 Can do predictive parsing
 Can select the right rule
 Looking at only the next 1 input symbol
 First L : Left to Right Scanning
 Second L: Leftmost derivation
 1 : one input symbol look-ahead for predictive decision
 LL(k) Grammars
 Can do predictive parsing
 Can select the right rule
 Looking at only the next k input symbols
 Techniques to modify the grammar:
 Left Factoring
 Removal of Left Recursion
 LL(k) Language
 Can be described with an LL(k) grammar
5
TABLE DRIVEN PREDICTIVE
PARSING
6
PARSE TABLE CONSTRUCTION
7
TABLE DRIVEN PREDICTIVE
PARSING
8
TABLE DRIVEN PREDICTIVE
PARSING
9
PREDICTIVE PARSING
ALGORITHM
10
PREDICTIVE PARSING
11
PREDICTIVE PARSING
12
PREDICTIVE PARSING
13
PREDICTIVE PARSING
14
PREDICTIVE PARSING
15
PREDICTIVE PARSING
16
PREDICTIVE PARSING
17
PREDICTIVE PARSING
18
PREDICTIVE PARSING
19
PREDICTIVE PARSING
20
PREDICTIVE PARSING
21
PREDICTIVE PARSING
22
PREDICTIVE PARSING
23
PREDICTIVE PARSING
24
PREDICTIVE PARSING
25
PREDICTIVE PARSING
26
PREDICTIVE PARSING
27
PREDICTIVE PARSING
28
PREDICTIVE PARSING
29
PREDICTIVE PARSING
30
PREDICTIVE PARSING
31
PREDICTIVE PARSING
32
PREDICTIVE PARSING
33
PREDICTIVE PARSING
34
PREDICTIVE PARSING
35
PREDICTIVE PARSING
36
PREDICTIVE PARSING
37
PREDICTIVE PARSING
38
PREDICTIVE PARSING
39
PREDICTIVE PARSING
40
PREDICTIVE PARSING
41
PREDICTIVE PARSING
42
PREDICTIVE PARSING
43
PREDICTIVE PARSING
44
PREDICTIVE PARSING
45
PREDICTIVE PARSING
46
PREDICTIVE PARSING
47
PREDICTIVE PARSING
48
PREDICTIVE PARSING
49
PREDICTIVE PARSING
50
PREDICTIVE PARSING
51
PREDICTIVE PARSING
52
PREDICTIVE PARSING
53
PREDICTIVE PARSING
54
PREDICTIVE PARSING
55
PREDICTIVE PARSING
56
PREDICTIVE PARSING
57
RECONSTRUCTING THE PARSE
TREE
58
RECONSTRUCTING THE PARSE
TREE
59
RECONSTRUCTING THE PARSE
TREE
60
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
61
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
62
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
63
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
64
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
65
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
66
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
67
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
68
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
69
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
70
EXAMPLE: THE “DANGLING ELSE”
GRAMMAR
71
LL(1) GRAMMAR
 LL(1) grammars
 Are never ambiguous.
 Will never have left recursion.
 Furthermore...
 If we are looking for an “A” and the next symbol is
“b”,
 Then only one production must be possible
 Although elimination of left recursion and left
factoring is easy.
 Some grammar will never be a LL(1) grammar.
LL(1) Grammar
72
LL(1) GRAMMAR
73
PROPERTIES OF LL(1) GRAMMAR
 A grammar G is LL(1) if an only if whenever A
→α | β are two distinct productions of G the
following conditions hold:
1. For no terminal a do both α and β derive strings
beginning with a.
2. At most one of α and β can derive the empty string.
3. If then β ⇒* ε , then α does not derive any string
beginning with a terminal in FOLLOW(A).
74
ERROR RECOVERY
a + b $
Y
X
$
Z
Input
Predictive Parsing
Program
Stack Output
Parsing Table
M[A,a]
When Do Errors Occur? Recall Predictive Parser Function:
1. If X is a terminal and it doesn’t match input.
2. If M[X, Input] is empty – No allowable actions 75
ERROR RECOVERY
76
ERROR RECOVERY: SKIP INPUT
SYMBOLS
77
ERROR RECOVERY: POP THE
STACK
78
ERROR RECOVERY: PANIC MODE
79
ERROR RECOVERY - TABLE
ENTRIES
80
QUESTIONS ?
81

More Related Content

Similar to Lecture 06 syntax analysis 3 (20)

PPT
Top down parsing
ASHOK KUMAR REDDY
 
PPT
compiler-lecture-6nn-14112022-110738am.ppt
SheikhMuhammadSaad3
 
PPTX
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
FutureTechnologies3
 
PPT
51114.-Compiler-Design-Syntax-Analysis-Top-down.ppt
Padamata Rameshbabu
 
PPT
51114.-Compiler-Design-Syntax-Analysis-Top-down.ppt
Padamata Rameshbabu
 
PDF
Syntax Analysis PPTs for Third Year Computer Sc. and Engineering
DrRajurkarArchanaMil
 
PPT
Cd2 [autosaved]
BBDITM LUCKNOW
 
PPT
Lecture 05 syntax analysis 2
Iffat Anjum
 
PDF
LL Parsing
Eelco Visser
 
PPT
Parsing
khush_boo31
 
PPTX
Syntax Analysis.pptx
AshaS74
 
DOCX
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
 
PDF
Lecture8 syntax analysis_4
Mahesh Kumar Chelimilla
 
PDF
05SyntaxAnalysis in compiler design notespdf
Padamata Rameshbabu
 
PPTX
11CS10033.pptx
ssuser0be977
 
PDF
CS17604_TOP Parser Compiler Design Techniques
d72994185
 
PPTX
Syntactic Analysis in Compiler Construction
voyoc79528
 
PPTX
3. Syntax Analyzer.pptx
Mattupallipardhu
 
PPT
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
nithya g
 
Top down parsing
ASHOK KUMAR REDDY
 
compiler-lecture-6nn-14112022-110738am.ppt
SheikhMuhammadSaad3
 
Top Down Parsing, Predictive Parsing
Tanzeela_Hussain
 
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
FutureTechnologies3
 
51114.-Compiler-Design-Syntax-Analysis-Top-down.ppt
Padamata Rameshbabu
 
51114.-Compiler-Design-Syntax-Analysis-Top-down.ppt
Padamata Rameshbabu
 
Syntax Analysis PPTs for Third Year Computer Sc. and Engineering
DrRajurkarArchanaMil
 
Cd2 [autosaved]
BBDITM LUCKNOW
 
Lecture 05 syntax analysis 2
Iffat Anjum
 
LL Parsing
Eelco Visser
 
Parsing
khush_boo31
 
Syntax Analysis.pptx
AshaS74
 
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
 
Lecture8 syntax analysis_4
Mahesh Kumar Chelimilla
 
05SyntaxAnalysis in compiler design notespdf
Padamata Rameshbabu
 
11CS10033.pptx
ssuser0be977
 
CS17604_TOP Parser Compiler Design Techniques
d72994185
 
Syntactic Analysis in Compiler Construction
voyoc79528
 
3. Syntax Analyzer.pptx
Mattupallipardhu
 
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
nithya g
 

More from Iffat Anjum (20)

PPTX
Fog computing ( foggy cloud)
Iffat Anjum
 
PPTX
Cognitive radio network_MS_defense_presentation
Iffat Anjum
 
PPTX
Lecture 15 run timeenvironment_2
Iffat Anjum
 
PPT
Lecture 16 17 code-generation
Iffat Anjum
 
PPTX
Lecture 14 run time environment
Iffat Anjum
 
PPTX
Lecture 12 intermediate code generation
Iffat Anjum
 
PPT
Lecture 13 intermediate code generation 2.pptx
Iffat Anjum
 
PPTX
Lecture 11 semantic analysis 2
Iffat Anjum
 
PPTX
Lecture 09 syntax analysis 05
Iffat Anjum
 
PPTX
Lecture 10 semantic analysis 01
Iffat Anjum
 
PPTX
Lecture 07 08 syntax analysis-4
Iffat Anjum
 
PPT
Lecture 03 lexical analysis
Iffat Anjum
 
PPT
Lecture 04 syntax analysis
Iffat Anjum
 
PPTX
Lecture 02 lexical analysis
Iffat Anjum
 
PDF
Lecture 01 introduction to compiler
Iffat Anjum
 
PPT
Compiler Design - Introduction to Compiler
Iffat Anjum
 
PPTX
Distributed contention based mac protocol for cognitive radio
Iffat Anjum
 
PPT
On qo s provisioning in context aware wireless sensor networks for healthcare
Iffat Anjum
 
PPT
Data link control
Iffat Anjum
 
PPT
Pnp mac preemptive slot allocation and non preemptive transmission for provid...
Iffat Anjum
 
Fog computing ( foggy cloud)
Iffat Anjum
 
Cognitive radio network_MS_defense_presentation
Iffat Anjum
 
Lecture 15 run timeenvironment_2
Iffat Anjum
 
Lecture 16 17 code-generation
Iffat Anjum
 
Lecture 14 run time environment
Iffat Anjum
 
Lecture 12 intermediate code generation
Iffat Anjum
 
Lecture 13 intermediate code generation 2.pptx
Iffat Anjum
 
Lecture 11 semantic analysis 2
Iffat Anjum
 
Lecture 09 syntax analysis 05
Iffat Anjum
 
Lecture 10 semantic analysis 01
Iffat Anjum
 
Lecture 07 08 syntax analysis-4
Iffat Anjum
 
Lecture 03 lexical analysis
Iffat Anjum
 
Lecture 04 syntax analysis
Iffat Anjum
 
Lecture 02 lexical analysis
Iffat Anjum
 
Lecture 01 introduction to compiler
Iffat Anjum
 
Compiler Design - Introduction to Compiler
Iffat Anjum
 
Distributed contention based mac protocol for cognitive radio
Iffat Anjum
 
On qo s provisioning in context aware wireless sensor networks for healthcare
Iffat Anjum
 
Data link control
Iffat Anjum
 
Pnp mac preemptive slot allocation and non preemptive transmission for provid...
Iffat Anjum
 
Ad

Recently uploaded (20)

PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Controller Request and Response in Odoo18
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Introduction to Indian Writing in English
Trushali Dodiya
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
Ad

Lecture 06 syntax analysis 3