Header Ads

  • Highlights

    👩🏻‍💻 Hello Readers 🧑🏻‍💻!!! Would you like to Explore more ? Hit on ⓘ(Ads)... ✨🌹

    What is a Parse Tree or Derivation Tree?

    Let's understand about parse tree which is also known as the derivation tree.

    Parsing is a way to derive string from given grammar by parse tree or better to say derivation tree.

    Parse tree or derivation tree is the tree representation having root nodes with its corresponding child node. With the help of that tree, we derive context-free language from a given grammar. A parse tree is an ordered tree in which the left-hand side of production represents a parent node and the right-hand side of production () represents a children node.

    There are certain conditions for constructing a parse tree from a given CFG. Those are as follows.

    ·        Each vertex of the tree must have a label. The label is non-terminal or terminal or null (Λ).

    ·        The root of the tree is the start symbol, i.e., S.

    ·        The label of the internal vertices is a non-terminal symbol VN.

    ·        If there is a production A → X1X2 . . .  XK, then for a vertex label A, the children of that node will be X 1X2 . . .  XK.

     A vertex n is called a leaf of the parse tree if its label is a terminal symbol Σ or null (Λ)

    The parse tree construction is possible only for CFG. This is because of the properties of a tree match with the properties of CFG.
    Here, we are describing the similar properties of a tree and a CFG.

    ·    For a tree, there must be some root. For every CFG, there is a single start symbol.

    ·      Each node of a tree has a single label. For every CFG at the LHS, there is a single non-terminal.

    ·       A child node is derived from a single parent. For constructing a CFL from a given CFG, a non-terminal is replaced by a suitable string at the RHS (if for a non-terminal, there are multiple productions). Each of the characters of the string is generating a node. That is, for each single node there is a single parent.

    The parse tree construction is possible only for CFG. This is because of the properties of a tree match with the properties of CFG.

    Properties of trees that are similar to CFG were described here:

    ·        Tree and CFG both have a single initial state. Root in tree & start symbol in CFG.

    ·     Single label in each node of the tree, similarly there is single non-terminal for every CFG at its LHS.

    ·     Each node of a tree has a single label. For every CFG at the LHS, there is a single non-terminal.

    ·        A child node is derived from a single parent. For constructing a CFL from a given CFG, a non-terminal is replaced by a suitable string at the RHS (if for a non-terminal, there are multiple productions). Each of the characters of the string is generating a node. That is, for every single node there is a single parent.

    Because of the above-mentioned similarities, we can construct a parse tree or derivation tree of CFG only.

    Note: If we talk about context-sensitive grammar as bB → aa or AA → B then since more than two elements are on the left side of the production it will not be possible to generate a parse tree as a parse tree has only a single parent node.

    Consider the following examples.

     Also, Study about: 

    Also Read, some interview tips

    No comments

    Post Bottom Ad

    Powered by Blogger.