Recursive descent parsing is a top-down parsing technique that attempts to construct a parse tree for an input starting from the root node and creating child nodes in a preorder traversal. It involves backtracking if the parser reaches a point in the input where it cannot determine the next step. Predictive parsers avoid backtracking by eliminating left recursion and left factoring from the grammar upfront. Transition diagrams can be created for predictive parsers, with states connected by edges labeled with grammar symbols to show the parsing steps. An example transition diagram is provided for a grammar including productions for E, E', T, T', and F.
Scaling API-first – The story of a global engineering organization
Topdown parsing
1. A . Antony Alex MCA
Dr G R D College of Science – CBE
Tamil Nadu - India
2. 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
3. Predictive Parsers
• Eliminating left recursion and left factoring the
resulting grammar, a new grammar can beresulting 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
4. 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