0% found this document useful (0 votes)
7 views7 pages

Compiler Design 20mss003

Top-down parsing constructs a parse tree starting from the root and guessing derivations until the input string is matched, primarily using recursive descent and LL parsers. It faces challenges such as left-recursion, which can lead to infinite loops, and backtracking. Left-factoring is a technique used to manipulate grammars for better compatibility with recursive-descent parsing.

Uploaded by

Akshaya V L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Compiler Design 20mss003

Top-down parsing constructs a parse tree starting from the root and guessing derivations until the input string is matched, primarily using recursive descent and LL parsers. It faces challenges such as left-recursion, which can lead to infinite loops, and backtracking. Left-factoring is a technique used to manipulate grammars for better compatibility with recursive-descent parsing.

Uploaded by

Akshaya V L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Top-down Parsing:

Recursive descent
parsing
Subject:COMPILER DESIGN
ROLL NO:20MSS003
Top-Down Parsing

 Top down parsing is the construction of a Parse tree by starting at


start symbol and “guessing” each derivation until we reach a string
that matches input.
 Top-Down parsing can be viewed as an attempt to find a left most
derivation for an input string.
 Parse tree starts from the root and creating the nodes of the parse
tree in preorder.
 Equivalently, it can be viewed as an attempt to construct the parse
tree rooted at the start symbol of the grammar for the input stream.
 Top-down parsers build parse trees from the top (root) to the bottom
(leaves).
 The parsers that use top-down parsing are
– Recursive descent parser
– LL parser (Left-to-right, Leftmost derivation).
Example:top down parsing

 The grammar:
• S->cAd
• A->ab|a
Input Word (w)=cad.
Problems with Top-down Parsing

 The two problems with top-down parsing are


 1. Left-recursion
 2. Backtracking
Left recursion
 A grammar ‘G’ is said to be left-recursive, if it
has a non-terminal A such that there is a
derivation
 A ->Aα, for some α, ‘A’ left-recursive
grammar can cause a top-down parser to go
into an infinite loop.
Recursive – Descent Parsing

 Recursive – descent parsing is a parsing with backtracking until to get


matched with input sentence.
 A parser that uses a set of recursive procedures to recognize its input
with backtracking is called a recursive-descent parsing.
 A useful method for manipulating grammars into a form suitable for
recursive-descent parsing is left-factoring.
 Left-factoring is the process of factoring out the common prefixes of
alternatives
Example

Ex:
Consider the grammar,
S->i C t S | i C t S e S | a
C ->b
Left-factoring this grammar will yield
S->i C t S S’ | a
S’->e S | ϵ
C ->b

You might also like