Friday, April 1, 2011

RECURSIVE PARSING


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
char input[10];
int i=0;
void t();
void eprime();
void f();
void tprime();
void e()
{
if(input[i+1]=='+')
eprime();
else if(input[i+1]=='*')
{
t();
e();
}
else if(input[i]=='\0')
printf("string not accepted");

else
{
f();
e();
}
}
void t()
{
if(input[i+1]=='*')
tprime();
else if(input[i]=='\0')
printf("string not accepted");
else
f();
}
void f()
{
if(input[i]=='(')
{
i++;
e();
}
else if(input[i]==')' && input[i+1]=='\0')
printf("string is accepted");
else if(input[i]=='I')
{
i++;
if(input[i]=='\0'||input[i]==')')
{
printf("string is accepted");
exit(0);
}
}
}
void eprime()
{
f();
i++;
e();
}
void tprime()
{
f();
i++;
e();
}
main()
{
clrscr();
printf("enter the string replacing id with I\n");
scanf(" %s",input);
e();
getch();
}

No comments:

Post a Comment