According to Chomsky Hierarchy, Context-Free Grammar belongs to grammar type-2. A CFG is quadruple, G = (V, T, P, S). G is the grammar used to generate the string of a language by using a finite collection of production rules. T is the final collection of terminal symbols which are denoted by lowercase letters. V is the final collection of non-terminal symbols which are denoted by uppercase letters. P is a finite collection of production rules. These rules are used for interchanging the non-terminals symbols in a string present on the left side of the production with other terminal or nonterminal symbols present on the right side of the production. S is considered to be the start symbol starting from which a string is derived. A Non-terminal is substituted repeatedly on the right-hand of the production to derive a string until all the non-terminals have been terminal symbols.
Programming languages in which a string can be generated in more than one way are said to have ambiguous grammar. In such a case, to select the intended parse tree of an ambiguous construct, semantic information is required. A derivation or a parse tree is used to represent the semantic information of a string which is generated from a Context-Free Grammar.
A derivation tree has a node that consists of a variable present on the left of the production rule while the child nodes consist of variables present on the right of the same production rule. A derivation tree illustrates how each variable is substituted in the derivation from the root identified with the start symbol, to the leaves or the terminals [1].
At any stage during a parse, on deriving a form that is not yet a sentence (sentential form), we have two choices to make:
a. Determine which non-terminal in the sentential form to which a production rule must be applied to.
b. Or which production rule for that non-terminal to apply
The first decision here is relatively easy. The input string is scanned from left to right in order to efficiently derive the leftmost terminal of the output sentence. Thus, the process of choosing the leftmost non-terminal occurring in the sentential form and applying a production rule is performed. This type of parsing technique is called the top-down parse and is also known as the leftmost derivation [2]. The top-down parsing technique starts the evaluation at the root node of the tree and proceeds systematically down the tree until it reaches the leaves and the given string is generated.
The situation is reversed in the bottom-up parsing technique, and the production rules are applied in the reverse order to the symbols present on the left. The Bottom-up approach starts the evaluation directly from the leaves i.e., the lowest level of the tree and proceeds upwards systematically for parsing the node.