Computer >> Computer tutorials >  >> Programming >> Programming

Difference Between Top-down and Bottom-up Parsing


In this post, we will understand the differences between top down and bottom-up parsing −

Top-down parsing and bottom-up parsing are different techniques to parse a tree to reach the beginning of the tree. This can be done in two different methods, which have been discussed below.

Top-down Parsing

  • It is a parsing technique that looks at the highest level of the parse tree initially, and then works its way down to the parse tree.
  • It does this using the rules of grammar.
  • It uses left most derivation.
  • This parsing method tries to determine the left most derivations for an input string.
  • Here, the parsing is done from top-most part to the leaf node of the parse tree, i.e in top-down manner.
  • The main decision of this parsing technique is to select the production rule that needs to be used to construct the string.

Bottom-up Parsing

  • It is a parsing technique that is just the opposite of top-down parsing, i.e it looks at the lowest level of the parse tree and then works its way up to the parse tree.
  • It does this using the rules of grammar.
  • It uses right most derivation technique.
  • It tries to determine the right most derivations for an input strong.
  • It tries to reduce the input string to the start symbol of the grammar.
  • This is done by using a production rule that reduces the string to a starting symbol.