Difference between Top-Down Parsing and Bottom-Up Parsing


Top-Down Parsing and Bottom-Up Parsing are used for parsing a tree to reach the starting node of the tree. Both the parsing techniques are different from each other. The most basic difference between the two is that top-down parsing starts from top of the parse tree, while bottom-up parsing starts from the lowest level of the parse tree.

Read this article to learn more about top-down parsing and bottom-up parsing and how these two parsing techniques are different from each other.

What is Top-Down Parsing?

Top-Down Parsing technique is a parsing technique which starts from the top level of the parse tree, move downwards, evaluates rules of grammar. In other words, top-down parsing is a parsing technique that looks at the highest level of the tree at start and then moves down to the parse tree.

The top-down parsing technique tries to identify the leftmost derivation for an input. It evaluates the rules of grammar while parsing. Consequently, each terminal symbol in the top-down parsing is produced by multiple production of grammar rules.

Since top-down parsing uses leftmost derivation, hence in this parsing technique, the leftmost decision selects what production rule is used to construct the string.

What is Bottom-Up Parsing?

Bottom-Up Parsing technique is again a parsing technique which starts from the lowest level of the parse tree, move upwards and evaluates the rules of grammar. Therefore, the bottomup parsing technique makes an attempt to decrease the input string to the start symbol of the grammar.

In bottom-up parsing, the parsing of a tree starts from the leaf node (bottom node) of the parse tree and works towards the start node of the parse tree. Hence, it works in a bottom-up manner so its named.

The bottom-up parsing technique makes use of rightmost derivation. The main rightmost decision is to select when a production rule is used to reduce the string to get the starting symbol of the parsing tree.

Now, let us discuss the differences between top-down parsing and bottom-up parsing in detail.

Difference between Top-Down Parsing and Bottom-Up Parsing

The following are some of the important differences between TopDown Parsing and BottomUp Parsing −

Key

Top Down Parsing

Bottom Up Parsing

Strategy

Top-down approach starts evaluating the parse tree from the top and move downwards for parsing other nodes.

Bottom-up approach starts evaluating the parse tree from the lowest level of the tree and move upwards for parsing the node.

Attempt

Top-down parsing attempts to find the left most derivation for a given string.

Bottom-up parsing attempts to reduce the input string to first symbol of the grammar.

Derivation Type

Top-down parsing uses leftmost derivation.

Bottom-up parsing uses the rightmost derivation.

Objective

Top-down parsing searches for a production rule to be used to construct a string.

Bottom-up parsing searches for a production rule to be used to reduce a string to get a starting symbol of grammar.

Conclusion

The most significant difference that you should note here is that top-down parsing uses leftmost derivation, while bottom-up parsing uses the rightmost derivation.

Updated on: 22-Feb-2023

29K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements