Sei sulla pagina 1di 5

IUBAT – International University of Business Agriculture and

Technology

CSC 397

Theory of Computation

Assignment No: 02
Report on: Program of PDA to recognize w#𝑤 𝑅

Prepared For:

Dr. Ehteshamul Haque

Course Instructor

Prepared By:
Suvrho Mojumder
ID: 14303040
Section: D
Fall 2017

Submission Date
27/11/2017
State diagram for w#𝒘𝑹 :

W, εW W, 𝑤 𝑅  ε

ε ,ε  $ #, ε ε ε ,$  ε

Formal Definition of PDA forw#𝒘𝑹 :

The formal definition of PDA for the given pattern is given below:
P = {Q, ∑,Г, δ, q0, F}, where

Q = {ql, q2, q3, q4},

∑ = {a, b, c, d},

Г = {0, $}

F = {q4}
Program:
# include <stdio.h>

int main()

int i=0, tos=0, state=1;

char str[20], stak[20];

printf("\n input string W#W = ");

scanf("%s",str);

stak[tos]= '$'; tos++;

while(1)

if(state==1 && str[i] !='#'){state=1; stak[tos]=str[i]; tos++; i++; }

else

if(state==1 && str[i]=='#'){state=2; i++; tos--; }

else

if(state==2 && stak[tos]==str[i] ){state=2; tos--; i++; }

else

if(state==2 && stak[tos]=='$' && str[i]=='\0' ){state=3; break; }

else

break;

if(state==3)printf(" is valid ");

else

printf(" is not valid ");

return 0;
}

Output:

Potrebbero piacerti anche