Pda PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Construct the PDA to accept the following L={wwR } by empty stack.

Solution

Transition Diagram

PDA M is defined as,

1)  (q1 , O, R) {( q1 , BR)}


2)  (q1 ,1, R) {( q1 , GR )}
3)  (q1 , O, B) {( q1 , BB)} ,(q2,  )}
4)  (q1 , O, G) {( q1 , BG )}
5)  (q1 ,1, B) {( q1 , GB )}
6)  (q1 ,1, G) {( q1 , GG )}( q 2 ,)}
7)  (q2 , O, B) {( q2 ,)}
8)  (q 2 ,1, G) {( q 2 ,)}
9)  (q1 ,, R ) {( q 2 ,)}
10)  (q 2 ,, R ) {( q 2 ,)}

M  ({q1 , q 2 , }, {0,1}, {R, B, G}, ,91 , R , )

Let x=0110

(q1, 0110, R)  (q1 ,110 , BR )

 (q1 ,10, GBR )  (q1 , O, BR )


 (q1 , O, GGBR )  (q 2 ,, R )

 (q1 , O, BGGBR )  (q 2 ,,)

 (q1 ,, BBGGBR )

x = 0110 is accepted by PDA

4) Convert the Grammar

S OSI| A

A IAO| S | E

Design a PDA that accepts the same language by empty stack.

Solution

The Given grammar

G=(V,T,P,S)

Where V = {S,A}

T = {0,1}

To construct a PDA M = Q, , , , q 0 , z 0 , )

Where

Q = {P1,q2}

  T {0,1}

 {v}U{z 0 }

= {S,A,O,1,Z0}

where  is defined as,

1) (q1 ,, z 0 )  q 2 , S)

For each production


2)  (q 2 ,, s)  (q 2 , OSI )
3)  (q 2 ,, s)  (q 2 , A)
4)  (q 2 ,, A)  (q 2 , S)
5)  (q 2 ,, A)  (q 2 , IAO)
6)  (q 2 ,, A)  (q 2 ,)

For each terminal

7)  (q 2 , o, O)  (q 2 ,)
8)  (q 2 ,1,1)  (q 2 ,)
9)  (q 2 , o,1)  (q 2 ,)
10)  (q 2 ,1,0)  (q 2 ,)

4) Design a PDA accepting L = {anbn | n  1} by final state

Solution:

Transition Diagram:

Transition function 

1) (q 0 , o, z 0 )  (q 0 , Oz 0 )
2) (q 0 , o, o)  (q 0 , oo)
3) (q 0 ,1, o)  (q1 ,)
4) (q1 ,1, o)  (q1 ,)
5) (q1 ,, z 0 )  (q 2 ,)

The PDA is defined as

M = ( Q, , , , q 0 , z 0 , F)
Q = {q0,q1,q2}

 {0,1)

  {0;1, z 0}

F = {q2}

Let us consider the string w = 0011

(q 0 ,0011; z 0 )  (q 0 ,011; oz 0 )  (q 1 ,1;0z 0 )  (q 1 ,; z 0 )  (q 2 ,)

Final state is reached so the string w = 0011 is accepted.

2. CONVERSION OF PDA TO CFL 


Convert the given PDA to CFG. ]

Given PDA

M = ({q0,q1},{0,1},{x,z0},  , q0,q0,  )

where  is given by

 (q 0 , o, z 0 )  (q 0 , xz 0 )

 (q 0 , o, x )  (q 0 , xx )

 (q 0 ,1, x )  (q1 ,)

 (q1 ,1, x )  (q1 ,)

(q1 ,, x )  (q1 ,)

(q1 ,, z 0 )  (q1 ,)

Construct a CFG G, generating N(M)

Solution :

V {s, [q 0 , x, q 0 ] , [q 0 , x, q1 ] , [q1 , x, q 0 ], [q1 , x, q1 ][q 0 , z 0 , q 0 ][q 0 , z 0 , q1 ][q1 , z 0 , q 0 ][q1 , z 0 , q1 ]}


T = {0,1}

The productions for s are

S  [q 0 , z 0 , q 0 ] (from rule 1)

S [q 0 , z 0 , q1 ]

The Productions for each transition functions of M.

1)  (q 0 , o, z 0 )  (q 0 , x, z 0 )

The Productions are

[q 0 , z 0 , q 0 ]  o [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]

[q 0 , z 0 , q 0 ]  o [q 0 , x, q1 ][q1 , z 0 , q 0 ]

[q 0 , z 0 , q1 ]  o [q 0 , x, q 0 ][q 0 , z 0 , q1 ]

[q 0 , z 0 , q1 ]  o [q 0 , x, q1 ][q1 , z 0 , q1 ]

2) There is a move  (q 0 , o, x )  {( q 0 , xx )}

The productions are

[q 0 , x, q 0 ]  o [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]

[q 0 , x, q 0 ]  o [q 0 , x, q1 ][q1 , x, q 0 ]

[q 0 , x, q1 ]  o [q 0 , x, q 0 ][q 0 , x, q1 ]

[q 0 , x, q1 ]  o [q 0 , x, q1 ][q1 , x, q1 ]

