How to convert context free grammar to push down automata?

Data Structure AlgorithmsComputer ScienceComputers

A context-free grammar (CFG) consisting of a finite set of grammar rules is a quadruple (V, T, P, S) where,

  • V is a variable (non terminals).

  • T is a set of terminals.

  • P is a set of rules, P: V→ (V ∪ T)*, i.e., the left-hand side of the production rules P does have any right context or left context.

  • S is the start symbol.

Push down automata

A push down automata (PDA) consists of the following −

  • A finite non-empty set of states denoted by Q.

  • A finite non empty set of input symbols denoted by∑.

  • A finite non empty set of push down symbol ┌.

  • A special state is called the initial state denoted by q0.

  • A special symbol called the initial symbol on the push down store denoted by Z0.

  • The set of the final subset of Q denoted by F.

  • The transition function ∂= QX(∑U{^})X┌ to the set of finite subsets of QX┌*.

Example

The CFG is as follows −

S->aSa

S->aSa

S->c

Design a Push down automata to accept the string

To convert CFG to PDA first write the production rules and then pop.

The rules for the conversion are as follows −

  • S(q0, ɛ, ɛ)=(q0, ɛ)

  • S(q0, ɛ,S)=(q0,aSa)

  • S(q0, ɛ,S)=(q0,bsb)

  • (q0, ɛ,S)=(q0,c)

Now start pop to convert

  • S(q0,a,a)=(q1, ɛ)

  • S(q1,b,b)=(q2, ɛ)

  • S(q2,c,c)=(q3, ɛ)

Transition table

The transition table with regards to converting CFG to PDA is as follows −

SnoStateUnread inputStackTransition
1q0abbccbbaΕ1
2q0abbcbbaS1
3q0abbcbbaaSa2
4q1bbcbbaSa5
5q0bbcbbabSba3
6q2bcbbaSba6
7q0bcbbabsbba3
8q2cbbaSbba6
9q0cbbacbba4
10q3bbabba7
11q2baba6
12q1ɛɛ5

Whenever you reach the final state by using PDA then we can say that the context free grammar converts into Push down automata.

raja
Published on 16-Jun-2021 13:40:43
Advertisements