Compiler Design and Construction - Old Questions
3. Differentiate between top-down parsing and bottom-up parsing.
Top-down Parsing |
Bottom-up Parsing |
It
is a parsing strategy that first looks at the highest level of the parse tree
and works down the parse tree by using the rules of grammar. |
It
is a parsing strategy that first looks at the lowest level of the parse tree
and works up the parse tree by using the rules of grammar. |
Top-down
parsing attempts to find the left most derivations for an input string. |
Bottom-up
parsing can be defined as an attempt to reduce the input string to start symbol
of a grammar. |
In
this parsing technique we start parsing from top (start symbol of parse tree)
to down (the leaf node of parse tree) in top-down manner. |
In
this parsing technique we start parsing from bottom (leaf node of parse tree)
to up (the start symbol of parse tree) in bottom-up manner. |
This
parsing technique uses Left Most Derivation. |
This
parsing technique uses Right Most Derivation. |
Its
main decision is to select what production rule to use in order to construct
the string. |
Its
main decision is to select when to use a production rule to reduce the string
to get the starting symbol. |
A top-down parser can be easily structured
and formed. |
It is difficult to produce a bottom-up
parser |
It
is less powerful. |
It
is more powerful. |
Error
detection is easy. |
Error
detection is difficult. |