3)  (q 0 ,1, x )  {( q1 ,)}

The production is

[q 0 , x, q1 ] 1

4)  (q1 ,1, x )  {( q1 ,)}

The production is
[q1 , x, q1 ] 1

5)  (q1 ,, x )  {( q1 ,)}

The production is

[q1 , x, q1 ] 

6)  (q 0 ,1, x )  {( q1 ,)}

The production is

[q 0 , x, q1 ] 1

 There are no production for the variable [q1 , x, q 0 ] and [q1 , z 0 , q 0 ]


 As all the productions for [q 0 , x, q 0 ] and [q 0 , z 0 , q 0 ] have [q1 , x, q 0 ] or [q1 , z 0 , q 0 ] on the
right, no string of terminals can be derived from [q 0 , x, q 0 ] or [q 0 , z 0 , q 0 ]
 Deleting all production involving one of these variables on either the right or left, we
end up with the following productions.

S [q 0 , z 0 , q1 ]

[q 0 , z 0 , q1 ]  o [q 0 , x, q1 ][q1 , z 0 , q1 ]

[q 0 , x, q1 ]  o [q 0 , x, q1 ][q1 , x, q1 ]

[q 0 , x, q1 ] 1

[q1 , z0 , q1 ] 

[q1 , x, q1 ] 

[q1 , x, q1 ] 1

1) Give a grammer for the language N(M) where


M  ({q 0 , q1}, {0,1}, {z 0 , x}, , q 0 , z 0 , ) and  is given by

 (q 0 ,1, z 0 ) {( q 0 , xz 0 )}

 (q 0 ,1, x ) {( q 0 , xx )}
 (q 0 ,0, x ) {( q1 , x )}

 (q 0 ,, z 0 ) {( q 0 ,)}

 (q1 ,1, x ) {( q1 ,)}

 (q1 ,0, z 0 ) {( q 0 , z 0 )}

V {S1 , [q 0 , z 0 , q 0 ] , [q 0 , z 0 , q1 ] , [q1 , z 0 , q 0 ], [q1 , z 0 , q1 ][q 0 , x, q 0 ][q 0 , x, q1 ][q1 , x, q 0 ][q1 , x, q1 ]}

T = {0,1}

P = set of productions

S  [q 0 , z 0 , q 0 ]

S [q 0 , z 0 , q1 ]

1)  (q 0 ,1, z 0 ) {( q 0 , xz 0 )}

[q 0 , z 0 , q 0 ] 1 [q 0 , x, q 0 ][q 0 , z 0 , q 0 ]

[q 0 , z 0 , q 0 ] 1 [q 0 , x, q1 ][q1 , z 0 , q 0 ]

[q 0 , z 0 , q1 ] 1 [q 0 , x, q 0 ][q 0 , z 0 , q1 ]

[q 0 , z 0 , q1 ] 1 [q 0 , x, q1 ][q1 , z 0 , q1 ]

2)  (q 0 ,1, x )  {( q 0 , xx )}

[q 0 , x, q 0 ] 1 [q 0 , x, q 0 ][q 0 , x, q 0 ]

[q 0 , x, q 0 ] 1 [q 0 , x, q1 ][q1 , x, q 0 ]

[q 0 , x, q1 ] 1 [q 0 , x, q 0 ][q 0 , x, q1 ]

[q 0 , x, q1 ] 1 [q 0 , x, q1 ][q1 , x, q1 ]

3)  (q 0 ,0, x )  (q1 , x )

[q 0 , x, q 0 ]  0 [q1 , x, q 0 ]
[q 0 , x , q1 ]  0 [q1 , x , q1 ]

4)  (q 0 ,, z 0 )  {( q 0 ,)}

[q 0 , z 0 , q 0 ] 

5)  (q1 ,1, x )  {( q1 ,)}

[q1 , x, q1 ] 1

6)  (q1 ,0, z 0 )  {( q 0 , z 0 )}

[q1 , z 0 , q 0 ]  0 [q 0 , z 0 , q 0 ]

[q1 , z 0 , q1 ]  0 [q 0 , z 0 , q1 ]

 There are no production for the variable [q1 , x, q 0 ]


 As all the productions for [q 0 , x, q 0 ] have [q1 , x, q 0 ] on the right, no string of terminals
can be derived from [q 0 , x, q 0 ]
 Deleting all production involving one of these variables on either the right or left, we
end up with the following productions.

[q 0 , z 0 , q1 ] 1 [q 0 , x, q1 ][q1 , z 0 , q1 ]

[q 0 , z o , q 0 ] 1 [q 0 , x, q1 ][q1 , z o , q 0 ]

[q 0 , x, q1 ] 1 [q 0 , x, q1 ][q1 , x, q1 ]

[q 0 , x , q1 ]  0 [q1 , x, q1 ]

[q1 , z 0 , q 0 ] 

[q1 , x, q1 ] 1

[q1 , z o , q 0 ]  0 [q 0 , z o , q 0 ]

[q1 , z o , q1 ]  0 [q 0 , z o , q1 ]

You might also like