0% found this document useful (0 votes)
30 views

Topdown Parsing

The document discusses recursive descent parsing and predictive parsers. Recursive descent parsing involves attempting to find a leftmost derivation for an input stream and constructing a parse tree from the root node in preorder. Predictive parsers eliminate left recursion from a grammar to create a grammar that can be parsed without backtracking using recursive descent parsing. Transition diagrams are created for predictive parsers, with an initial and final state and edges labeled with production symbols to represent each production path from initial to final state. An example grammar and its corresponding transition diagram are provided.

Uploaded by

antony
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Topdown Parsing

The document discusses recursive descent parsing and predictive parsers. Recursive descent parsing involves attempting to find a leftmost derivation for an input stream and constructing a parse tree from the root node in preorder. Predictive parsers eliminate left recursion from a grammar to create a grammar that can be parsed without backtracking using recursive descent parsing. Transition diagrams are created for predictive parsers, with an initial and final state and edges labeled with production symbols to represent each production path from initial to final state. An example grammar and its corresponding transition diagram are provided.

Uploaded by

antony
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

A .

Antony Alex MCA Dr G R D College of Science CBE Tamil Nadu - India

Recursive Descent Parsing


Attempt to find a leftmost derivation for the input 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 Recursive Descent Parsing that involve Backtracking

Predictive Parsers
Eliminating left recursion and left factoring the 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 stmt while expr do stmt begin stmt_list end

Transition Diagrams for predictive parsers


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

Transition Diagrams for Predictive Parsers

Grammer
E TE E +TE | T FT T *FT | F (E) | id

E TE E: T
0 1

E
2

E +TE | E:
3

E
5

T FT T: F
7 8

T
9

T *FT | T:
10

11

T
12

13

F (E) | id F:
14

15

E id

)
16

17

Thank You

You might also like