topdown parsing
DESCRIPTION
Top-Down ParsingTRANSCRIPT
![Page 1: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/1.jpg)
A . Antony Alex MCA
Dr G R D College of Science – CBE
Tamil Nadu - India
![Page 2: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/2.jpg)
Recursive Descent Parsing
• Attempt to find a leftmost derivation for the
input streaminput stream
• Attempt to construct a parse tree for the input
starting from the root and creating the nodes
of the parse tree in preorder
• A general form of top down parsing called • A general form of top down parsing called
Recursive Descent Parsing that involve
Backtracking
![Page 3: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/3.jpg)
Predictive Parsers
• Eliminating left recursion and left factoring the
resulting grammar, a new grammar can be resulting grammar, a new grammar can be
obtained that can be parsed by a recursive-
descent parser without backtracking
stmt if expr then stmt else stmtstmt if expr then stmt else stmt
while expr do stmt
begin stmt_list end
![Page 4: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/4.jpg)
Transition Diagrams for predictive
parsers
• Create an initial and final (return) state• Create an initial and final (return) state
• For each production A → X1 X2 ….. X n
create a path from the initial to the final
state with edges labeled X1 , X2 , …… X n
![Page 5: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/5.jpg)
Transition Diagrams for Predictive
Parsers
Example
![Page 6: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/6.jpg)
Grammer
• E → TE’
• E’ → +TE’ | ε• E’ → +TE’ | ε
• T → FT’
• T’ → *FT’ | ε
• F → (E) | id
![Page 7: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/7.jpg)
0 1
E → TE’
2E:T E’
E’ → +TE’ | ε
4 5 6E’:T E’
3+
E’:
ε
![Page 8: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/8.jpg)
7 8
T → FT’
9T:F T’
T’ → *FT’ | ε
11 12 13T’:F T’
10*
T’:
ε
![Page 9: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/9.jpg)
F → (E) | id
15 16 17F:E )
14(
15 16F: 14
id
![Page 10: Topdown parsing](https://reader038.vdocuments.mx/reader038/viewer/2022110308/5577ba84d8b42a1c068b4ade/html5/thumbnails/10.jpg)
Thank You