Open In App

Parse Tree in Compiler Design

Here we will study the concept and uses of Parse Tree in Compiler Design. First, let us check out two terms :

Parse Tree:



Rules to Draw a Parse Tree:

  1. All leaf nodes need to be terminals.
  2. All interior nodes need to be non-terminals.
  3. In-order traversal gives the original input string.

Example 1: Let us take an example of Grammar (Production Rules).



S -> sAB
A -> a
B -> b

The input string is “sab”, then the Parse Tree is:

 

Example-2: Let us take another example of Grammar (Production Rules).

S -> AB
A -> c/aA
B -> d/bB

The input string is “acbd”, then the Parse Tree is as follows: 

 

Uses of Parse Tree:

Article Tags :