- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- 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 Articles
- 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
- Derive the string â€ś00101â€ť using LMD and RMD while using CFG
- Derive the formula for kinetic energy.
- Derive the formula for potential energy.
- Mechanics of Train Movement and Derivation for Tractive Effort
- Explain inverse square rule and its derivation for class 9.
- Derive the formula for the universal law of gravitation.
- Derive An Expression For Electric Energy
- Bohr radius - definition and derivation
- Derive the formula for finding the base of a Right angle triangle.
- Derive an expression for the heat produced by electric current and state Joule's law.
- Derivation of Torsion Equation
- EMF Equation of DC generator â€“ Derivation and Examples

Advertisements