Lecture 8
Lecture 8
Syntax Analysis
Awanish Pandey
February 5, 2025
February 5, 2025 1 / 13
Take aways from the last class
Predictive Parser
February 5, 2025 2 / 13
Take aways from the last class
Predictive Parser
Parsing algorithm
February 5, 2025 2 / 13
Take aways from the last class
Predictive Parser
Parsing algorithm
Computing first for grammar symbols.
February 5, 2025 2 / 13
Compute follow sets
February 5, 2025 3 / 13
Compute follow sets
February 5, 2025 3 / 13
Compute follow sets
February 5, 2025 3 / 13
Compute follow sets
February 5, 2025 3 / 13
Compute follow sets
February 5, 2025 3 / 13
Example
February 5, 2025 4 / 13
Example
February 5, 2025 4 / 13
Example
February 5, 2025 4 / 13
Example
February 5, 2025 4 / 13
Example
February 5, 2025 4 / 13
Construction of parse table
February 5, 2025 5 / 13
Construction of parse table
February 5, 2025 5 / 13
Construction of parse table
February 5, 2025 5 / 13
Construction of parse table
February 5, 2025 5 / 13
Construction of parse table
February 5, 2025 5 / 13
Construction of parse table
February 5, 2025 5 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Error handling
February 5, 2025 6 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Panic Model
February 5, 2025 7 / 13
Phase Level Recovery
February 5, 2025 8 / 13
Phase Level Recovery
February 5, 2025 8 / 13
Phase Level Recovery
February 5, 2025 8 / 13
Phase Level Recovery
February 5, 2025 8 / 13
Phase Level Recovery
February 5, 2025 8 / 13
Phase Level Recovery
February 5, 2025 8 / 13
Error Production
February 5, 2025 9 / 13
Error Production
February 5, 2025 9 / 13
Error Production
February 5, 2025 9 / 13
Error Production
February 5, 2025 9 / 13
Error Production
February 5, 2025 9 / 13
Global Correction
February 5, 2025 10 / 13
Global Correction
February 5, 2025 10 / 13
Global Correction
February 5, 2025 10 / 13
Global Correction
February 5, 2025 10 / 13
Global Correction
February 5, 2025 10 / 13
Error Recovery in LL(1) parser
February 5, 2025 11 / 13
Error Recovery in LL(1) parser
February 5, 2025 11 / 13
Error Recovery in LL(1) parser
February 5, 2025 11 / 13
Error Recovery in LL(1) parser
February 5, 2025 11 / 13
Error Recovery in LL(1) parser
February 5, 2025 11 / 13
Error Recovery in LL(1) parser
February 5, 2025 11 / 13
Bottom up parsing
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
a b b c d e
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
a b b c d e
a A b c d e
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
a b b c d e
a A b c d e
a A d e
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
a b b c d e
a A b c d e
a A d e
a A B e
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
a b b c d e
a A b c d e
a A d e
a A B e
S
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
Rightmost derivation
a b b c d e
a A b c d e
a A d e
a A B e
S
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
Rightmost derivation
a b b c d e
S → aABe
a A b c d e
a A d e
a A B e
S
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
Rightmost derivation
a b b c d e
S → aABe
a A b c d e
S → aAde
a A d e
a A B e
S
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
Rightmost derivation
a b b c d e
S → aABe
a A b c d e
S → aAde
a A d e
S → aAbcde
a A B e
S
February 5, 2025 12 / 13
Bottom up parsing
Construct a parse tree for an input string beginning at leaves and going towards root
Reduce a string w of input to start symbol of grammar
Consider the following grammar
S → aABe
A → Abc|b
B→d
Reduction of the string
Rightmost derivation
a b b c d e
S → aABe
a A b c d e
S → aAde
a A d e
S → aAbcde
a A B e
S → abbcde
S
February 5, 2025 12 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13
Shift reduce parsing
February 5, 2025 13 / 13