- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Derive the string “abb” for leftmost and rightmost derivation

## Problem

Let’s consider a grammar to derive “abb” string using LMD and RMD

S->AB/ ε

A-> aB

B-> Sb

## Solution

We have to use context free grammar.

Derivation is a sequence of production rules, which is used to get input strings.

**During parsing, we have to take two decisions**, which are as follows −

- We have to decide which non-terminal has to be replaced.
- We have to decide which non-terminal has to be replaced by using which production rule.

There are two options to decide which non-terminal has to be replaced with production rule −

- Leftmost derivation
- Rightmost derivation

## Leftmost derivation

The input is scanned and replaced with production rules from left to right.

The given production rules are: S->AB/ ε A-> aB B-> Sb Let’s derive the string “abb” using LMD S->AB ->aBB {A->aB} ->aSbB {B->Sb} ->abB {S-> ε} ->abSb {B->Sb} ->abb {S-> ε} Which is our final string

## Rightmost derivation

The input is scanned and replaced with a production rule from right to left.

The given production rules are: S->AB/ ε A-> aB B-> Sb Let’s derive the string “abb” using RMD S -> AB ->ASb {B->Sb} ->Ab {S-> ε} ->aBb {A->aB} ->aSbb {B->Sb} ->abb {S-> ε} Reached our final string

- Related Questions & Answers
- Print leftmost and rightmost nodes of a Binary Tree in C Program.
- Construct the derivation tree for the string aabbabba.
- Program to check we can reach leftmost or rightmost position or not in Python
- Mechanics of Train Movement and Derivation for Tractive Effort
- Derive the string “00101” using LMD and RMD while using CFG
- What is accounting and derive accounting equation?
- Explain the concept of derivation in TOC
- EMF Equation of DC generator – Derivation and Examples
- What are Parse Trees (Derivation Trees)?
- Golang Program to find the position of the rightmost set bit
- What is a Derivation tree in TOC?
- Derivation of Fourier Transform from Fourier Series
- Position of rightmost set bit in C++
- Position of rightmost different bit in C++
- Python Program to Clear the Rightmost Set Bit of a Number

Advertisements