Tuesday, 14 October 2014

C Program to implement Recursive Deceptive Parsing

#include
#include
#include
void main()
{
int i,j,k;
char a[20],b[20],c[20],m,n[10],o[10];
clrscr();
printf("Enter a recursive string:");
gets(a);
if(a[0]==a[3]) {
m=a[0];
printf("%c\n",m);
}
else {
printf("Entered string is not recursive");
}
j=0;
for(i=4;a[i]!=NULL;i++) {
if(a[i]!='/') {
b[j++]=a[i];
printf("%c",b[j]);
}
else {
goto a1;
}
}
a1:
b[j]='\0';
j=0;
for(i=i+1;a[i]!=NULL;i++) {
c[j]=a[i];
j++;
}
c[j]='\0';
n[0]=m;
n[1]='-';
n[2]='>';
j=3;
for(i=0;c[i]!=NULL;i++) {
n[j]=c[i];
j++;
}
n[j++]=m;
n[j++]='`';
n[j++]='\0';
printf("\n\nOutput string1 is:");
puts(n);
o[0]=m;
o[1]='-';
o[2]='>';
j=3;
for(i=0;b[i]!=NULL;i++)
{
o[j]=b[i];
j++;
}
puts(b);
o[j++]=m;
o[j++]='`';
o[j++]='/';
o[j++]='$';
o[j++]='\0';
printf("\n\nOutput string is:");
puts(o);
getch();
}

No comments:

Post a Comment